Track referral on Sign Up page

Capturing and tracking referrals requires integrating Referral Rocket's tracking system into your website or application. This guide walks you through the complete implementation process.

Step-by-Step Referral Tracking Implementation

Step 1: Add the following script in the Head tag (replace with your campaign id) on this page.

// Add this script in the HEAD tag
<script type="text/javascript" campaign-id="YOUR-CAMPAIGN-ID" defer src="https://app.referralrocket.io/widget/widgetIndex.js"></script>

Step 2: To capture referrals on your sign up page, you need to listen to form submission and send the information back to Referral Rocket. For this we have created a sample javascript that you can tweak and use. Note: Replace the form Id and field Id as per your page

window.onload = function() { 
 //REPLACE WITH YOUR FORM ID
  const form = document.getElementById("signupForm");
  
  form.onsubmit = function(event) { 
    event.preventDefault(); 
    
    // Collect user information | REPLACE WITH YOUR FIELD ID
    const userData = {
      email: document.querySelector("input[name='email']").value,
      firstName: document.querySelector("input[name='firstName']").value,
      lastName: document.querySelector("input[name='lastName']").value
    }; 

    // Send participant data to Referral Rocket
    if (window.Rocket) {
      window.Rocket.getCampaign().addParticipant(userData);
    }
  }; 
};

This script listens when the signup form is submitted and sends the new user to Referral Rocket SDK. The SDK automatically captures referrals if the referral code exists in the URL or in the cookie (60day retention).

(Alternative Method): Automatically add hidden referral field to your form

If you prefer to capture the referral code as part of your form submission without using JavaScript event listeners, you can use this alternative approach that automatically adds a hidden field with the referral value from the cookie.

  1. Add the following script after the Referral Rocket base script:

  1. Add the data-referralrocket="true" attribute to any form that should capture referrals:

  1. On your server, handle the form submission as normal. The referral field will be included in the form data when a referral code is present, allowing you to:

    • Store the referral data in your database

    • Pass the referral information to Referral Rocket when qualifying the participant

Last updated