Callbacks
Callbacks in ReferralHero are functions that get executed when specific events occur during the tracking and referral process. You define these callbacks within the window.RHConfig
object. Each callback serves a particular purpose, allowing you to customize the behavior of your referral system.
Defining Callbacks
Callbacks are properties of the global variable window.RHConfig
. Here's a general structure:
IMPORTANT: Callbacks must be defined BEFORE the Tracking Pixel.
onLoad
This callback is triggered before everything else. It’s useful for initializing variables or performing actions that need to happen as soon as the tracking script is loaded.
ready
Triggered when the Tracking Code is fully initialized, all widgets are generated, and all required libraries are loaded. This is usually the place to put logic that should run as soon as your tracking is ready to go.
beforeSubmit
This callback is triggered right before the sign-up form is submitted. It’s useful for modifying the data that will be sent to the server. It receives an object containing form data like name
and email
.
success
Triggered after the sign-up form has been successfully submitted. This callback receives an object with the response of the submission. Initializing this callback will prevent the default sharing screen from appearing.
afterSuccess
Triggered after the form has been successfully submitted. Like success
, it receives the submission response. However, initializing this callback will NOT prevent the sharing screen from appearing.
error
This callback is triggered if there is an error during the form submission. It’s useful for handling errors gracefully.
popupOpen
Triggered when a popup is opened. This can be used to track popup usage or to customize what happens when a popup is displayed.
popupClose
Triggered when a popup is closed. Use this to track or manage actions after the user closes a popup
subscriberNotFound
Triggered when an email that doesn’t exist in the system is used to check the status of a subscriber.
subscriberLoaded
Triggered when a subscriber is identified. This is useful for loading subscriber-specific data or customizing the experience based on the subscriber’s information.
emailNotValid
Triggered when the email entered is not valid. It receives a reason
parameter explaining why the email is considered invalid.
serverProblem
Triggered when the server returns a 500 or 4XX error, indicating a server-side issue.
Syntax for defining callbacks
Last updated