Professional affiliate marketing with XML pt2
2/05/2008 by paul
In my previous article I created the affiliate links using a reformatted RSS feed from another site. This solves the problem of having those links indexed by the search engines because the code is generated server-side instead of with JavaScript on the viewers' browser.
However, applying the affiliate tags in the normal way, by appending a value to the query string, could interfere with the search engine capital gains from using XML. For example, instead of indexing normal links to the remote site, the crawlers will index those links with an affiliate tag on the end. At the extreme, these may end up as the preferred URLs in the search engines, and the affiliate will be hitting a score everytime someone finds your site through a search engine!
To get around this problem, we're going to use the limitations of the JavaScript method to our advantage by using it to add the affiliate tags post-download.
This is done by setting all relevant external links to the remote site to a specific class. When the page loads, a JavaScript call then changes the href attribute of links of that class and appends the affiliate tag.
<a href="http://www.camera-warehouse.com.au/product.asp?pr=PENTAX-K20D" class="M afftag">Pentax K20D</a>
Pentax K20D
The box above shows the same link, firstly as it is created initially and as search engine crawlers see it. There are two class names 'M' and 'afftag' and these will be treated seperately by CSS so long as they're separated by a space. This allows you to apply a valid styling class, in this case 'M', to the link as well as the 'afftag' class, which isn't declared in CSS and will only be used to identify the links to change. The second is that same link with the JavaScript update applied. For confirmation, check the source code of this page and the affID tag will not appear in the link.
The code below is the JavaScript snippet that does the work. This identifies the links with class 'afftag' (using a getElementsByClassName() method I found online, though I can't find the link...sorry!) and a simple changelinks() function that cycles through each and appends the affID, defined elsewhere in the page. The function also checks if there are any other elements in the querystring and adjusts accordingly (& or ?).
<script type="text/javascript" language="javascript">
//<!--
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};
function changelinks(affID) {
var links = document.getElementsByClassName('course');
for (var i = 0; i < links.length; i++) {
var ql = links[i].href.indexOf('?');
if(ql < 0) {
links[i].href=links[i].href + '?affID=' + affID;
}
else
{
links[i].href=links[i].href + '&affID=' + affID;
}
}
}
var affID=1010;
changelinks(affID);
//-->
</script>
The reliance on JavaScript to add the affiliate tag may be seen (particularly by the affiliate) as a weakness, compared to the potential benefits of adding a static affID to the link. This negates the reliance on JavaScript being enabled, and may bring the affiliate additional hits if the search engines adopt their links.
Keywords : javascript, rss, xml, cross-site pollenation, affiliate marketing,
