Tracking Script

Install the Blitz Rocket tracking script on your website

Tracking Script

The Blitz Rocket tracking script is a lightweight JavaScript snippet that you add to your website to automatically track referral visits, signups, and purchases.

Installation

Add the following script to your website. Replace YOUR_CAMPAIGN_ID with your actual campaign/contest ID from the Blitz Rocket dashboard:

<script
  src="https://blitzrocket.com/referral-tracker.js?campaignId=YOUR_CAMPAIGN_ID&autoInject=stripe"
  async
></script>

The autoInject=stripe parameter automatically captures Stripe checkout purchases. Remove it if you don't use Stripe or prefer to track purchases manually.

Track Signups

Call RocketTracker.trackSignup() when a user completes registration on your site:

// After user successfully registers
if (window.RocketTracker) {
  window.RocketTracker.trackSignup("[email protected]");
}
function SignupForm() {
  const handleSubmit = async (formData) => {
    const result = await registerUser(formData);

    if (result.success && window.RocketTracker) {
      window.RocketTracker.trackSignup(formData.email);
    }
  };

  return <form onSubmit={handleSubmit}>...</form>;
}
<script setup>
async function handleSignup(formData) {
  const result = await registerUser(formData);

  if (result.success && window.RocketTracker) {
    window.RocketTracker.trackSignup(formData.email);
  }
}
</script>

Track Purchases

Call RocketTracker.trackPurchase() when a user completes a purchase:

// After purchase is confirmed
if (window.RocketTracker) {
  window.RocketTracker.trackPurchase(
    "order-12345",  // orderId
    49.99,          // amount
    "USD",          // currency
    "[email protected]" // email (optional)
  );
}
function CheckoutSuccess({ order }) {
  useEffect(() => {
    if (window.RocketTracker) {
      window.RocketTracker.trackPurchase(
        order.id,
        order.total,
        order.currency,
        order.email
      );
    }
  }, [order]);

  return <div>Thank you for your purchase!</div>;
}

Get Referral Code

Retrieve the current referral code stored from a referral link visit:

if (window.RocketTracker) {
  const code = window.RocketTracker.getReferralCode();
  if (code) {
    console.log("Active referral code:", code);
  }
}

Referral & Affiliate Code Detection

The tracking script automatically detects codes from URL parameters and tells referral and affiliate programs apart by which parameter is used:

  • Referral program: ?code=ABC123 or ?ref=ABC123
  • Affiliate program: ?aff=XYZ789 or ?fpr=XYZ789 (FirstPromoter-style)

Each program is stored in its own cookie namespace so a single site can run a referral program and an affiliate program at the same time:

  • Referral code → blitzrocket_referral_code cookie
  • Affiliate code → blitzrocket_affiliate_code cookie

Because codes are only unique within a campaign, the script resolves which campaign a code belongs to via the server when a visitor first lands. The detected code is then included in subsequent tracking calls.

A domain can have at most one active referral program and one active affiliate program at a time. To switch programs, deactivate the existing one first.

Targeting a specific program

When tracking server-side, read the matching cookie. When using the JS helpers on a site that runs both programs, pass the program type explicitly:

// Track an affiliate signup specifically
window.RocketTracker.trackSignup("[email protected]", { type: "affiliate" });

// Track an affiliate purchase specifically
window.RocketTracker.trackPurchase("order-12345", 49.99, "USD", "[email protected]", { type: "affiliate" });

Framework Integration

Nuxt 3

Blitz Rocket provides a built-in Nuxt plugin. Set the NUXT_PUBLIC_BLITZROCKET_CAMPAIGN_ID environment variable and the script loads automatically.

You can also use the provided $blitzrocket helper:

<script setup>
const { $blitzrocket } = useNuxtApp();

async function handleSignup(email) {
  await $blitzrocket.trackSignup(email);
}

async function handlePurchase(order) {
  await $blitzrocket.trackPurchase(
    order.id,
    order.total,
    order.currency,
    order.email
  );
}

const referralCode = $blitzrocket.getReferralCode();
</script>

Next.js

// app/layout.js
import Script from "next/script";

export default function RootLayout({ children }) {
  const campaignId = process.env.NEXT_PUBLIC_BLITZROCKET_CAMPAIGN_ID;

  return (
    <html>
      <head>
        <Script
          id="blitzrocket-tracker"
          src={`https://blitzrocket.com/referral-tracker.js?campaignId=${campaignId}&autoInject=stripe`}
          strategy="afterInteractive"
        />
      </head>
      <body>{children}</body>
    </html>
  );
}

Plain HTML

<!DOCTYPE html>
<html>
  <head>
    <script
      src="https://blitzrocket.com/referral-tracker.js?campaignId=YOUR_CAMPAIGN_ID&autoInject=stripe"
      async
    ></script>
  </head>
  <body>
    <!-- Your page content -->
  </body>
</html>

Google Tag Manager

  1. Go to GTMTagsNew Tag
  2. Choose Custom HTML
  3. Paste:
<script
  src="https://blitzrocket.com/referral-tracker.js?campaignId=YOUR_CAMPAIGN_ID&autoInject=stripe"
  async
></script>
  1. Set trigger to All Pages
  2. Publish your changes