Pap_Api_ClickTracker

It is possible to replace standard click tracking using javascript code with PHP version of click tracking.

Javascript version looks like this:
<script type="text/javascript" id="pap_x2s6df8d" src="https://URL_TO_PAP/scripts/trackjs.js"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('default1');
try {
PostAffTracker.track();
} catch (err) { }
</script>
NOTE: URL_TO_PAP  has to be replaced with the REAL URL of your installation of Post Affiliate Pro or Post Affiliate Network
Notice: API click tracking doesn't work with Anchor links.
 
PHP version of the click tracking has to be placed on all landing pages (the same as with javascript version) and looks like this:
<?php 

    //PapApi.class.php can be downloaded in the merchant panel at 
    //Tools>Integration>API Integration>Download PAP API 
    require_once 'PapApi.class.php';  

    // init session for PAP
    $session = new Pap_Api_Session("https://URL_TO_PAP/scripts/server.php");
    
    // register click
    $clickTracker = new Pap_Api_ClickTracker($session);

    $clickTracker->setAccountId('default1');

    //if you need to set customer's IP use this row, otherwise is used IP recognized from $_SERVER['REMOTE_ADDR']
    //$clickTracker->setIp('123.456.789.1');

    try {  
        $clickTracker->track();
        $clickTracker->saveCookies();
    } catch (Exception $e) {
    }
?>
For PAN you need to set right account Id into click tracker by using function setAccountId($accountId)
 
$clickTracker->saveCookies(); will output javascript code that saves all necessary cookies. This function outputs javascript code because it needs to save also HTML5 local storage cookies.
Warning: If you do not call this function, sales won't work.

If you do not wish to save cookies using javascript, you can use following code:
    // save cookies
    $clickTracker->save3rdPartyCookiesOnly();

This code will save browser cookies only (cookies are saved by php script). Optional parameter for the save3rdPartyCookiesOnly() is cookie domain (this can save cookie under higher domain).
Warning: if you save 3rd party cookies only, all tracking (click + sale) will be working on one same domain only.

If you need to save the ID of the generated cookie for later use in S2S tracking for example you can use the following after try catch in the above code:

$clickTracker->getVisitorId();

After click is saved (method track() was called) you can use the information about the affiliate through which the click was made. Also you can use the information about the campaign and channel and display it on your site:

    if ($clickTracker->getAffiliate() != null) {
        echo $clickTracker->getAffiliate()->getValue('userid'); // prints affiliate userid
        echo $clickTracker->getAffiliate()->getValue('refid'); // prints affiliate refid
    }

    if ($clickTracker->getCampaign() != null) {
        echo $clickTracker->getCampaign()->getValue('campaignid'); // prints campaign id
    }

    if ($clickTracker->getChannel() != null) {
        echo $clickTracker->getChannel()->getValue('channelid'); // prints channel id
        echo $clickTracker->getChannel()->getValue('channel'); // prints channel code
        echo $clickTracker->getChannel()->getValue('name'); // prints channel name
    }
NOTE: channel name and channel code can be obtained only if you initiated a merchant session via php API prior to triggering the click tracking code.
To login via php API as a merchant use the following code for session initialization:
    // init merchant session for PAP
    $session = new Pap_Api_Session("https://URL_TO_PAP/scripts/server.php");
    if(!$session->login("MERCHANT_USERNAME", "MERCHANT_PASSWORD")) {
        echo("Cannot login. Message: ".$session->getMessage());
    }
 
If you login before calling click tracker you will get additional info for affiliate.
 
Additional info available after login.

Affiliate:
username
rpassword
firstname
lastname
parentuserid
dateinserted - date when affiliate joined the program
dateapproved - date when affiliate was approved
minimumpayout
note
photo
data1 - see Configuration -> Affiliate signup -> Fields
...
data25

Campaign:
accountid
rtype
rstatus
name
description
dateinserted
rorder
networkstatus
logourl
productid
discontinueurl
validfrom
validto
validnumber
validtype
cookielifetime
overwritecookie
countries
geocampaigndisplay
geobannersshow
geotransregister

Other Articles

×