Referral Rocket
HomeDashboard
  • What is Referral Rocket?
  • Referral Program Examples
  • Getting Started
    • Campaigns
      • Campaign Types
      • Campaigns Details
        • Milestone Details
        • Reward Details
        • Referrer Widget
        • Invitee Widget
      • Installing/Tracking your Referral Campaign
        • Option 1: Hosted Solution (No/Low Code)
        • Option 2: Custom Solution
          • Simple Referral Program Redirect: Quick Setup Guide
          • Redirect user to hosted campaign
          • Embed Referral Rocket Widget
          • Integrate the referral program inside your webapp for logged in user
        • Referral Tracking
          • Track referral on Sign Up page
          • Track referral on Payments
      • Reward Management
      • Campaign Participants
      • Campaign Dashboards
  • Developer Tooks
    • Javascript SDK
    • REST API
      • API Endpoint
    • Webhooks
      • Setup
      • Testing
      • Events
  • Integrations
    • Stripe
      • How to setup Stripe?
        • Stripe Settings
      • Referral Tracking with Stripe
        • Promo Code Referral Tracking with Stripe
        • Setup Stripe Pricing Table
        • Setup Stripe Payment Links
        • Setup Stripe Payment Button
    • Cashfree
    • Razorpay
    • MemberSpace
    • Outseta
    • Shopify
      • How to setup Shopify?
      • Add Referral Widget on Shopify Stor
      • Popup Script to Display Discount Codes
    • ScoreApp
  • Rewards
    • Tremendous
      • How to integrate Tremendous?
        • Tremendous Settings
      • How to issue rewards with Tremendous?
    • PayPal Mass Payments
    • Wise Batch Payments
    • Stripe
    • Shopify
    • RazorPayX
    • Paypal
  • Affiliate Hub
    • Affiliate Program Hub
  • Product Updates
    • December 2024
  • Trust Center
  • Contact Us
  • FAQ
    • Where to find Campaign ID?
    • Understanding the Test Plan: Perfect for Testing, Limited for Production
Powered by GitBook
On this page
  • Step-by-Step Referral Tracking Implementation
  • (Alternative Method): Automatically add hidden referral field to your form
  1. Getting Started
  2. Campaigns
  3. Installing/Tracking your Referral Campaign
  4. Referral Tracking

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:

// Add this script after the Referral Rocket base script in your HEAD tag
document.addEventListener('DOMContentLoaded', function() {
  // Find all forms with data-referralrocket attribute
  const forms = document.querySelectorAll('form[data-referralrocket="true"]');
  
  // Process each form
  forms.forEach(function(form) {
    // Check if we have the Rocket object available
    if (window.Rocket) {
      const campaign = window.Rocket.getCampaign();
      
      // Get the referral code from Rocket SDK
      const referralCode = campaign.getReferralCode();
      
      // Only update the hidden field if a referral code exists
      if (referralCode) {
        // Get the referral input field
        const referralField = form.querySelector('input[name="referral"]');
        
        if (referralField) {
          // Update the existing referral field
          referralField.value = referralCode;
          console.log('Referral Rocket: Updated referral field with code', referralCode);
        } else {
          console.warn('Referral Rocket: No referral field found in the form. Add a hidden input with name="referral"');
        }
      }
    } else {
      console.error('Referral Rocket: SDK not loaded. Make sure the Referral Rocket script is properly included.');
    }
  });
});
  1. Add the data-referralrocket="true" attribute to any form that should capture referrals:

<form action="/signup" method="post" data-referralrocket="true">
  <input type="text" name="firstName" placeholder="First Name">
  <input type="text" name="lastName" placeholder="Last Name">
  <input type="email" name="email" placeholder="Email">
  <input type="hidden" name="referral" value="">
  <button type="submit">Sign Up</button>
</form>
  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

PreviousReferral TrackingNextTrack referral on Payments

Last updated 2 months ago