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. Stores partner_code in a cookie
  3. Generates a unique customer_code
  4. Sends a click event to Affitor

All subsequent events (signups, purchases) are linked via these cookies.


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
  1. Go to your Affitor dashboard
  2. Navigate to Settings → Integration
  3. Copy your Program ID

Add the script to every page where affiliate traffic might land.

Recommended: Add to your site’s global <head> so it loads on all pages.

<!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>
pages/_document.tsx
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head>
<script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="false"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
app/layout.tsx
import Script from 'next/script'
export default function RootLayout({ children }) {
return (
<html>
<head>
<Script
src="https://api.affitor.com/js/affitor-tracker.js"
data-affitor-program-id="YOUR_PROGRAM_ID"
data-affitor-debug="false"
strategy="afterInteractive"
/>
</head>
<body>{children}</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>

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.

Partners can also use Affitor short links:

https://affitor.com/r/abc123

These redirect to your site with the ?ref= parameter automatically added.


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

<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 with ?ref=TEST123
  4. Look for Affitor debug messages
  1. Open Developer Tools → ApplicationCookies
  2. Look for partner_code and customer_code
  3. Values should be set after visiting with ?ref=
  1. Visit your site with a test referral link
  2. Go to Affitor dashboard → Integration Status
  3. Pageview tracker should show “Connected”

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:

  • URL has ?ref= parameter
  • 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
  • Backend API is reachable
  • Check browser Network tab for failed requests