In this article we are going to explain what is click tracking code, why is it needed, how does it looks like and what additional options you can do with it. All the code examples are clickable and show you how the specific function is added in default code.
- What is click tracking code and why is it needed
- Different code examples
- Advanced click tracking code (additional functions and paramters)
- How to set Post Affiliate Network account ID
- How to disable creation of flash cookies
- How to create cookie for top domain
- How to force saving click with specified attributes
- How to write visitor's cookie ID or referring affiliate ID to site elements
- How to load referring affiliate ID to use in your code directly without writing it
To track affiliate referrals (both clicks and sales), your target pages (landing pages) has to contain click tracking code. Even if you want to track sales only, you have to insert click tracking code first. Without it, the sale will be registered to default affiliate or won't be registered at all.
The target page is the page to which your banners/links point. Usually the best practice is to put click tracking code somewhere into general footer template, so it is included in every page of your website.
To get the integration code you need to go into your Post Affiliate Pro (Network) merchant panel and copy the code from Tools->Integration->Click tracking.
this is the simple version of the code, it has 4 requirements:
- Correct URL to your PAP instead of URL_TO_PostAffiliatePro
- Correct protocol HTTP/HTTPS, if the website which you are tracking has SSL certificate so is available via HTTPS you need to have SSL certificate for your PAP as well so it is available with HTTPS as well.
- Correct AccountId in PostAffTracker.setAccountId() line. All Post Affiliate Pro owners will always have account ID default1. Owners of Post Affiliate Network will find the account ID in Accounts->Accounts manager part of their owner panel.
- Code placed within <body> </body> section of your website so it can create all types of cookies.
ID of your network merchant account is set in the following function. Post Affiliate Pro owners will always have ID "default1":
In case you wish to disable flash cookie creation for any reason, then you need to add the following line to your code:
In case you add your click tracking code to all your domains and subdomains (highly recommended) then you don't need to use this option.
However if you don't want to add click tracking code everywhere and your landing page is a subdomain and payment page is either the top domain or a different subdomain, then you need to create the 1st party cookie for the top domain instead of the landing subdomain. Example to make it more clear:
- landing page is landing.maindomain.com
- checkout is at checkout.maindomain.com
One option is to add click tracking to both subdomains, but if you want your click tracking only on landing.maindomain.com, then you must create the cookie for maindomain.com. Normally it would be created only on landing.website.com. The following function would help:
There are many uses for the following. For example you want all visits to website A to be tracked in website A campaign so you would force a campaign. Other example is that you have a dedicated affiliate page which should tie the visitor to affiliate on visit so you would force an affiliate in the code.
You can use these options to force stuff into the click. If you force affiliate, then all visits of the page will be saved as clicks for that affiliate.
var AffiliateID='affiliate id'; var BannerID='banner id'; var CampaignID='campaign id'; var Channel='channel'; var Data1='data1'; var Data2='data2';
You can read more about Channel, Data1 and Data2 variables in our SubID article.
this section is useful mainly for server side integrations where you need to save/pass the visitor's identification so the server can work with it afterwards. For example you need to read the visitor's cookie and save it in your database so that your server can later execute postbacks to your PAP. In that case the ideal place for saving the cookie is during the visitor's registration on your website so you would add the cookie to hidden input field in your form.
- The writeCookie functions return a 40 characters long string where the first 8 characters is the AccountId and the last 32 characters are the visitorId, so you'd need to split the string before you send it to sale.php.
- Function setParamNameUserId() is available since 184.108.40.206 and is used when in your Configuration->URL parameter names you have defined a different Affiliate ID parameter, than the default a_aid.
The function tells the writeAffiliate functions to look into the URL of the opened page for that specific parameter in case your writeAffiliate function will not recognize affiliate from cookie. This does NOT need to be used with the writeCookie functions.
- Affiliate might not be recognized from cookie if the affiliate link pointed directly to the page where the writeAffiliate function was used because the click on link was not processed yet by PAP, it can take a minute. You might want to check if the affiliate ID was actually written to your field/link before the page with this code is left by the customer and execute your writeAffiliate function again. This does NOT apply to the writeCookie functions.
// writes the cookie value to an input field inside your HTML with defined ID. PostAffTracker.writeCookieToCustomField('id_field'); // appends the cookie value to <a> link with id="id_field" after papCookie URL parameter. PostAffTracker.writeCookieToLink('id_field', 'papCookie'); // if you use different affiliate parameter than a_aid in Configuration->URL parameter names specify it here. PostAffTracker.setParamNameUserId('a_aidCustom'); // writes the ID of the referring affiliate to an input field inside your HTML with defined ID. PostAffTracker.writeAffiliateToCustomField('id_field'); // writes the ID of the referring affiliate to <a> link with id="id_field" after a_aid URL parameter. PostAffTracker.writeAffiliateToLink('id_field', 'a_aid');
available since 220.127.116.11. This option is useful if you don't really need to write the ID of the referring affiliate to any element of your website but you want to use it directly in your code. Without this new option you'd need to use some timeout or interval to check whether the ID was written to your element to get the ID from there. With this new option you don't need to write the ID at all.