Skip to main content

Affiliate Tracking Script Not Loading

Diagnose a missing or blocked AffiliateBase tracking script, wrong account ID, CSP or CORS errors, duplicate installs, and late initialization.

Table of Contents

This guide is for merchants and developers whose AffiliateBase tracking script (track.js) is missing, blocked, or loads without creating browser referral state. Start with the page source and the Network tab. Then check the account ID, content security policy, timing, and your platform.

Quick diagnosis

Check that the script is present

  1. Right-click your page -> View Page Source
  2. Search for affiliatebase or track.js
  3. Confirm the script tag is there

Expected code:

HTML
<script
  async
  src="https://app.affiliatebase.io/track.js"
  data-account-id="YOUR_ACCOUNT_ID">
</script>

Check the console for errors

  1. Open Developer Tools (F12 or right-click -> Inspect)
  2. Go to the Console tab
  3. Look for red error messages
  4. Search for messages containing “affiliatebase”

Check the Network tab

  1. Open Developer Tools
  2. Go to the Network tab
  3. Filter by “affiliatebase” or “track.js”
  4. Look for the script request
  5. Check the status (it should be 200)

Common Issues & Solutions

Issue: Script not in HTML

Symptom: The script tag isn’t in the page source.

Solutions:

  1. Confirm you added the script to your template or theme
  2. Check that it’s in a shared layout or site-wide custom-code area, ideally before </body>
  3. Clear any caches (CDN, browser, CMS)
  4. Confirm the page uses the right template

Issue: Wrong account ID

Symptom: The script loads, but nothing is tracked.

Solutions:

  1. In AffiliateBase, open Setup step 4 (Choose your checkout) and choose your checkout path to see Add the tracking script
  2. Choose Copy script. The copied snippet contains your account ID
  3. Replace the data-account-id value in the script on your site
  4. Deploy the change
HTML
<!-- Verify this matches the snippet in Setup step 4 -->
<script ... data-account-id="correct-account-id"></script>

Issue: Script blocked by an ad blocker

Symptom: The network request is blocked or fails.

Solutions:

  1. Turn off the ad blocker temporarily to test
  2. Check whether your ad blocker uses strict rules
  3. Test in an incognito or private window

Issue: Content Security Policy (CSP) Blocking

Symptom: The console shows a CSP violation error.

Error example:

Refused to load script from 'https://app.affiliatebase.io/track.js'
because it violates Content-Security-Policy

Solutions: Allow app.affiliatebase.io in your script-src and connect-src policies:

Content-Security-Policy: script-src 'self' https://app.affiliatebase.io; connect-src 'self' https://app.affiliatebase.io;

Or in a meta tag:

HTML
<meta http-equiv="Content-Security-Policy"
      content="script-src 'self' https://app.affiliatebase.io; connect-src 'self' https://app.affiliatebase.io;">

Issue: CORS error

Symptom: The console shows a CORS error.

Cause: CORS errors usually point to a configuration problem.

Solutions:

  1. Confirm you’re loading from https://app.affiliatebase.io/track.js
  2. Check that your server isn’t proxying the script incorrectly
  3. Remove any conflicting headers

Issue: Script loads too late

Symptom: The script loads, but window.affiliatebase_referral is undefined when your code reads it.

Solutions:

  1. Keep the script in the shared layout so it loads before the visitor starts checkout
  2. For advanced code that calls affiliatebase(...) before the remote script loads, add the command-queue preloader from the Tracking Script Reference
  3. Wait for the script to initialize:
JavaScript
affiliatebase('ready', () => {
  console.log('Referral:', window.affiliatebase_referral);
});
  1. Or check before reading it:
JavaScript
// Check if ready
if (window.AffiliateBase) {
  console.log(window.affiliatebase_referral);
} else {
  // Script not loaded yet
}

Issue: Multiple script instances

Symptom: Unexpected behavior or duplicate tracking.

Solutions:

  1. Search your code for more than one copy of the script
  2. Check for theme or plugin conflicts
  3. Load the script only once per page

Issue: Localhost or local app testing

Symptom: Browser checks work locally, but final Stripe attribution doesn’t appear in production.

Cause: Local checks confirm that the script, form field, or checkout link receives a referral value. The final Stripe checkout test should run from a reachable staging or production page.

Solutions:

  1. For local app checks, use /track.js, data-api-url="http://localhost:3000", and data-debug="true".
  2. Confirm window.AffiliateBase.referral is present after opening a test affiliate link.
  3. Confirm the checkout form or Stripe link receives the referral value.
  4. Run the final Stripe Checkout test from a deployed page.

Verification steps

Step 1: Confirm the script loads

In console, run:

JavaScript
typeof window.affiliatebase
// Should return "function"

Step 2: Check initialization

In console, run:

JavaScript
Boolean(window.AffiliateBase)
// Should return true after the script loads

If you enabled data-debug="true", look for AffiliateBase debug messages in the console.

Step 3: Test referral capture

  1. Visit with a real affiliate link: https://yoursite.com?via=YOUR_TOKEN
  2. In console, run:
JavaScript
console.log(window.AffiliateBase?.referral || window.affiliatebase_referral);
// Should output a generated referral ID after a valid affiliate link click

Step 4: Check cookies

  1. Go to Developer Tools -> Application -> Cookies
  2. Look for a cookie starting with ab_referral (for example ab_referral_<account_id>)
  3. Confirm it contains referral data

Step 5: Check the network request

  1. Visit with a real affiliate link (?via=YOUR_TOKEN)
  2. Look for a request to /api/track
  3. Confirm it returns a 200 status

Platform-specific issues

WordPress

  • Check that the theme footer or global custom-code area has the script
  • Confirm caching plugins aren’t removing it
  • Try adding via a plugin like “Insert Headers and Footers”

Webflow

  • Add to Project Settings -> Custom Code, usually in the footer code area
  • Publish the site again

Shopify

  • Add to theme.liquid before </body> or through the theme’s global custom code
  • Or use Google Tag Manager
  • Save the theme, then clear your CDN cache if you use one

React/Next.js

  • Use the next/script component to load it
  • Add to _app.js or _document.js
  • Confirm the build process isn’t removing it

Single-page applications

  • Make sure the script loads on the initial page load
  • The script persists across client-side navigation
  • You don’t need to reinitialize it on route changes

Still not working?

Gather diagnostic info

Before contacting support, collect:

  1. A screenshot of console errors
  2. A screenshot of the Network tab (filtered to affiliatebase)
  3. Your website URL
  4. Your account ID
  5. Browser and version
  6. Steps to reproduce

Contact support

Email support@affiliatebase.io with:

  • All diagnostic info above
  • What you expected and what happened
  • Any recent changes

Prevention

Best practices

  1. Test after deployment: Verify tracking every time you push changes
  2. Monitor the console: Watch for new errors
  3. Check periodically: Confirm the script is still present
  4. Document setup: Record where you added the script

Monitoring

Consider:

  • Uptime monitoring for your site
  • Alerts for JavaScript errors
  • Regular testing of affiliate links

Next steps

Esc