Skip to content

Pageview Tracker

The pageview tracker captures when visitors arrive via affiliate links. This is the foundation of Affitor tracking.


When someone clicks a partner’s affiliate link (https://yoursite.com?ref=PARTNER123), the tracker:

  1. Detects the ?ref= parameter
  2. Request to Affitor backend to get a unique customer_code
  3. Stores customer_code in a cookie
  4. Creates customer-partner relationship in database
  5. Sends a click event to Affitor

All subsequent events (signups, purchases) are linked via customer_code and user_id.


MethodBest forBenefits
npm SDKReact, Next.js, Vue, any JS/TS appTypeScript types, Promise-based, no race conditions
Script TagStatic HTML, WordPress, no-build sitesZero dependencies, copy-paste setup

Install the official SDK package:

Terminal window
npm install @affitor/tracker

Wrap your app with AffitorProvider — the tracker loads automatically:

// app/layout.tsx (or your root layout)
import { AffitorProvider } from '@affitor/tracker/react';
export default function RootLayout({ children }) {
return (
<html>
<body>
<AffitorProvider programId="YOUR_PROGRAM_ID">
{children}
</AffitorProvider>
</body>
</html>
);
}
pages/_app.tsx
import { AffitorProvider } from '@affitor/tracker/react';
export default function App({ Component, pageProps }) {
return (
<AffitorProvider programId="YOUR_PROGRAM_ID">
<Component {...pageProps} />
</AffitorProvider>
);
}
import { loadAffitor } from '@affitor/tracker';
// Load once — returns a singleton Promise
const affitor = await loadAffitor('YOUR_PROGRAM_ID');
OptionTypeDefaultDescription
programIdstring | numberRequired. Your program ID (from dashboard)
env'production' | 'uat' | 'local''production'Environment preset
debugbooleanfalseEnable debug mode (verbose console logs)
scriptUrlstringCustom script URL (overrides env)
// Local development with debug
const affitor = await loadAffitor('YOUR_PROGRAM_ID', { env: 'local', debug: true });
// UAT environment
const affitor = await loadAffitor('YOUR_PROGRAM_ID', { env: 'uat' });

For static HTML sites or platforms without a build step, add this script tag to your website’s <head> section:

<script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="false">
</script>

That’s it. The script handles everything automatically.

AttributeRequiredDescription
srcYesAffitor tracker script URL
data-affitor-program-idYesYour program ID (from dashboard)
data-affitor-debugNoSet “true” for test mode
<!DOCTYPE html>
<html>
<head>
<title>Your Site</title>
<script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="false">
</script>
</head>
<body>
<!-- Your content -->
</body>
</html>
public/index.html
<!DOCTYPE html>
<html>
<head>
<script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="false">
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>

  1. Go to your Affitor dashboard
  2. Navigate to Settings → Integration
  3. Copy your Program ID

Partners receive links in this format:

https://yoursite.com?ref=PARTNER123

Or with a landing page:

https://yoursite.com/pricing?ref=PARTNER123

The tracker detects any URL with ?ref= and captures the partner code.


Enable debug mode to see tracking events in your browser console:

npm SDK:

// Pass debug: true to AffitorProvider or loadAffitor
<AffitorProvider programId="YOUR_PROGRAM_ID" debug>
// or
const affitor = await loadAffitor('YOUR_PROGRAM_ID', { debug: true });

Script tag:

<script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="true">
</script>

Then:

  1. Open your browser’s Developer Tools (F12)
  2. Go to the Console tab
  3. Visit your site
  4. You should see the following console messages:
[Affitor Tracker] Affitor tracker initialized with options: {debug: true}
[Affitor Tracker] Using advertiser ID: YOUR_PROGRAM_ID
[Affitor Tracker] 🔍 Verifying cookie functionality...
[Affitor Tracker] 📝 Writing test cookies: {customer_code: "test_customer_...", affiliate_url: "..."}
[Affitor Tracker] Cookie set: {name: "customer_code", value: "test_customer_...", expires: ...}
[Affitor Tracker] Cookie set: {name: "affiliate_url", value: "...", expires: ...}
[Affitor Tracker] 📖 Reading test cookies back: {customer_code: "test_customer_...", affiliate_url: "..."}
[Affitor Tracker] ✅ Cookie verification PASSED - All cookies working correctly!
[Affitor Tracker] trackTest() called true
[Affitor Tracker] Sending test event to verify tracking: {customerCode: null, hasAttribution: false, eventType: "test"}

If cookies are blocked, you’ll see:

[Affitor Tracker] ❌ Cookie verification FAILED - Cookies may be blocked or not working properly!
[Affitor Tracker] customer_code cookie issue:
[Affitor Tracker] - Expected: test_customer_...
[Affitor Tracker] - Got: null/undefined
[Affitor Tracker] Possible causes:
[Affitor Tracker] - Browser privacy settings blocking cookies
[Affitor Tracker] - Safari Intelligent Tracking Prevention (ITP)
[Affitor Tracker] - Third-party cookie restrictions
[Affitor Tracker] - Browser extensions (ad blockers, privacy tools)
[Affitor Tracker] - Site not served over HTTPS (required for secure cookies)
  1. Visit your site
  2. Go to Affitor dashboard → Setting -> Pageview Tracker
  3. Click on Test Click Tracking
  4. Pageview tracker should show a blue checkmark

Symptoms: No cookies set, no console messages in debug mode

Check:

  • Script URL is correct
  • No Content Security Policy blocking the script
  • Script is in <head>, not <body>

Symptoms: Script loads but cookies are missing

Check:

  • Site is served over HTTPS (required for secure cookies)
  • No browser extensions blocking cookies

Symptoms: Cookies set but no events in Affitor

Check:

  • Program ID is correct
  • Check browser Network tab for failed requests