How to Add Affiliate Program to Any Website with JavaScript

Add a simple script tag to track referrals on any website. This works with any HTML page, static site, or custom web application.

Image: JavaScript tracking script overview
1

Add the tracking script

Paste this snippet before the closing </head> tag on every page of your website. This script is lightweight (~2KB) and loads asynchronously so it won't affect page speed.

HTML
<script
  async
  src="https://js.blossu.com/v1/blossu.js"
  data-program-id="YOUR_PROGRAM_ID"
></script>

Replace YOUR_PROGRAM_ID with your actual program ID from the Blossu dashboard.

Image: Where to add the script in your HTML
2

Verify the installation

To verify the script is working correctly:

  • Visit your site with a test referral link (e.g., yoursite.com?via=test)

  • Open your browser's developer console (F12 or right-click and select "Inspect")

  • Type window.blossu_ref_id in the console and press Enter

  • You should see the referral ID (e.g., "test") displayed

3

Check network requests (optional)

You can also verify the installation by checking the Network tab in your browser's developer tools. Look for requests to js.blossu.com.

Image: Browser console showing blossu_ref_id

How it works

When a visitor arrives via a partner referral link (e.g., yoursite.com?via=partner), the script automatically captures the referral and stores it in window.blossu_ref_id and as a first-party cookie.

This ID persists for 60 days and is used to attribute purchases to the referring partner. Even if the visitor closes their browser and returns later, the referral will still be tracked.

Supported referral parameters

The tracking script recognizes the following URL parameters:

  • ?via=partner_code - The primary referral parameter

  • ?ref=partner_code - Alternative referral parameter

Next steps

Now that you have tracking set up, you need to connect your payment platform to automatically track conversions and calculate partner commissions.