Skip to main content

Integration Using JavaScript (JS)

Written by Zuzana Toulcová
Updated today

If we don't have a dedicated plugin or a ready-to-use guide for your specific platform in our Integration section, our JavaScript (JS) Integration is the most universal and flexible option. It allows you to customize the tracking flow to fit your website’s unique needs.


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.


1. 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 on the JS 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.



2. 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. Position the code as high as possible within the <head> tag of your HTML document.


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".


Default Conversion Types

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

  • Sale

  • Lead

  • Free Trial


3. Customizing with the Tracking Script Generator (Beta)

To help you build a precise structure for your manual integration, we provide a Tracking Script Generator directly within the JS Tracking Code section.




How it helps you:

The generator (currently in Beta) acts as a visual interface for our JavaScript tracking library. By selecting different options in the UI, you can dynamically inject additional parameters into the tracking object structure.

  • Customizable Parameters: For example, in the Conversion Script > CID, as you activate different variables (e.g., externalId and advS1) the generator automatically updates the code block with the corresponding key-value pairs (as shown in the screenshot below)

  • Structural Foundation: Once you have configured your required parameters, the tool provides a complete structural foundation for your Click or Conversion scripts, ready to be copied and pasted into your website's code.


⚠️ Important: While our generator provides the correct syntax and object structure, the developer is responsible for implementing the logic to capture dynamic data (such as order totals, customer IDs, or emails) from your website's environment (e.g., the DOM, Data Layer, Local/Session storage, cookies, or your backend) and passing it into our script variables.



4. 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 parameter must be provided as a string (e.g., "100" for whole numbers or "100.50" for decimals).

🛡️ 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.


5. 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?