Identify a subscriber

RH.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 unique identifier (eg: a section of the website only logged in users can access).

RH.identify(data, force, callback);

RH.identify() is not always necessary especially if you have already used an 'Add a Subscriber' function, as 'Add a Subscriber' will also identify the subscriber.

ex. RH.form.submit() is called on your portal signup/login form, you do not need to call RH.identify() again on an internal page, as the subscriber is already identified.

The RH.identify() function accepts two parameters:

  • the first parameter is an object containing the user data. At the bare minimum, the object must contain the unique identifier 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 RH.identify() function is called, ReferralHero will check if a subscriber with that specific unique identifier exists. If a subscriber is not found, a new subscriber is automatically created using the data sent over and bypassing the verification method. If the subscriber with that unique identifier already exists, 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 RH.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 RH.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 not force identification as it will degrade the 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, RH.identify() will not work.

Last updated