Identify a subscriber

identify() lets you identify a person so that they don't have to manually enter their data (eg: email address, name, etc). This is particularly useful, for example, when you want to display the embeddable widgets on an internal page of your website where you already know the user's email (eg: a section of the website only logged in users can access).

RH.identify(data, force, callback);

The identify() function accepts two parameters:

  • the first parameter is an object containing the user data. At the bare minimum, the object must contain the email address of the user.

  • the second (optional) parameter is a boolean that informs us whether you want to override an existing session (see section Force identification for more details). The default is false

  • the third (optional) parameter is a callback that will be called if the identification succeeds. The callback will have a parameter containing the subscriber data.

var myFunc = function(data) {
console.log(data);
}
var data = {
email: "john@smith.com",
name: "John Smith",
extra_field: "USA",
extra_field_2: null,
upsert: true
}
RH.identify(data, false, myFunc);

How it works

When the identify() function is called, ReferralHero will check if a subscriber with that specific email address exists. If a subscriber is not found, a new subscriber is automatically created using the data sent over and bypassing the confirmation email. If the subscriber with that email already exist, ReferralHero simply returns the subscriber data.

Either way, if the subscriberLoaded callback has been initialized, it will be triggered.

If you don't want to automatically create a new subscriber when one isn't found (for example if you want to allow your users to manually opt-in), set the upsert property to false.

Load callback

The ReferralHero Tracking Code loads asynchronously, so if you intend on executing any RH functions on page load, you must wait until the library has completely loaded.

The best way to do this is to only call the identify() function in the load callback.

<script type="text/javascript">
window.RHConfig = {
callbacks: {
ready: function() {
var data = {
email: "john@smith.com",
name: "John Smith",
extra_field: "USA",
extra_field_2: null,
upsert: true
}
RH.identify(data, false);
}
}
}
</script>

Force identification

If a cookie session is already present (for example if the user has already been identified in the past), by default ReferralHero will not attempt to identify the user again. We do this to improve the user experience so that your users don't have to wait (usually around 1 second) to be identified again.

If, instead, you want to identify your users every time, you must set the second parameter of the identify() function to true.

var data = {
email: "john@smith.com",
name: "John Smith",
extra_field: "USA",
extra_field_2: null,
upsert: true
}
RH.identify(data, true);

NOTE

Our recommendation is to forcing identification as it will degrade user experience. If you force identification, ReferralHero will attempt to check the existence of the subscriber every single time a person visits that page, slowing down your website.

ReCaptcha

Unfortunately, if you're using ReCaptcha, identify() will not work.