Track custom referral events

NOTE

Tracking a custom referral event will only work for campaigns that are configured to accept referrals as custom events. To do that, go to your campaign dashboard > Edit campaign > Goal and choose "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. Also, the above example code must be called BEFORE the ReferralHero Tracking Code.

Sending extra data

You can add an optional second parameter to send extra data about the referral, like the name or the value of the conversion.

var data = {
name: 'John Doe',
value: 54.3,
transaction_id: 'AJGJY87782h8h',
category: 'upgrade'
}
RH.trackReferral(userEmail, data);

The extra data you can send are:

  • name The subscriber's name

  • value The monetary value of the referral. E.g if the referral is worth $52, send 52

  • transaction_id The unique ID of the transaction. This is useful if you're tracking purchases and want to be able to associate a referral to a specific transaction later.

  • category The type of referral. Useful if you're tracking conversion in several places or for different products and want to be able to create reports.

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 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 third argument to the trackReferral() function, like this:

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

If you don't want to send extra data, you can pass on the callback function as the second parameter, like this:

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