Transferring affiliates data from one domain to another in case of tracking the sale

 
To track the sales you have to do two steps - click tracking code has to be inserted in the landing pages of your banners and links and also the sales tracking code (in general integrated with the thank you page) has to be within the same domain as the landing pages to track the sales properly.

But what if your landing page is not at the same domain as the "thank you page" containing the sales tracking code? You can transfer the affiliate information.


NOTE: In case you do not use Standard Link (redirect) linking method and on the other domain (where the purchase happens) there is no click tracking code, then you do not need to follow the instructions below, since Flash cookies (set by Post Affiliate Pro click tracking code) are cross-domain cookies.


The code for the transfer is below. The main idea is to append the affiliates ID and campaign ID within the cookies to the link. It is a JavaScript code used in those HTML pages which contain the redirect links (links which redirect from the 'landing page' domain to the 'thank you page' domain). You can also use API for smoother usage, but it can be used only in PHP. So here is the code for HTML:
JavaScript code:
<script id="pap_x2s6df8d" src="path_to_PAP/scripts/salejs.php" type="text/javascript">
</script>
<script type="text/javascript">
  //PostAffTracker.setAccountId('default1');  //use this line for PAN account, set here your account Id instead of default1 
  PostAffTracker.writeAffiliateToLink('affLinkId', 'a_aid');
</script>
Note that your links where you want to append the cookies, have to contain id="affLinkId" (it is identification from the script above - you can change both) so the link will look like this:
 
<a href="https://www.wheretomigrate.com/site.html" id="affLinkId">Click here</a>
The following script is valid only for version PAP 4.3.x and older.
 
PHP code:
<?php
if (array_key_exists('PAPCookie_Sale', $_COOKIE)) { 
$cookieParams = $_COOKIE['PAPCookie_Sale'];
$cookieParams = stripslashes($cookieParams);
$papvars = json_decode($cookieParams);

$a_aid= $papvars->{'a'};
$a_cid= $papvars->{'c'};
}
?>
The following script is valid only for version PAP 4.4.x and higher.
For obtaining affiliate ID or campaign ID use this PHP code:
 
<?php 
    require_once 'PapApi.class.php';

    // init session for PAP
    $session = new Pap_Api_Session("URL_TO_PAP/scripts/server.php");
    
    // register click
    $clickTracker = new Pap_Api_ClickTracker($session);
    try {  
        $clickTracker->track();
        $clickTracker->SaveCookies();
    } catch (Exception $e) {
    }

if ($clickTracker->getAffiliate() != null) {
        $a_aid = $clickTracker->getAffiliate()->getValue('userid');
        $affiliateRefId = $clickTracker->getAffiliate()->getValue('refid'); // optionally you can get affiliate refid too
    }
if ($clickTracker->getCampaign() != null) {
        $a_cid = $clickTracker->getCampaign()->getValue('campaignid'); // get campaign id
    }
?>
Then you can use variables $a_aid and $a_cid to append it to link:
<a href="https://www.wheretomigrate.com/site.html<?php echo ("?a_aid=". $a_aid . "&amp;". $a_cid); ?>">Click here</a>

Solution for old PAP 3:

If you are using PAP3, then you have to use this code, but the problem is, you will not be able to track the campaign ID... you can only transfer affiliates ID so the default campaign will take effect:
<script type="text/javascript">
<!--
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//-->
</script>

<script type="text/javascript">
<!--
var x = readCookie('POSTAff2Cookie')
if (x) {
  var mySplitResult = x.split("_");
	document.write("<a href=\"https://www.link_to_site_at_another_domain.com/buy.html?a_aid=" + mySplitResult[0] + "\">");
} else {
    document.write("<a href=\"www.link_to_site_at_another_domain.com/buy.html\">");
 }

//-->
</script>
    This is exported link...
  </a>
If you want to use PHP to get values from cookies, use this code:
<?php
    if(!isset($_COOKIE['POSTAff2Cookie']) || $_COOKIE['POSTAff2Cookie'] == '') { 
      $_POST['parentaffiliateid'] = '2';  // default affiliate ID here ...
    } else {
      $temp = explode("_", $_COOKIE['POSTAff2Cookie']);
      $parentaffiliateid = $temp[0];
    }
    ?>
×