# Tracking script

# What is Tracking Script?

The tracking script is a small js-library that can transfer information about clicks and conversions. This allows you to quickly connect Keitaro to the already running landing page so that you don't have to redirect traffic and change links. It is also possible to use it on the final landing pages where leads are collected.

# Tracking script restrictions

  1. A tracking script doesn't support the landing pages split.
  2. Redirects are not supported.
  3. Campaigns can't be run with a tracking script.

# How to use

Please see page Landing Pages.

# How to count non-unique clicks?

In the default settings, the tracking script counts only the first visit, after which the script keeps all the information about this click in cookies. To count non-unique clicks, add _new=1 parameter to the page link, where the script is installed, e.g. http://landingpage.com/?_new=1.

There is another option. You can switch collectNonUniqueClicks to true:

collectNonUniqueClicks: true

Is param is included in the tracking script snippet

if (!window.KTracking){window.KTracking={collectNonUniqueClicks: true, R_PATH:...

# Sending conversions

Conversions are sent by using the method KTracking.reportConversion. Here are some examples.

  • Making a sale:

KTracking.reportConversion(revenue, 'sale');

Instead of revenue enter the amount of income or 0.

  • Sending a conversion with parameters:

KTracking.reportConversion(revenue, 'lead', {extra_param_1: 'johh@gmail.com', extra_param_2: 'John Smith'})

  • Cancellation of conversion:

KTracking.reportConversion(revenue, 'rejected');

  • With passing the parameters:

KTracking.reportConversion(revenue, 'sale', {sub_id_10: 'order 1'})

You can send parameters sub_id_1..10 and extra_param_1..10.

  • For upsells and rebills send a unique (for subid) tid:
var tid = Math.floor(Math.random() * 1000000000);
KTracking.reportConversion(revenue, 'sale', {tid: tid})

# Sending postbacks on PHP

There are two ways to get subid for the postback:

  1. Insert subid in the links or the form
  2. Get subid from the cookies

Here's how you can get subid from the cookies

file_get_contents('http://keitaro.com/xxxxxx/postback?sub_id=' . $_COOKIE['subid']. '&payout=0.10&status=sale');

  1. Add the code to the page:
function keitaro_report_conversion(link, revenue, status, tid) {
   KTracking.reportConversion(revenue, status, tid, function() {
       window.location = link.href;
    return false;
  1. Add to the links:

<a onclick="keitaro_report_conversion(this, 0, 'lead')" href="http://google.com">link</a>

# Sending a postback with sending a form

Read a post in our blog. (opens new window)

Put a code on a page:

<script type='application/javascript'>
function reportConversion(el, status, params) {
    var form = (el && el.form) ? el.form : el;
    var params = params || {};
    var status = status || 'lead';

    [].map.call(form.elements, function(el) {
      if (el.name != '') {
          params[el.name] = el.value;

    KTracking.reportConversion(params.payout || 0, status, params);
    return true;


Add an attribute onclick="reportConversion(event.target)" to the button of sending a form, e.g.:

<a href="reportConversion(event.target, 'lead', {payout: 10})">Send an Order</a>

You can accept a form content. Fill in the Parameters table in a campaign's settings. Put inputs' names in the first column, e.g. <input type="text" name="name"> and the parameter's name is name.

# Sending a postback from a "Thank You" page

Insert a tracking script code on a page and add the following code below:

 KTracking.reportConversion(0, 'lead', 'tid');

0 - conversion sum lead - status tid - Transaction ID

# How to get 'subid'

KTracking.ready(function(subid, token) {
    alert('SubId: ' + subid + ', Token: ' + token);

Use the macro {subid} in the links:

<a href="http://offer.com/?id=123123&subid={subid}">go to an offer</a>

# How to add 'subid' to a form?

Add input with name subid to the form:

<input type="hidden" name="subid" />

# How to send 'subid' in PHP

You must have at least 2 pages:

  1. Landing page (with installed tracking script)
  2. Submit page

On the submit page you can get current subid in variable $_COOKIE['subid']:

$subid = $_COOKIE['subid'];

Use macro {offer} in the links:

<a href="{offer}">Link to offer</a>

Make sure, that campaign streams contain offers.

Use macro {offer} with parameter offer_id=ID in the links:

<a href="{offer}&offer_id=1">Link to offer 1</a>
<a href="{offer}&offer_id=2">Link to offer 2</a>

# Updating the click parameters

To update the parameter use the method KTracking.update:

KTracking.ready(function() {
   KTracking.update({sub_id_1: window.navigator.cookieEnabled})

You can update parameters sub_id_1..15.

# Why doesn't a tracking script work with a website with HTTPS?

Keitaro should also be installed on a domain with an HTTPS protocol. Otherwise, a browser will block all connections as insecure.

  • What is Tracking Script?
  • Tracking script restrictions
  • How to use
  • How to count non-unique clicks?
  • Sending conversions
  • Sending postbacks on PHP
  • Sending postback after clicking the link
  • Sending a postback with sending a form
  • Sending a postback from a "Thank You" page
  • How to get 'subid'
  • How to add 'subid' to links
  • How to add 'subid' to a form?
  • How to send 'subid' in PHP
  • How to add offer link
  • How to add links to multiple offers
  • Updating the click parameters
  • Why doesn't a tracking script work with a website with HTTPS?