Skip to main content
tapfiliate.js detects visitors who come through affiliate links and reports their sign-ups and purchases. It only needs your account ID, which is public, so it is safe to use in the browser.
Using a shop or billing platform? Check the integrations in the help center first: most of them set this up for you.

Setup

Add the snippet to every page of your site, so a click is recorded wherever the visitor lands:
Then call conversion, customer, trial or lead on the page where the sale or sign-up happens. Calls are queued, so they work before the script has loaded. For a visitor who came through an affiliate link and still has the tracking cookie, these calls are always sent to Tapfiliate. For other visitors, a call is sent only if it carries something that can attribute it without a click: coupons for any of these calls, or customer_id for conversion. Otherwise nothing is sent, so the code can stay on the page for all visitors. Inside an iframe, detect records no click, and click, conversion, customer, trial, and lead track nothing. None of them calls its callback. Put the tracking code on the top-level page.

npm package

In apps built with a bundler, such as React, Vue, Next.js or Nuxt, you can install @tapfiliate/tapfiliate-js instead of adding the snippet. It loads the same tapfiliate.js.
This section describes version 1.1.1 and later. If the package is already in your lock file, update it: in 1.0.x, a method called before Tap.init throws, and so does any call during server-side rendering.
Tap.init takes the place of create and detect, with their arguments in this order:
Don’t call Tap.create or Tap.detect yourself: Tap.init already runs them. A create made after tapfiliate.js has loaded runs again and can switch the account ID, and a second detect sends the click again. A second Tap.init on the same page does nothing. Every other method on this page is available as Tap.methodName(...) with the same arguments, without the method name in front: tap('trial', 'USER1234') becomes Tap.trial('USER1234'). Calls made before Tap.init wait in a queue and run once tapfiliate.js has loaded. Call the package from code that runs in the browser. On the server it does nothing, so importing it in server-rendered code is safe, but a call made there is not repeated in the browser and nothing is tracked. In the Next.js App Router, layouts and pages are server components by default: call Tap from a client component ('use client') inside useEffect. In Nuxt, call it in onMounted or a client-only plugin.
TypeScript types are included. If your site enforces Trusted Types, see Content Security Policy. The source and release notes are on GitHub.

create

Initializes tapfiliate.js.

detect

Looks for affiliate tracking parameters in the URL. If it finds them, it records a click and sets a cookie, so a later conversion is attributed to the affiliate. Without tracking parameters it makes no request.

conversion

Tracks a conversion, usually a purchase. Put it on your thank-you page.

conversionMulti

Tracks one conversion with several commissions, for example a different rate per product category.
options is the same as for conversion. commissions is an array with one object per commission:

customer, trial and lead

Track a customer when a referred visitor signs up, before they pay. Conversions you track later for the same customer_id are attributed to the same affiliate.
trial and lead work like customer and set the customer’s initial status to trial or lead. Use trial for SaaS and subscriptions, lead for lead generation and long sales cycles.

click

For standard setups use detect. click is for rare cases where you know the affiliate from your own data, for example a list of referring domains.
Records a click from tracking parameters you pass explicitly.
trackingParameters holds either a referral code or an asset ID and source ID, for example { referral_code: 'janejameson' } or { asset_id: '1-abcdef', source_id: '2-cdefgh' }. The only option is always_callback.

Callbacks

By default the callbacks of detect, conversion, conversionMulti, customer and click fire only on success. Pass always_callback: true in the options to get every outcome, with the conventional signature:

Several sites

program_group is a legacy option. It works only in accounts that already use program groups. If your account uses them, pass the identifier of the group in the conversion. Tapfiliate then tracks the conversion from the visitor’s click only if their latest click is in one of that group’s programs:
In other accounts the option is ignored.

Content Security Policy

If your website sends a Content-Security-Policy header, allow these sources: The inline part of the snippet is subject to script-src too: allow it with a nonce or a hash, or move it to a script file that your policy allows. With 'strict-dynamic', the <script src> tag needs the nonce as well. If your policy enforces Trusted Types (require-trusted-types-for 'script'), the npm package can’t load tapfiliate.js there on its own. Use the snippet instead of the package: remove the package, including Tap.init, and call every method as tap('…'). Don’t mix the two on one page: tapfiliate.js reads only one of their queues, and calls through the other are silently lost. Under Trusted Types, test mode (?tap_test=true) doesn’t work. Opening it still switches that browser to test mode: tracking stops there until you delete the tap_debug cookie.