Identify a Referrer

Here, we'll explore how to use the RH_MFxxxxxxxxx.referrer variable, a powerful tool for retrieving the referrer code associated with a user. By leveraging this variable, you can tailor your code to execute specific actions based on whether or not a user was referred to your site.

The RH_MFxxxxxxxxxx.referrer variable is a key component in tracking and utilizing referral codes in your website or application. By using this variable, you can detect whether a user has been referred by someone else and trigger specific actions based on that information. This section will guide you through the practical applications of RH_MFxxxxxxxxxx.referrer, how it works, and how you can implement it in your own code.

What is the RH_MFxxxxxxxxxx.referrer Variable?

The RH_MFxxxxxxxxx.referrer variable stores the referrer code if it is available. This code can be found in the URL query string (e.g., ?mwr=xxxxxxxx) or stored within a cookie named __maitre-referrer- in the user's browser. The referrer code typically represents a unique identifier associated with the person who referred the user to your site.

  • URL-Based Referrer Code: When a user clicks on a referral link, the referrer code is appended to the URL, allowing your site to recognize the referral.

  • Cookie-Based Referrer Code: If the user’s browser has the __maitre-referrer- cookie, it indicates that the user was referred previously, even if they navigate to your site later without the referral link in the URL.

The RH_MFxxxxxxxxxx.referrer variable does not require any specific method calls. Instead, it is automatically available in your code once the ReferralHero script is loaded on your site. When called, RH_MFxxxxxxxxxx.referrer will return the referrer code if it exists, or undefined if no referrer code is present.

Implementing RH_MFxxxxxxxxxx.referrer in Your Code

Here’s a basic example of how you can implement the RH_Mfxxxxxxxxxx.referrer variable in your code:

Copy

window.RHConfig = {
  callbacks: {
    ready: function() {
      if (RH_MFxxxxxxxxxx) {
        var referrerCode = RH_MFxxxxxxxxxx.referrer;
        
        if (referrerCode) {
          // Logic to execute if a referrer code is present
          console.log("Referrer Code Found: " + referrerCode);
          // Example: Apply discount, personalize page, etc.
        } else {
          // Logic if no referrer code is found
          console.log("No Referrer Code Detected");
        }
      }
    }
  }
}
  • Step 1: The script waits until ReferralHero is fully loaded by using the ready callback.

  • Step 2: It checks whether the RH_MFxxxxxxxxxx.referrer variable has a value.

  • Step 3: Depending on whether a referrer code is present, different logic can be applied. For instance, you might apply a discount if a referrer code is found.

Important: Replace 'MFxxxxxxxxxx' with your actual campaign UUID. This UUID is essential to get the correct referrer code.

Practical Applications of RH_MFxxxxxxxxxx.referrer

Knowing whether a user was referred allows you to enhance their experience on your website. Here are two practical examples:

  1. Automatic Discount Application: Suppose you want to offer a special discount to users who were referred by others. By checking if RH_MFxxxxxxxxxx.referrer has a value, you can automatically apply a discount code during the checkout process.

  2. Personalized Landing Page Content: You can personalize the text, offers, or even the entire layout of a landing page based on the referrer code. For instance, if the user was referred by a friend, you might display a welcome message mentioning the referrer’s name.

Implementation Example Applying discount if Referred:

<script type="text/javascript">
  window.RHConfig = {
    callbacks: {
      ready: function() {
        var form = document.getElementById('checkout-form');
        form.addEventListener("submit", function(e) {

          var discount_code = form.querySelector('#discountCodeInput').value

          if (RH_MFxxxxxxxxx) {
            var referrerCode = RH_MFxxxxxxxxx.referrer;
            console.log("Referrer Code:", referrerCode);

            if (referrerCode) {
              // Apply the discount code entered in the form
              var discountCode = discount_code;
              console.log("Discount applied: " + discountCode);
            } else {
              console.log("No Referrer Code Detected");
            }
          }
        });
      }
    }
  };
</script>

This is just an example; you can use it in your own way. You can replace the console.log statement with your own logic, depending on your use case.

Last updated