If you want to show the customer/visitor of your shop that he/she was referred by some affiliate, it is possible by using our API. You can e.g. show the whole block of information that can be useful for this customer/visitor.
This is useful for signups when you want to show your customer that he was referred by somebody, so the customer will have a parent affiliate...
To show a table like this in red:
This is useful for signups when you want to show your customer that he was referred by somebody, so the customer will have a parent affiliate...
To show a table like this in red:
you will need to use this code:
<?php
include ("pap/api/PapApi.class.php");
$session = new Pap_Api_Session("https://www.yoursite.com/pap/scripts/server.php");
if(!$session->login("merchant@username.com", "password")) { // change it here please
die("Cannot login. Message: ".$session->getMessage());
}
$clickTracker = new Pap_Api_ClickTracker($session);
try {
// save the cookies first, if the parameters exist in the link
$clickTracker->track();
$clickTracker->saveCookies();
/* if you want to save cookies for the default affiliate, then remove the comments from this block
if ($clickTracker->getAffiliate() == null) {
// save default cookies if there were no affiliate parameter in link
$clickTracker->setAffiliateID('testaff'); // default affiliate
$clickTracker->track();
}
*/
if ($clickTracker->getAffiliate() != null) {
//echo "Affiliate loaded successfully";
?>
<table style="border: 1px solid red;">
<tr>
<td>You were referred by <strong>
<?php
echo $clickTracker->getAffiliate()->getValue('firstname')
.' '. $clickTracker->getAffiliate()->getValue('lastname')
.' ('. $clickTracker->getAffiliate()->getValue('refid') . ')';
?>
</strong></td>
</tr>
<tr>
<td>from <strong>
<?php
echo $clickTracker->getAffiliate()->getValue('data5');
?>
</strong></td>
</tr>
</table>
<?php
} else {
//echo "Cannot load affiliate";
}
} catch (Exception $e) {
//die("Error while communicating with PAP: ".$e->getMessage());
}
?>
If you need to show more information, you can take a look at API specification of affiliates.
NOTE: in case there is a cron job set up in your Post Affiliate Pro (in all the hosted solutions there is), then the cookie (PAPVisitorId) is processed offline after 2-3 cron runs. In that case, a little bit different approach is needed:
The following approach is a bit outdated and we strongly recommend to use more recent approach using a built in plugin to achieve this.
First of all, you will need to create an 'affiliateInfo.php' file that will be uploaded somewhere in your server along with the PapApi.class.php file (can be downloaded from the merchant panel of Post Affiliate Pro at Tools > Integration > API Integration).
The 'affiliateInfo.php' file is going to include the following code:
<?php
include_once "PapApi.class.php"; //this include assumes the PapApi.class.php file is in the same folder as this script itself
include_once "PapApi.class.php"; //this include assumes the PapApi.class.php file is in the same folder as this script itself
global $papUrl,$papUsername,$papPwd;
$papUrl = "URL_TO_PostAffiliatePro"; //URL to Post Affiliate Pro (network) without protocol and trailing slash
$papUsername = "merchant@example.com";
$papPwd = "123456";
$papUrl = "URL_TO_PostAffiliatePro"; //URL to Post Affiliate Pro (network) without protocol and trailing slash
$papUsername = "merchant@example.com";
$papPwd = "123456";
if (isset($_GET['affuserid'])) {
echo getInfoOfReferringAffiliate($_GET['affuserid']);
}
echo getInfoOfReferringAffiliate($_GET['affuserid']);
}
function papLogin() {
global $papUrl,$papUsername,$papPwd;
$session = new Pap_Api_Session("https://".$papUrl."/scripts/server.php");
if(!@$session->login($papUsername, $papPwd)) {
echo "<!-- cannot login to API -->";
return;
}
return $session;
}
global $papUrl,$papUsername,$papPwd;
$session = new Pap_Api_Session("https://".$papUrl."/scripts/server.php");
if(!@$session->login($papUsername, $papPwd)) {
echo "<!-- cannot login to API -->";
return;
}
return $session;
}
function getInfoOfReferringAffiliate($userid) {
if (!papLogin()) {
return;
}
$session = papLogin();
if (!papLogin()) {
return;
}
$session = papLogin();
if (!empty($userid)) {
$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUserid($userid);
try {
$affiliate->load();
} catch (Exception $e) {
//echo "Cannot load record: ".$affiliate->getMessage();
return;
}
//See https://support.qualityunit.com/961744-Pap_Api_Affiliate regarding all available affiliate details
$affiliate = $affiliate->getFirstname()." ".$affiliate->getLastname();
return $affiliate;
}
}
?>
$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUserid($userid);
try {
$affiliate->load();
} catch (Exception $e) {
//echo "Cannot load record: ".$affiliate->getMessage();
return;
}
//See https://support.qualityunit.com/961744-Pap_Api_Affiliate regarding all available affiliate details
$affiliate = $affiliate->getFirstname()." ".$affiliate->getLastname();
return $affiliate;
}
}
?>
Secondly, you will need to use the JavaScript click tracking code along with a special code in your website's footer and that code will all the 'affiliateInfo.php' file via iframe:
<!-- PAP integration snippet --> <input type="hidden" id="affCookieInfoId" name="affCookieInfoId" value=""> <script type="text/javascript"> document.write(unescape("%3Cscript id=%27pap_x2s6df8d%27 src=%27" + (("https:" == document.location.protocol) ? "https://" : "https://") + "URL_TO_PostAffiliatePro/scripts/trackjs.js%27 type=%27text/javascript%27%3E%3C/script%3E")); </script> <script type="text/javascript"> PostAffTracker.setAccountId('default1'); PostAffTracker.track(); </script> <script type="text/javascript"> PostAffTracker.writeAffiliateToCustomField('affCookieInfoId'); </script> <script type="text/javascript"> setTimeout(function(){ var affUserIdFromCookie=document.getElementById('affCookieInfoId').value; if (affUserIdFromCookie != "") { var affinfoPlace = document.getElementById('affinfo'); if (affinfoPlace) { //let's append the current date to the request url to fight the browser cache if (!Date.now()) { Date.now() = function() { return new Date().getTime(); }; } var dateInMiliseconds = Date.now(); affinfoPlace.innerHTML = "<iframe src='https://URL_TO_affiliateInfo.php?affuserid="+affUserIdFromCookie+"&dateInMiliseconds="+dateInMiliseconds+"' width='550px' height='35px' frameborder='0' style='float: right;'></iframe>"; } } }, 3000); </script> <!-- PAP integration snippet ends here -->
NOTE: the URL_TO_PostAffiliatePro must be replaced with the URL address leading to your installation of Post Affiliate Pro (Network) without protocol (https:// or https://)
Finally, somewhere on your page, where the affiliate details are supposed to be displayed, you will have to place:
<span id="affinfo"></span>
That's it.