Track custom referral events

NOTE

Tracking a custom referral event will only work for campaigns that are configured to accept referrals as custom events.

ReferralHero allows you to track custom events as referrals so that you can reward people who refer friends who complete a specific action, e.g: creates an account on your website, makes a purchase, schedules a call, etc.

To track a conversion, simply call the following Javascript code:

RH.trackReferral(userEmail);

userEmail is the email address of the person who has converted and it's required.

You should call trackReferral() when the conversion happens. For example, if you want to trigger a referral when they upgrade to a paid plan, then this is how you could do it:

<script>
var purchase = function(userEmail) {
if (RH) {
RH.trackReferral(userEmail);
}
}
</script>

However, if you want to trigger a referral on page load (for example when they visit a "Thank you page" after they convert), it's better to call trackReferral() inside the ready() callback to make sure the ReferralHero object has already been loaded, like this:

<script type="text/javascript">
window.RHConfig = {
callbacks: {
ready: function() {
RH.trackReferral(userEmail);
}
}
}
<script>

IMPORTANT

Make sure the ReferralHero Tracking Code is installed on the page where you trigger the referral.

Tracking referrals without emails

Whilst ReferralHero requires the email address of the referral to trigger the conversion, the email address doesn't need to be real. If you don't care about the identity of the referral, or simply don't have access to their email address, you can use a random one. Just make sure the email address you pass over is unique.

Here's an example code of how to generate unique email addresses:

var random_email = Math.random().toString(36).substring(2) + "@email.com" // Create an email address like dh83yhjdh83@email.com
RH.trackReferral(random_email);

Callback

Optionally, you can execute a function after the referral has been tracked. You can do so by adding a second argument to the trackReferral() function, like this:

<script>
var getReferralLink = function(data) {
// Your custom logic
}
RH.trackReferral(userEmail, getReferralLink(data));
</script>