September 16, 2026
This guide walks you through connecting your website with Tapfiliate. This setup is for advertisers who want to track clicks, conversions, and customers via a custom code embedded into their website.
In this article:
- Why JavaScript is the best choice for your tracking setup
- What are the necessary prerequisites for the JavaScript integration
- Essential steps to get started
- How to verify your JavaScript integration
- Advanced use cases that this integration type can cover
- All methods and the npm package
JavaScript integration advantages
- Compatible with various website types - If your platform-based website does not have a direct integration with Tapfiliate, JavaScript integration can be your magic wand, allowing you to connect a CMS-based website to your Tapfiliate program.
- Flexible event tagging - Whether you aim to track a conversion, a sign-up, or even a newsletter subscription, JavaScript integration lets you set the conversion trigger to almost any event.
- Not necessary to do server-side installation - Most of the websites have an instance for the custom code installation, where you can put Tapfiliate’s JavaScript code. If you have a custom website, you can add the code directly to the website pages.
- Capable of covering advanced tracking cases - JavaScript integration works great when you need to perform complex tracking scenarios, such as tracking multiple commission types, assigning recurring commissions, or setting up coupon tracking.
JavaScript integration prerequisites
Before you start the integration process, make sure you have:- A Tapfiliate account (with access to your Account ID)
- A website that allows for adding custom tracking codes
- Admin/developer access to your site’s codebase
Setting up the JavaScript integration
1. Add the click tracking code.
Copy the code below and add it to your website’s Header section, or paste it to all website pages. If your website is CMS-based, you should locate the instance where the system allows hosting of custom code. Make sure to replace ‘YOUR ACCOUNT ID’ with your Tapfiliate Account ID so that we can match visitor activity to your Tapfiliate account.2. Add the conversion tracking code.
To inform Tapfiliate that a conversion took place on your website’s end, you must add the conversion code to the page where an order/target action is confirmed.The most basic version of this snippet includes the essential parameters: an external ID and the conversion amount. Make sure to pass the relevant data from the order details within the placeholders in the code (‘Unique Conversion Id’ and Conversion Amount) so that the conversion data is recorded along with the transaction.
Using Google Tag Manager? Fire the conversion tag only on the event that completes the conversion (for example
purchase), not on every page, and fill ‘Unique Conversion Id’ and Conversion Amount from variables that read the order (or lead) ID and amount from your dataLayer. Check that the amount variable returns the real total: a fallback such as || 0 records conversions with an amount of 0. The click tracking code from step 1 still has to run on every page.Verify your integration
Before setting your program live, you have to verify your JavaScript integration. The best way to do that is to use a test affiliate’s link and initiate a test purchase.- In your Tapfiliate account, locate a test affiliate record in the Affiliates section > Click to expand details > Copy their referral link.
- Follow the test affiliate’s referral link to your website. Once a page is loaded, you should see a click tracked in your Recent Activity Box (Dashboard).
- Make a test sale or subscription for which your code should pass an amount above 0, for example of your cheapest product. When set up correctly, you should be able to see the conversion tracked in your Recent Activity Box (Dashboard). Then check on the Conversions page that its amount is the amount your code should pass for that order, for example the subtotal without shipping and tax if that is what you pay commission on. A free product only shows that a conversion is recorded: its total is 0, so it can’t show that your code passes the real amount (a variable that falls back to 0 looks the same).
Additional functionalities of JavaScript integrations
As we have highlighted in this article, JavaScript integration is highly powerful for handling advanced use cases.Option 1. Tracking a customer (or a signup)
A customer is an event that represents lead creation, user account creation, or a purchase of your product or service. Customers are usually tracked when a visitor, referred by an affiliate, signs up for a trial or fills out a lead form. Later, one or more conversions will be created for the customer, e.g., for each successful payment.If you’d only like to track the customer without attaching any conversions just yet, you can use the code below. Depending on your use case, you may replace the customer in the code with the alias that best suits your use case. You may choose from the following: customer, trial, or lead.
Option 2. Tracking recurring or lifetime commissions
If you aim to track recurring/lifetime commissions in your program, you will need to send the Customer ID when you track a conversion. This way, our system will recognize the customer attribution and attach the recurring/lifetime commission to a customer record in your program. If the customer with the respective ID is not found, Tapfiliate will create a new customer record. If this code, or your server, also tracks the customer’s later purchases or renewals, keep Recurring commissions of your commission types on Smart connected, not Time based (see Smart Connected): with Time based, Tapfiliate also creates a conversion for the customer every Recurrence interval, on top of the conversions you send. If only the first purchase is tracked, see the note on renewals below. Renewals that your billing system charges without the customer visiting your website are not seen by this code: see How to Set Up the Recurring/Lifetime Commissions via REST API, Zapier or Make. If your commission type is Time-Based, Tapfiliate creates a renewal itself every Recurrence interval: don’t send them, or renewals are paid twice (see Time-Based).Option 3. Tracking an alternative commission type (Extra commission)
If you have added multiple commission types for your program, you can specify which commission type applies to the conversion you are tracking. The ‘COMMISSION-TYPE-IDENTIFIER’ is created and stored in your Tapfiliate account, under Programs > Commission structure > Extra commissions. Depending on the value passed in the parameter, the appropriate commission will be applied to the conversion. If the identifier doesn’t match a commission type in your program (an archived one included), the conversion gets the standard commission (or the affiliate’s group rate for it) and no error is returned.Option 4. Tracking multiple commissions (conversionMulti method)
When you need to track multiple commissions for a single conversion, useconversionMulti. This is useful when the commission you offer varies by product or category.Usually, you loop through the order’s line items to create the commission array.
Tapfiliate doesn’t return an error because of a conversion’s commission lines. Check what your code sends:
- A line without
commission_type, or with an identifier that doesn’t match a commission type in your program (an archived one included), gets the program’s standard commission (or the affiliate’s group rate for it). - A line without
sub_amount, or with a value that isn’t a number, is recorded with an amount of 0. A percentage commission is then 0, while a fixed commission is still paid in full. - With an empty commissions array, the conversion is recorded with an amount of 0 and a standard commission (or the affiliate’s group rate for it).
sub_amount values. Before going live, track a test conversion and check on the Conversions page that each commission has the type and amount you expected.Option 5. Attaching metadata to a conversion
Suppose you need to store additional information alongside a conversion (not collected in the default parameters), such as a name, subscription type, or product quantity. In that case, you can add themeta_data object to the conversion options. Its limits are described on the Developer Portal: conversion.
In this example, we fetch the user’s email address and gender as metadata, passed in the email and gender metadata keys.
All methods and the npm package 📚
Every method of tapfiliate.js (create, detect, conversion, conversionMulti, customer, trial, lead and click), with all its arguments and options, is described on the Developer Portal: JavaScript tracking.
If your website is an app built with React, Vue, Next.js or Nuxt, your developer can install the npm package @tapfiliate/tapfiliate-js instead of adding the snippet. See npm package on the Developer Portal.