Transferring Affiliates Data From One Domain To Another In Case of Cross-Domain Sales Tracking

To track sales effectively, you need to complete two steps: the click tracking code must be inserted into the landing pages of your banners or links, and the sales tracking code (generally integrated into the Thank You page) must reside within the same domain as the landing pages to properly track sales.

But what if your landing page is not on the same domain as the Thank You page containing the sales tracking code? The best approach is to transfer the tracking information (visitor ID).

When the tracking cookie is created, it contains only one value—the visitor ID. It does not matter whether the visitor to your site was referred by an affiliate or not; the visitor ID is always generated. However, if a referring affiliate was involved, the visitor ID value is internally (in database) linked with information such as affiliate ID, banner ID, campaign ID, browser information, etc.

Sending visitor ID to the new domain

To retain the same referral information across both domains, you simply need to carry over the visitor ID from one domain to another. The code for this transfer is provided below. The main idea is to append the visitor ID to the link that takes the customer to the other domain. The code is JavaScript and should be placed on the HTML pages containing the redirect links (i.e., links redirecting from the domain with the landing page to the domain with the Thank You page).

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 a PAN account. Set your account ID here instead of 'default1'.
  PostAffTracker.writeCookieToLink('link_id', 'visitorId');
</script>

The first step is done here.

Note that the links to which you want to append the visitor ID must contain the specified id="link_id" (this is the identifier used by the script above—you may change the ID if needed), so the link will appear as follows:

<a href="https://www.wheretomigrate.com/site.html" id="link_id">Click here</a>

Receiving and setting the visitor ID in cookies on a new domain

The second and final step is to receive the value sent as visitorId and set it in the cookies of the new domain. You can retrieve this value using PHP and then insert it into your site with JavaScript, or you can use JavaScript for both operations. Below is an example of how to accomplish this using only JavaScript:

<script type='text/javascript'>
var urlParams = new URLSearchParams(window.location.search);
var visitorId = '';
if (urlParams.get('visitorId') !== null) {
  visitorId = urlParams.get('visitorId');
}

if (visitorId !== '') {
  PostAffTracker.setVisitorId(visitorId);
}
</script>

It is important to ensure that this code is executed before any sale tracking takes place.

Specific details from cookies

If you need to retrieve the affiliate ID or campaign ID for any reason, use the following PHP code:

<?php 
    require_once 'PapApi.class.php';

    // Initialize 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 retrieve the referral ID as well
    }
    if ($clickTracker->getCampaign() != null) {
        $a_cid = $clickTracker->getCampaign()->getValue('campaignid'); // Retrieve campaign ID
    }
?>

You can then use the variables $a_aid and $a_cid to append them to the link as follows:

<a href="https://www.wheretomigrate.com/site.html<?php echo ("?a_aid=$a_aid&amp;a_cid=$a_cid"); ?>">Click here</a>
×