Skip to main content

Integration Using JavaScript (JS)

Set up custom click and conversion tracking on any platform.

The JavaScript integration tracks affiliate clicks and conversions on any website with two scripts: one on every page and one on your thank-you page. Use it when your platform has no dedicated plugin or guide.


​

How it works

The integration consists of two simple parts:

  1. Click Tracking Script: You place this on all pages of your website to track when a user arrives via an affiliate link.

  2. Conversion Tracking Script: You place this only on your thank-you page (the page shown after a successful purchase or signup) to record the conversion and calculate commissions.

Finding your base scripts

To begin, we provide pre-filled base templates directly within your dashboard that already include your unique identifiers.

  1. Navigate to Offers → Offer list → Offer detail → Integrations tab in the Offer menu.

  2. Scroll down to the Advanced integrations section.

  3. Click the Tracking Code card.

  4. From there, you will find a dedicated page with your specific scripts for clicks and every active conversion type in your Offer. By clicking on Show details, the code will be displayed ready to copy and use.

Implementing the base scripts

Step 1: Set up click tracking

The click script (found below Setting up clicks) must be placed on every page of your website, including subdomains and landing pages. Place it as high as possible in the <head>, ideally right after the opening <head> tag, so the click is recorded before the visitor can leave the page.

​

Step 2: Set up conversion tracking

Place this script only on your thank-you page (the page after a successful purchase or signup). You'll find this script by clicking on Show details below the Setting up conversion type section. Place it right before the closing </body> tag, so any order details shown on the page are already loaded if you later extend the script to read them.

​

Default conversion types

By default, our platform supports several conversion types, which you can find in your Offer settings:

  • Sale

  • Lead

  • Free Trial

Customizing the scripts with the AI assistant

The base scripts cover a standard setup. To add more data, such as the order amount, an External ID or Adv S parameters, ask the AI assistant: open the Search or ask AI… bar, switch to AI Chat and describe your setup, for example: "Add the order total and order ID to my Sale conversion script." It returns the script with the right parameters for your account. For the parameter reference, see Adding Parameters to a Conversion Script and Methods of Adding Data to Parameters.

⚠️ Important: The AI assistant provides the correct syntax and object structure, but your developer still captures the dynamic data (such as order totals, customer IDs or emails) from your website (e.g., the DOM, data layer, local or session storage, cookies or your backend) and passes it into the script variables where applicable.


​

Important technical considerations

  • Success Activation Only: Ensure conversion scripts only trigger after a successful action to prevent false commissions.

  • One Script per Action: You can track multiple events, but a specific script must be implemented for each conversion type individually.

  • Amount Parameter Format: To ensure accurate calculation, the amount.value parameter must be provided as a string (e.g., "100" for whole numbers or "100.50" for decimals, as in amount: { value: "100.50" }).

🛡️ Security Tip: While our basic JavaScript integration is quick to set up, if you wish to make your tracking flow more secure, we recommend using an API integration or Postback solution. We also suggest using IP whitelisting and disabling tracking scripts as described in our Tracking Authorization guide. These methods help protect your data and ensure higher security compared to client-side integrations.


​

Testing your integration

We highly recommend verifying your setup before launching your program:

  1. Open an incognito window.

  2. Use a test affiliate link to visit your site.

  3. Complete a test conversion (e.g., a $0 purchase).

  4. Verify that both the Click and the Conversion appear in your Trackdesk reports.

Did this answer your question?