- Blitz Rocket API DocumentationGetting StartedAPI ReferenceWebhooksReferral Tracking
Tracking Script
Install the Blitz Rocket tracking script on your website
On this page
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 Code Detection
The tracking script automatically detects referral codes from URL parameters:
?ref=REF-XYZ789?referral=REF-XYZ789
When detected, the referral code is stored in a cookie and included in subsequent tracking calls.
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
- Go to GTM → Tags → New Tag
- Choose Custom HTML
- Paste:
<script
src="https://blitzrocket.com/referral-tracker.js?campaignId=YOUR_CAMPAIGN_ID&autoInject=stripe"
async
></script>
- Set trigger to All Pages
- Publish your changes