Callbacks

Callbacks allow you to "register" functions that will be executed when a specific event occurs.

You can define callbacks in the Configuration file. Callbacks is a property of the global variable window.RHConfig.

IMPORTANT

Callbacks must be defined BEFORE the Tracking Pixel.

Code
Callbacks
Code
<script type="text/javascript">
window.RHConfig = {
callbacks: {
onLoad: function() {
// ... your logic ...
},
ready: function() {
// ... your logic ...
},
beforeSubmit: function(data) {
RH.form.data = {
name: "Mr "+ data.name,
email: "john.smith@email.com",
extra_field: null,
extra_field_2: null
}
},
success: function(output) {
// ... your logic ...
},
afterSuccess: function(output) {
// ... your logic ...
},
error: function() {
// ... your logic ...
},
popupOpen: function() {
// ... your logic ...
},
popupClose: function() {
// ... your logic ...
},
subscriberNotFound: function() {
// ... your logic ...
},
emailNotValid: function(reason) {
// ... your logic ...
},
serverProblem: function(reason) {
// ... your logic ...
},
subscriberLoaded: function(response, data) {
// ... your logic ...
}
}
}
</script>
Callbacks

Callback

Description

onLoad

It's triggered before everything else.

ready

It's triggered when the Tracking Code is initialized, the widgets have been generated and all libraries have been loaded.

beforeSubmit

It's triggered right before the sign-up form is submitted. Useful to change the data before is sent. It receives an object that contains the data from the form (name, email, etc). To change the data, change the properties of the RH.form.data object.

success

It's triggered after the sign-up form has been successfully submitted. It receives an object that contains the response of the submission. Initializing this callback will prevent the sharing screen from appearing.

afterSuccess

It's triggered after the form has been successfully submitted. It receives an object that contains the response of the submission. Initializing this callback will NOT prevent the sharing screen from appearing.

error

It's triggered if there was an error with the form submission.

popupOpen

It's triggered when the popup is opened.

popupClose

It's triggered when the popup is closed.

subscriberNotFound

It's triggered when an email that doesn't exist is used to check the status

subscriberLoaded

It's triggered when a subscriber is identified.

emailNotValid

It's triggered when the email entered is not valid. It receives one parameter: reason, which contains the reason why ReferralHero thinks that email is not valid.

serverProblem

It's triggered when the server returns a 500 or 4XX error.