Integrating with Javascript

Out-of-the-box features:
  • Conversion tracking
  • Commission based on order amount
  • Track affiliate coupon code conversions
  • Supports lifetime commissions
  • Per category commissions
  • Track order currency
  • Auto-handle recurring commissions
  • Auto-handle refunds and disputes

This guide offers an overview of the different ways your Tapfiliate code can be formatted depending on your use case and needs.

You can watch our video guide or refer to the instruction below.
Embedded content: https://www.loom.com/share/194d1b851c48429fb0430b9c3b92d144

In this article, you will find the most basic base template, as well as sample templates for the following use cases:

  1. This is your click tracking code. Regardless of your use case, you must place this code in the head of every page of your website, between the <head> and </head> HTML tags.

    <script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
    <script type="text/javascript">
      (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');
    
      tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
      tap('detect');
    </script>
    

    {{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

  2. Whenever a conversion takes place, you will need to signal our platform that this happened. To do so, you can use our conversion page code. This code is usually placed on your thank you page, right after the order has been completed, or the lead data has been collected. There are several levels of integration possible with this code. By far the easiest is by using the following snippet:

    <script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
    <script type="text/javascript">
      (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');
    
      tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
      tap('conversion');
    </script>
    

    {{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

Important: This concludes our setup instructions for our most basic form of integration. With this way of integration you won’t be able to to cross-reference conversions, use percentage based commissions, set up lifetime/recurring commissions, or track customers/trials/leads.

If you want to make use of any of these features, please read on below to find the formatting option that best matches your use case.

Optional: Cross-referencing and deduplication

We strongly advise you to send along a unique conversion id when tracking a conversion. This id can be anything that is meaningful to you, like an order id, user id, lead email address etc.. If you send a conversion id along in our tracking code, you will then be able to see this id alongside the conversion data on our platform. This will allow you to cross-reference data on our platform with your own administration. Next to that, we perform automatic deduplication for you based on the id.

To send along a conversion id, please add it as the second argument to the ‘conversion’ method in our conversion page code:

<script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
<script type="text/javascript">
  (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');

  tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
  tap('conversion', '((((Unique Conversion Id))))');
</script>

{{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

  • [[[[Unique Conversion Id]]]] is a unique id that should be generated on your end - you need to replace this placeholder text by an actual tag or variable that will automatically inject the respective value on each conversion. It can be anything that is meaningful to you, and unique for each transaction: an order number, transaction number, etc. After a conversion has taken place, you can find this id alongside the conversion on our platform. This makes it very easy to cross-reference data on our platform with your own administration.

Optional: Percentage-based commissions

If you would like to use percentage based commissions, i.e. to have the commission be a percentage of e.g. the order amount, you will need to send along this amount in the conversion code like so:

<script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
<script type="text/javascript">
  (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');

  tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
  tap('conversion', '((((Unique Conversion Id))))', ((((Conversion Amount)))));
</script>

{{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

  • [[[[Unique Conversion Id]]]] see above.
  • [[[[Conversion Amount]]]] is the total value of the conversion. We use this value to calculate any percentage-based commissions you might have set up for your program. Be aware you also need to replace the placeholder text in the code by the actual tag or variable that passes this data on your website, dynamically injecting a new value on each transaction.

Optional: Lifetime/Recurring commissions

If you are looking to set up lifetime/recurring commissions, you will have to send a customer id when you track a conversion, and send it like so:

<script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
<script type="text/javascript">
  (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');

  tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
  tap('conversion', '((((Unique Conversion Id))))', ((((Conversion amount)))), {customer_id: "((((Customer Id))))" });
</script>

{{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

  • [[[[Unique Conversion Id]]]] see above.
  • [[[[Conversion Amount]]]] see above.
  • [[[[Customer Id]]]] is a unique customer id that should be generated on your end - you need to replace this placeholder text by an actual tag or variable that will automatically inject the respective value on each conversion. It can be anything that is meaningful to you and unique for each customer: a user id, an account number, an email address, etc. You can find this customer id alongside the conversion on our platform. This makes it very easy to cross-reference data on our platform with your own administration.

For more information on how to attach future reccurring commissions via the REST API or Zapier, please refer to our lifetime/recurring commissions guide.

Note: Remember to make sure you have the lifetime/recurring commissions option in your program toggled ON, so that commissions are attributed accordingly.

Optional: Track a sign-up

If you’d only like to track the customer without attaching any conversions just yet, you can track the customer.

Depending on your use case, you may replace customer in the code with the alias that best suits your use case. You may choose from the following: customer, trial, or lead.

<script src="https://script.tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
<script type="text/javascript">
  (function(t,a,p){t.TapfiliateObject=a;t[a]=t[a]||function(){ (t[a].q=t[a].q||[]).push(arguments)}})(window,'tap');

  tap('create', '((((YOUR ACCOUNT ID))))', { integration: "javascript" });
  tap('customer', '((((Customer Id))))');
</script>

{{{{NO_ACCOUNT_ID_SET_MESSAGE}}}}

  • [[[[Customer Id]]]] see above.

After you have tracked your customer, future conversions may be attached. Please refer to this guide for further information on how conversions may be attached.

Note: Remember to make sure you have the lifetime/recurring commissions option in your program toggled ON, so that commissions are attributed accordingly.

Advanced tracking

For an overview of additional tracking posibilities, like conversion metadata, using commission types, handling multiple currencies, coupon tracking and more, please check our complete tapfiliate.js reference.

Important

Please remember to test a conversion before starting your program. This way you can verify that tracking has been set up correctly. You can create a test conversion by following the steps described here.

Start a 14-day free trial with all our features enabled