Script Not Loading

Troubleshoot issues with the AffiliateBase tracking script

Table of Contents

Script Not Loading

If the AffiliateBase tracking script isn’t working properly, this guide helps you diagnose and fix common issues.

Quick Diagnosis

Check Script is Present

  1. Right-click on your page → View Page Source
  2. Search for affiliatebase or jsdelivr
  3. Verify the script tags are present

Expected code:

<script>
  (function(w,r){
    w._abq=w._abq||[];
    w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}
  })(window,'affiliatebase');
</script>
<script
  async
  src="https://cdn.jsdelivr.net/npm/affiliatebase-tracking@1/src/index.js"
  data-org-id="YOUR_ORG_ID">
</script>

Check 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 Network Tab

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

Common Issues & Solutions

Issue: Script Not in HTML

Symptom: Script tags not found in page source.

Solutions:

  1. Verify you added the script to your template/theme
  2. Check it’s in the correct section (<head> recommended)
  3. Clear any caching (CDN, browser, CMS cache)
  4. Verify the page uses the correct template

Issue: Wrong Organization ID

Symptom: Script loads but no tracking occurs.

Solutions:

  1. Go to AffiliateBase dashboard
  2. Copy your Organization ID from setup
  3. Update data-org-id in your script
  4. Deploy changes
<!-- Verify this matches your dashboard -->
<script ... data-org-id="correct-org-id"></script>

Issue: Script Blocked by Ad Blocker

Symptom: Network request blocked or failed.

Solutions:

  1. Disable ad blocker temporarily to test
  2. Check if your ad blocker has strict rules
  3. Test in incognito/private mode
  4. Consider using npm package instead of CDN

Issue: Content Security Policy (CSP) Blocking

Symptom: Console shows CSP violation error.

Error example:

Refused to load script from 'https://cdn.jsdelivr.net/...'
because it violates Content-Security-Policy

Solutions: Add jsdelivr.net to your CSP header:

Content-Security-Policy: script-src 'self' https://cdn.jsdelivr.net;

Or in meta tag:

<meta http-equiv="Content-Security-Policy"
      content="script-src 'self' https://cdn.jsdelivr.net;">

Issue: CORS Error

Symptom: Console shows CORS-related error.

Solutions:

  1. CORS errors usually indicate a configuration issue
  2. Verify you’re loading from the official CDN
  3. Check your server isn’t proxying incorrectly
  4. Ensure no conflicting headers

Issue: Script Loading Too Late

Symptom: Script loads but window.affiliatebase_referral is undefined when accessed.

Solutions:

  1. Place script in <head> not bottom of body
  2. Wait for script to initialize:
// Wait for script to be ready
window._abq = window._abq || [];
window._abq.push(function() {
  console.log('Referral:', window.affiliatebase_referral);
});
  1. Or check before accessing:
// Check if ready
if (window.AffiliateBase) {
  console.log(window.affiliatebase_referral);
} else {
  // Script not loaded yet
}

Issue: Multiple Script Instances

Symptom: Unexpected behavior, duplicate tracking.

Solutions:

  1. Search your code for multiple script inclusions
  2. Check theme/plugin conflicts
  3. Ensure script is only loaded once per page

Issue: Localhost Testing

Symptom: Script loads but window.affiliatebase_referral is undefined on localhost.

Explanation: The tracking script doesn’t create referrals on localhost by design (security measure).

Solutions:

  1. Test on a deployed site (staging or production)
  2. Use a tunneling service (ngrok, localhost.run)
  3. Deploy to a test environment

Verification Steps

Step 1: Confirm Script Loads

In console, run:

typeof window.affiliatebase
// Should return "function"

Step 2: Check Initialization

Look for console message:

AffiliateBase: Initialized with org YOUR_ORG_ID

Step 3: Test Referral Capture

  1. Visit: https://yoursite.com?via=test
  2. In console, run:
console.log(window.affiliatebase_referral);
// Should output a referral ID

Step 4: Check Cookies

  1. Go to Developer Tools → Application → Cookies
  2. Look for ab_referral cookie
  3. Should contain referral data

Step 5: Check Network Request

  1. Visit with ?via=test parameter
  2. Look for request to api.affiliatebase.com/api/track
  3. Should return 200 status

Platform-Specific Issues

WordPress

  • Check theme’s header.php has the script
  • Verify caching plugins aren’t removing it
  • Try adding via a plugin like “Insert Headers and Footers”

Webflow

  • Add to Project Settings → Custom Code → Head Code
  • Publish changes
  • Clear Webflow CDN cache

Shopify

  • Add to theme.liquid in <head> section
  • Or use Google Tag Manager
  • Clear Shopify cache

React/Next.js

  • Use next/script component for proper loading
  • Add to _app.js or _document.js
  • Verify it’s not being removed by build process

Single Page Applications

  • Ensure script loads on initial page load
  • Script persists across client-side navigation
  • No need to reinitialize on route changes

Still Not Working?

Gather Diagnostic Info

Before contacting support, collect:

  1. Screenshot of console errors
  2. Screenshot of network tab (filtered to affiliatebase)
  3. Your website URL
  4. Your organization ID
  5. Browser and version
  6. Steps to reproduce

Contact Support

Email support@affiliatebase.com with:

  • All diagnostic info above
  • Description of expected vs actual behavior
  • Any changes made recently

Prevention

Best Practices

  1. Test after deployment: Always verify tracking after pushing changes
  2. Monitor console: Watch for new errors
  3. Check periodically: Verify script is still present
  4. Document setup: Record where script was added

Monitoring

Consider setting up:

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