About
This plugin (available from version 5.4.12.8) enables you to display affiliate details in any page by placing a simple script to the page. You can load affiliate name, email, photo and 5 data fields defined by you in the plugin configuration. The data fields loads values from affiliate fields defined by you in Configuration> Affiliate signup> Fields.
How to use the plugin
To display affiliate info in a page, simply place the following code to the page, with the proper parameter:
<span id="papXXXXXX"></span> <script type="text/javascript" id="pap_x2s6df8d" src="https://_PATH_TO_YOUR_PAP_/scripts/trackjs.js"></script> <script type="text/javascript"> PostAffTracker.setAccountId('default1'); try { PostAffTracker.track(); } catch (err) { } PostAffTracker.executeOnResponseFinished.push(function() { PostAffTracker.getAffInfo().call(function() { var papAffID = PostAffTracker.getAffInfo().getAffiliateId(); var affInfoScript = document.createElement('script'); affInfoScript.setAttribute('src','https://_PATH_TO_YOUR_PAP_/plugins/AffiliateInfo/affiliateinfo.php?userId=' + papAffID + '¶m=XXXXXX'); affInfoScript.setAttribute('type','text/javascript'); document.body.appendChild(affInfoScript); }); }); </script>
Remember to set a proper URL to your Post Affiliate Pro installation.
Replace the value XXXXXX in the link and the SPAN element with one of the following values, depending on what do you want to display:
- name
- email
- photo
- field1 to field12
- all (this will display all enabled values in one call, but still you have to use all SPAN elements for proper placement)
NOTE: In case you would want to have an element (for example affiliate name) on your website multiple times then instead of "id=" in the span elements use "class=" so for example the affiliate name would be added everywhere where it should show up with <span class="papname"></span>. This works from version 5.4.31.6
E.g. if you wanted to display affiliate email, replace the value XXXXXX with "email":
<span id="papemail"></span> <script type="text/javascript" id="pap_x2s6df8d" src="https://_PATH_TO_YOUR_PAP_/scripts/trackjs.js"></script> <script type="text/javascript"> PostAffTracker.setAccountId('default1'); try { PostAffTracker.track(); } catch (err) { } PostAffTracker.executeOnResponseFinished.push(function() { PostAffTracker.getAffInfo().call(function() { var papAffID = PostAffTracker.getAffInfo().getAffiliateId(); var affInfoScript = document.createElement('script'); affInfoScript.setAttribute('src','https://_PATH_TO_YOUR_PAP_/plugins/AffiliateInfo/affiliateinfo.php?userId=' + papAffID + '¶m=email'); affInfoScript.setAttribute('type','text/javascript'); document.body.appendChild(affInfoScript); }); }); </script>
The script will load the affiliate email and display it in the SPAN element, so you can place the span element to the place where you need it. Make sure the SPAN element is placed before the javascript code, as it is in the above example.
Remember that the value is returned only in case it has been set in the plugin configuration. When it is not set or is not enabled, no value is returned, so nobody will be able to read any affiliate personal data except those info you enabled.
E.g. if you wanted to display more affiliate fields, use url param "all":
<span id="papname"></span> <span id="papemail"></span> <span id="papphoto"></span> <span id="papfield1"></span> <span id="papfield2"></span> <span id="papfield3"></span> <span id="papfield4"></span> <span id="papfield5"></span> <span id="papfield6"></span> <span id="papfield7"></span> <span id="papfield8"></span> <span id="papfield9"></span> <span id="papfield10"></span> <span id="papfield11"></span> <span id="papfield12"></span> <script type="text/javascript" id="pap_x2s6df8d" src="https://_PATH_TO_YOUR_PAP_/scripts/trackjs.js"></script> <script type="text/javascript"> PostAffTracker.setAccountId('default1'); try { PostAffTracker.track(); } catch (err) { } PostAffTracker.executeOnResponseFinished.push(function() { PostAffTracker.getAffInfo().call(function() { var papAffID = PostAffTracker.getAffInfo().getAffiliateId(); var affInfoScript = document.createElement('script'); affInfoScript.setAttribute('src','https://_PATH_TO_YOUR_PAP_/plugins/AffiliateInfo/affiliateinfo.php?userId=' + papAffID + '¶m=all'); affInfoScript.setAttribute('type','text/javascript'); document.body.appendChild(affInfoScript); }); }); </script>
The plugin works with browser cookies and GET params from the affiliate link (in case it is used). First, the plugin will try to load the cookie PAPVisitorId and if it is not found, the plugin will try to load affiliate ID from the referring URL - by default a_aid. If no affiliate is recognized from cookies of from URL, no affiliate info is set to the SPAN elements.
How to display 'custom text' ONLY if affiliate info is used
Let's say you want to add some own text above affiliate info. Something like "Your affiliate is:" and then continue with real data. If you would just wrote your custom text within 'span' blocks, text would be always displayed on the page. Even if there is no affiliate recognized. If you want display custom text only when click is referred by some affiliate, you can do it this way:
<div id="papAffiliateInfo" style="display:none"> <b>Your affiliate is:</b> <span id="papphoto"></span> <span id="papname"></span> <span id="papemail"></span> </div> <script type="text/javascript" id="pap_x2s6df8d" src="https://_PATH_TO_YOUR_PAP_/scripts/trackjs.js"></script> <script type="text/javascript"> PostAffTracker.setAccountId('default1'); try { PostAffTracker.track(); } catch (err) { } PostAffTracker.executeOnResponseFinished.push(function() { PostAffTracker.getAffInfo().call(function() { var papAffID = PostAffTracker.getAffInfo().getAffiliateId(); var affInfoScript = document.createElement('script'); affInfoScript.setAttribute('src','https://_PATH_TO_YOUR_PAP_/plugins/AffiliateInfo/affiliateinfo.php?userId=' + papAffID + '¶m=all'); affInfoScript.setAttribute('type','text/javascript'); document.body.appendChild(affInfoScript); }); }); MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var observer = new MutationObserver(function(mutations, observer) { for (i = 0; i < mutations.length; i++) { for (j = 0; j < mutations[i].addedNodes.length; j++) { if(mutations[i].addedNodes[j].nodeName == '#text' || mutations[i].addedNodes[j].nodeName == 'IMG') { document.getElementById('papAffiliateInfo').style.display='block'; } } } }); observer.observe(document.getElementById('papAffiliateInfo'), { subtree: true, childList: true }); </script>
NOTE: This code works with the SPAN elements mentioned at the beginning, so you still have to use those...
NOTE2: Enable affiliate fields in plugin carefully, anybody can access these details even you use only one at the page. E.g. after enabling name and email in the plugin and using only email in a site still allows strangers to play with the code at your site and load email address.