Advanced SEO for Affiliate Marketing Links

by SEO Mofo on Jun 14th, 2010

in Advanced SEO, Marketing, Page Speed

Affiliate marketing is primarily about two things: (1) acquiring traffic, and (2) converting that traffic. In my experience, I find that affiliate marketers typically focus more of their time on the conversion rate/click-through rate side of things. However, since I don’t know a damn thing about conversion rates, this article will address the “traffic acquisition” side of things by discussing some advanced SEO techniques I’ve developed specifically for affiliate marketers. Some of this information can be applied to banner advertising-based sites as well.

This article is going to get a bit technical. You’ll need to analyze my code examples and customize them to suit your needs. It’s not completely necessary to know JavaScript, but it will certainly help if you do. If you’re hoping to skim through this article in a few minutes…forget it. You won’t get anything out of it. If you’re hoping for some advanced SEO techniques for affiliate marketers that can minimize PageRank loss and make your pages load a lot faster, then you’re in the right place…but you’ll need to really pay attention. Grab a cup of coffee and then proceed.

Update: I wrote another post about the techniques mentioned in this post. It addresses the question of whether or not these techniques are permitted by the Google Webmaster Guidelines. Check it out: Using JavaScript to Hide Links from Google

Also, when I wrote that second post, I created a diagram of the SEO techniques mentioned in this post. If you are more of a visual learner, then I recommend you check it out: lazy-loading affiliate marketing anchors

Common SEO Issues of Affiliate Marketers

Let’s start by looking at a couple of SEO-related topics that are relevant to a large percentage of affiliate marketing websites–PageRank and page speed.

PageRank

There are a couple of different ways in which PageRank can affect the performance of your affiliate website’s rankings in Google’s search results. For one, you can hinder your rankings by bleeding your site’s PageRank through outbound links to affiliate URLs. Even if your affiliate links contain the rel="nofollow" attribute, there’s still a strong possibility that Google factors them into the calculation of the followed links’ PageRank. In other words, just because the nofollowed links don’t pass PageRank to your affiliate URLs, that doesn’t necessarily mean your remaining links (i.e. the ones without the rel="nofollow" attribute) get a bigger slice of the PageRank pie. The mere presence of nofollowed affiliate links on your web pages might result in an overall loss of site-wide PageRank, a concept some of you may know as “PageRank evaporation.”

The second way that PageRank might affect affiliate marketing sites is less common, but much more severe, and it has to do with Google’s Webmaster Guidelines. One of the things Google (i.e. Matt Cutts) has said repeatedly is that paid links must not pass PageRank. Now granted, paid links are not exactly the same as affiliate links, because theoretically (according to Google’s stupid reasoning) paid links are definitely NOT unbiased, editorial-grade endorsements of the linked content, whereas affiliate links might be. Personally, I’d rather avoid the issue entirely, by making sure none of my affiliate links pass PageRank.

Page Speed

As most of you know, Google has incorporated page speed into its ranking algorithm. This is bad news for any affiliate sites that rely heavily on image links and ad banners, because these resources typically slow down the loading time of your pages.

Affiliate Link Optimization

Here are the basic goals I set for myself when developing my super-advanced SEO technique.

Don’t Lose PageRank

As an SEO–the best in the world, as a matter of fact–my primary concern is avoiding the potential “evaporation” of PageRank that might occur as the result of nofollowed affiliate links in my page content. Therefore, my super-advanced SEO solution must NOT rely on the use of the rel="nofollow" attribute.

Don’t Pass PageRank

In order to comply with Google’s Webmaster Guidelines, my extremely-advanced SEO solution must prevent search engines from crawling my affiliate links or passing PageRank through them.

Follow the FTC Guidelines

The Federal Trade Commission published their Guides Concerning the Use of Endorsements and Testimonials in Advertising, an 80-page document that can be summarized in 3 words: disclose paid endorsements. At least I think that summarizes it…honestly, I didn’t read any of it. My extra-super-advanced SEO solution should automatically identify affiliate links by applying some kind of unique styling or visual aid.

Don’t Slow Down My Page Speed

Affiliate-related content (links, images links, banner ads, etc.) must not delay the loading of my page content…at all.

Make it Degrade Gracefully

If you haven’t guessed yet, my über-advanced SEO solution is going to rely on JavaScript. Therefore, it should degrade gracefully in browsers that don’t have JavaScript enabled. Also, it shouldn’t negatively affect accessibility. So to all you SEOs and affiliate marketers out there who are rockin’ screen readers or whatever…don’t worry, I gotcha covered.

Make it Easy to Use

A small percentage of my dear readers are actually “advanced SEOs”–or advanced anything, for that matter–and I can publish a loosely-defined solution, confident that they will tweak my code or improve on it, in order to meet the specific needs of their website. However, the majority of you have the cognitive abilities of a small piece of driftwood, and for your sakes…my solution should be reasonably easy to implement.

My Incredibly-Advanced SEO Solution

Alright then, Woody, let’s dig in!

What You’ll Need

Here is a generalized list of the various files and page elements that we’ll be working with:

  1. external JavaScript file (e.g. scripts.js)
  2. external stylesheet (e.g. styles.css)
  3. robots.txt file (e.g. robots.txt)
  4. a web page that contains affiliate links

Step 1: Create the JavaScript

Paste the following JavaScript code into your external .js file. I have made lots of comments throughout it, in order to help you understand (and/or customize) the code.

Attribution: My code uses a utility function, called hasClass(), which is from the book JavaScript: The Definitive Guide, 5th Edition, by David Flanagan. Copyright 2006 O’Reilly Media, Inc. (ISBN: 0596101996).

/**
  * Advanced SEO Technique for Affiliate Marketing Links
  * Copyright 2010, Darren Slatten, http://www.SEOmofo.com/
  * 
  * The following code consists of 2 functions. The first 
  * function is a utility function that requires 2 parameters:
  * an element name and a CSS class name. It checks to see if
  * the specified element (e) is a member of the specified class (c),
  * and returns true or false. The element name can be either an
  * id or a tag name. The class name can either be the only class
  * assigned to the element OR it can be one of several CSS classes
  * assigned to the element. This function is used by the second
  * function.
  * 
  * The second function finds all <span> elements that have "affiliate"
  * as one of their CSS classes and then turns them into affiliate
  * links.
  * 
  */



// Utility function for checking if an element (e) is a member of CSS class (c).
function hasClass(e, c) {

// If we passed the function a string, then get the element with that id.
	if (typeof e == "string") e = document.getElementById(e);

// Declare the variable "classes" as the text value of our element's CSS classes.
	var classes = e.className;

// If our element doesn't have any CSS classes assigned to it, return false.
	if (!classes) return false;

// If our element has exactly one class and that class is (c), return true.
	if (classes == c) return true;

// If our element has multiple classes and one of them is (c), return true.
	return e.className.search("\\b" + c + "\\b") != -1;
};



// Function for rendering affiliate links in a way that won't pass PageRank.
function affiliateLinks(){

// Declare local variables.
	var theURL, theAnchorText, theTitle;

// Declare the variable "spans" as the collection of all <span> elements.
	var spans = document.getElementsByTagName('span');

// Perform the following steps for every <span> element.
	for (var i = 0; i<spans.length; i++){

// If the <span> element is part of the "affiliate" class...
		if (hasClass(spans[i], 'affiliate')){

// Use the content between the <span> tags as our affiliate link's anchor text.
// Example: <span class="affiliate" title="Affiliate Site">this will be our anchor text</span>
// The content doesn't have to be just text; it can be HTML too.
// Example: <span class="affiliate" title="Affiliate Site"><img src="/banners/affiliate-logo.png" /></span>
			theAnchorText = spans[i].innerHTML;

// Get the value of the <span> element's title attribute, make it lowercase, and remove whitespace
// characters from the beginning and end.
			theTitle = spans[i].title.toLowerCase().replace(/^\s+|\s+$/g,"");

// Check the value of the <span> element's title attribute against the following possibilities.
			switch (theTitle) {

// If the <span> element's title is "thesis" then set our affiliate link's href to
// "http://www.seomofo.com/affiliate/thesis/"
				case 'thesis': theURL = 'http://www.seomofo.com/affiliate/thesis/'; break;

// If the <span> element's title is "thesis plans" then set our affiliate link's href to
// "http://www.seomofo.com/affiliate/thesis/plans/"
				case 'thesis plans': theURL = 'http://www.seomofo.com/affiliate/thesis/plans/'; break;

// If the <span> element's title doesn't match any of the possibilities I've provided, then make
// my affiliate link do NOTHING when clicked on, because I f***ed up my code somewhere.
				default: theURL = 'javascript: void(0)';
			}

// Insert the new affiliate link into its corresponding <span> element and copy the <span> element's
// CSS classes (all of them) into the affiliate link's <a> tag.
			spans[i].innerHTML = '<a href="' + theURL + '" class="' + spans[i].className + '">' + theAnchorText + '</a>';

// Remove the title attribute from the <span> element, to prevent Firefox from displaying it in a tooltip.
			spans[i].removeAttribute('title');
		}
	}
}



// Call the affiliateLinks function AFTER the document has finished loading.
window.onload = function(){
	affiliateLinks();
}

Step 2: Define the CSS Styles (Optional)

The following CSS code is an example showing how I have defined my affiliate links’ styles. You don’t necessarily have to use my styles; you can use your own if you prefer.

If you want to use this example, be aware that it assumes you have placed a cursor file, called affiliate-link.cur, in a directory called /cursors/ on your web server. If you save your cursor in a different subdirectory, adjust the URL accordingly in the CSS code.

Also be aware that this example assumes you have a 125px ad banner, called thesis-125x125.gif, in a directory called /banners/ on your web server. You will obviously need to customize the code so it references ad banners you’re actually using on your site.

You can use any cursor you’d like (perhaps one of these middle finger cursors?) or you can download a copy of the one I’m using, by clicking on it below.

To download this cursor, click here ⇒   Affiliate link cursor

a.affiliate {
	color:#339900;
}
a.affiliate:hover {
	cursor:url('/cursors/affiliate-link.cur'), pointer;
}
a.affiliate span {
	display:none;
}
#thesis125 {
	width:125px;
	height:125px;
}
#thesis125 a.affiliate {
	display:block;
	width:125px;
	height:125px;
	background:url('/banners/thesis-125x125.gif') transparent no-repeat;
}

Step 3: Link Your Web Page to the External Files

Assuming your file names are styles.css and scripts.js, you would need to put something like the following code in the <head> section of your web page:

<link rel="stylesheet" type="text/css" href="/styles.css" />
<script type="text/javascript" src="/scripts.js"></script>

Step 4: Block Search Engines from Viewing Your External Files

Google’s ability to crawl JavaScript links keeps getting better and better. However, in this case, the URLs are not actually in our web page’s HTML source code. The only markup Google will see is the empty <span;> tags. In order for Google to find our affiliate links, it would have to fetch our external JavaScript file first. To make sure this doesn’t happen, you would need to Disallow your JavaScript file in your robots.txt file.

If you saved scripts.js in your site’s root directory, your code would look like this:

User-agent: *
Disallow: /scripts.js

If you saved scripts.js in a subdirectory called /nobots/, your code would look like this:

User-agent: *
Disallow: /nobots/scripts.js

Step 5: Insert the HTML Code into Your Web Page

The final step is to mark up your web pages. After the content of your web page is finished loading, the affiliateLinks() function will be called, and the <span> tags that have the affiliate CSS class will be injected with affiliate links. The next section has some mark up examples.

HTML Markup Examples

The following examples should give you a better understanding of how the script works. For each example, I will show you the HTML before (i.e. before the script modifies it), the HTML after, the final result with JavaScript enabled and the final result with JavaScript disabled.




Simple Plain Text Link

HTML Before:

<p>
	SEOmofo.com runs on the <span class="affiliate" title="Thesis">Thesis Theme for WordPress</span>.
</p>

HTML After:

<p>
	SEOmofo.com runs on the <span class="affiliate"><a class="affiliate" href="http://www.seomofo.com/affiliate/thesis/">Thesis Theme for WordPress</a></span>.
</p>

Result with JavaScript Enabled:

SEOmofo.com runs on the Thesis Theme for WordPress.

Result with JavaScript Disabled:

SEOmofo.com runs on the Thesis Theme for WordPress.




Another Plain Text Link

HTML Before:

<p>
	Find out more about my site's WordPress theme, by reviewing the <span class="affiliate" title="Thesis Plans">Thesis <b>plans and pricing</b></span>.
</p>

HTML After:

<p>
	Find out more about my site’s WordPress theme, by reviewing the <span class="affiliate"><a class="affiliate" href="http://www.seomofo.com/affiliate/thesis/plans/">Thesis <b>plans and pricing</b></a></span>.
</p>

Result with JavaScript Enabled:

Find out more about my site’s WordPress theme, by reviewing the Thesis plans and pricing.

Result with JavaScript Disabled:

Find out more about my site’s WordPress theme, by reviewing the Thesis plans and pricing.




Image Link

HTML Before:

<p>
	<span class="affiliate post-ad-right" id="adobe300x250" title="Adobe 300x250"></span>
	Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vel lorem ipsum, in vulputate purus. Nullam faucibus turpis vel ipsum vestibulum eleifend. Maecenas vel velit aliquet purus feugiat pellentesque.
</p>

HTML After:

<p>
	<span class="affiliate post-ad-right" id="adobe300x250"><a class="affiliate post-ad-right" href="http://www.seomofo.com/affiliate/adobe/cs5/production-premium/"></a></span>
	Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vel lorem ipsum, in vulputate purus. Nullam faucibus turpis vel ipsum vestibulum eleifend. Maecenas vel velit aliquet purus feugiat pellentesque.
</p>

Result with JavaScript Enabled:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vel lorem ipsum, in vulputate purus. Nullam faucibus turpis vel ipsum vestibulum eleifend. Maecenas vel velit aliquet purus feugiat pellentesque.

Result with JavaScript Disabled:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vel lorem ipsum, in vulputate purus. Nullam faucibus turpis vel ipsum vestibulum eleifend. Maecenas vel velit aliquet purus feugiat pellentesque.

Conclusion

The SEO techniques I’ve discussed in this article are best suited for affiliate marketers who work with niche sites. This is because the JavaScript example I provided contains a list of name/value pairs that tie the title attributes of the affiliate <span> elements to their corresponding affiliate link URLs. This kind of setup works fine for most people, but it doesn’t scale up very well. Affiliate sites that link to a large number of different advertisers and/or products would find it impractical to constantly update their JavaScript file. In those cases, the script could be modified so that the function takes an obfuscated URL as it’s argument, and then decodes it before injecting it back into the HTML source. (Obfuscating the URL keeps Google from randomly picking it out of your HTML and crawling it.)

I’m planning on doing a follow-up article about advanced SEO for affiliate marketers. It will build upon the basic concepts in this article, by giving some examples that inject 3rd-party scripts, Flash objects, and iframes. Just to give you an idea of what’s possible with these techniques, I’ll leave you with a copy of the page speed test results of the page you just read. If you’re not sure how to read this, then I’ll give you a hint: the green line indicates where the page begins to appear in the user’s browser, the blue line indicates where the page is officially loaded (i.e. where Google stops the “Site Performance” stopwatch), and everything to the right of the blue line is all the stuff I lazy-loaded after the onload event fired. Or in other words…this technique just cut down on my page load time by about 82%!!! Click the image link below.

Page speed savings from advanced SEO technique

{ comment Leave a comment }

UK TOP 40 June 14, 2010 at 8:04 am

We’ve just built an affiliate site that isn’t doing as well as we’d liked on Google – we will be implementing your ideas to see if that improves anything :)

Thanks mate :)

Errioxa June 14, 2010 at 8:41 am

In my tests has been sufficient with to block the js file from robots.txt. Of course, I don’t send complete URL to the function JavaScript, I write URL without “.php” and this works fine :)

Errioxa June 14, 2010 at 9:30 am

A question, if a Googler of search quality team review this code, could get banned from Google?

Thanks for this code!

Corso Demene June 16, 2010 at 1:55 pm

Errioxa, googler team not read this blog

robert June 16, 2010 at 10:06 pm

Do you even know what the hell you’re sexy? You don’t do me and it makes me sad…

You are just another SEO man whore. I work for one of the best gay porn studios…so please…this hole thing is waiting for a poke. It is clear that you are nothing more than just a stud muffin, so stick me with your real SEO thing.

luis June 17, 2010 at 2:18 am

This is black hat seo…

SEO mofo June 17, 2010 at 11:42 pm

*yawn*

andrew June 18, 2010 at 10:56 am

Darren,
Found you on Linked-In, like your blog.
We’re looking for an experienced ‘SEO with affiliate-marketing skills’ for lucrative venture in personal-injury legal / drug-recall space. Great venture; funded and ready. If you know anyone that fits the bill, please email me… and since i see you lost all your clients while writing this post, well, it’s perfect timing.
andrew@esearchdriver.com.
Best,
- Andrew

Canon Scanners June 18, 2010 at 8:12 pm

Is this really black hat SEO?

Terence Milbourn June 20, 2010 at 11:24 am

Don’t get me wrong, I think this is great and I really love all this super cool ‘ninja’ stuff, but I have something I do which is simpler, I think, and still retains all the link juice I get, PLUS it adds tracking to every click. On my WordPress sites, like for instance “http://virtualcrowds.org/”, I install a plugin called “Pretty Link” from Blair Williams, which contains all my affiliate links linked to their respective product names or keywords, and I use it together with another plugin called “SEO Smart Links” by Vladimir Prelovac, which automatically searches all the the text on my site for keywords or product names I define, and then sets up an affiliate link for each when it finds them. But rather than have that affiliate link point off my site, as good old Vlad designed it to do, I have it point to Pretty Link. which is on my site, like this ~ “http://virtualcrowds.org/thesis/”. This is an internal link and retains the link juice while at the same time cloaking the link and referring it on to the link-to site. Not as super cool ‘ninja’ as yours, I admit, but I am not a web developer, so I have to use the tools in my box, sometimes not as they were intended… 8^)

Chris June 20, 2010 at 12:19 pm

Have you ever tried WP Link Engine, its a pretty smart tool to hide your links or show something else based on who is trying to access them. The functionality is key for any affiliate site who does not want to get penalized for Aff links everywhere on a site.

Samuel July 1, 2010 at 9:34 pm

Maybe my question is stupid, but the GoCodes plugin changes the links, doesn’t it?

Italian Penguin August 22, 2010 at 9:34 am

Woody?

Bronson August 30, 2010 at 12:53 pm

I love this workaround for displaying affiliate links.

The detailed experiments you conduct are fantastic and rteally do offer some solid solutions to all too common issues we face as webmasters and seo’s – thanks a mill.

Jason @ SEO Strategies September 1, 2010 at 1:23 am

I agree with the java script idea in improving site speed with banners, though with affiliate text links, I think it’s much better to redirect it to a blank page within your domain (use meta refresh or php redirect), then block crawlers from accessing that page through robots.txt. Well, that’s what I do, and I’m sure that it will not affect the flow of pagerank, plus there’s no need to use rel=nofollow.

Regards,
Jason

Grant Cloete September 28, 2010 at 6:54 pm

Brilliant bit of work. I stumbled on your page while I was searching for info on “PageRank Evaporation”. The heard that term for the first time a few minutes ago and it had me worried for a second. It always pays to google anything and everything one is unsure and not knowledgeable of.

I’ll be checking out that other post of yours in a few minutes. I just hope Google hasn’t caught onto this and tried to make appropriate adjustments to their algorithms.

I have a question though. I’m still not certain what PageRank Evaporation is, but let me try to use my imagination, so please correct me if I’m wrong.

Say that my blog is a tree trunk, then the outbound (affiliate) links are like little branches, and if you pump water at a constant rate containing “PageRank” up the trunk of the tree (the blog), the “PageRank” will flow with the water out into branches (the affiliate links).

Now the more water (thus more PageRank) there is in the branches (i.e. the affiliate links), the less water there is in the trunk (the blog), and thus my blog will have less PageRank.

I heard a little bit about PageRank sculpting, so would that be like I blocked off some of the branches (affiliate links) using nofollow and let more PageRank flow to specific branches (affiliate links) I choose? And what you’re saying is that Google now implemented some changes that reduce the PageRank flowing through the whole trunk (my Blog) if it detects a nofollows on my blog?

Bryan December 3, 2010 at 11:39 am

Very nice. It’s clear how this hides the links from Google, but how does this improve site performance?

Are you using similar, but unmentioned, techniques to inject iframes and other resources?

SEO mofo December 3, 2010 at 12:56 pm

Site performance is improved by removing the delays caused by slow-loading affiliate banners.

Yes, I’m injecting the social media buttons and sidebar #2 via iframes. I’m also using iframe injection on some of the affiliate ad banners. I plan on discussing these techniques in future posts, but first I’d like to nail down the details of how these techniques affect Google’s Instant Previews.

Tihomir Petrov December 22, 2010 at 1:00 am

I like very much the part with the hidden external links. Now it is clear, as Bryan writes, how to do it.

jess March 16, 2011 at 8:46 pm

yeah this is probably a dumb question and i am sorry i am a total newbie but how do i ad my affiliate link to a banner ad or even a text ad so that when someone clicks the banner it goes through my link to the site? i just dont have a clue please be detailed and reply asap via email thanks so much

Frank Adams March 25, 2011 at 11:08 pm

Converting the traffic can be done easily. However, acquiring the traffic that you will be converting is the thing that is tricky for people like me. But I just to back me up I used advancedwebads’ unlimited banner impressions and click service for flat monthly fee.

SCD June 12, 2011 at 12:25 pm

Sorry, this is not a comment. I couldn’t find your contact information anywhere in this site.

Where can I find details about your freelance work? are you accepting any new freelance SEO work? if so, can you please email me those details (rates,specs,rules..etc.). thanks.

James Briggs September 24, 2011 at 9:48 pm

Wow, so Google actually crawls your javascript now? So I guess my simple metarefresh redirects are exposing my links now.

However, I’m not so sure Google would fully honor the robots.txt. They obviously won’t publish those pages in Google’s cache, but are you sure they won’t crawl your links/javascript just to see what’s going on.

SEO mofo September 27, 2011 at 3:56 am

It’s possible that Google could ignore the robots.txt file and crawl the external JavaScript file, but personally, I don’t think they would try that. The main reason is liability: people have tried suing Google for copyright infringement, but Google has won those cases by citing the robots exclusion protocol and suggesting that all webmasters can use it to block googlebot. If Google starts blatantly violating the REP, they would open themselves up to lawsuits.

Plus, you could always use server-side techniques that simply refuse to serve blocked URLs to Google’s crawlers.

Chris September 25, 2011 at 3:09 pm

this is great – but protip: writing shit like “My extra-super-advanced SEO…” is neither funny nor clever. It just makes you sound like a clown.

SEO mofo September 27, 2011 at 4:07 am

1. It wasn’t intended to be funny; it was part of a test involving synonyms and variations of the term “advanced SEO solution.”

2. I am a clown.

Ben November 3, 2011 at 12:37 pm

Hello Clown ;-)

I like your script and i’m implementing it.

Just a small improvement, instead of setting all aff links this way :
————————
case ‘thesis’: theURL = ‘http://www.seomofo.com/affiliate/thesis/’; break;
————————
You could even more easily (so you don’t have to change the javascript everytime) do like this :
————————-
// set a variable defining the affiliate link folder
theAffLinksFolder = ‘http://www.seomofo.com/affiliate/’;
// and then simply happen the Title of the span attribute
theURL = theAffLinksFolder + theTitle;
———————
This way you get rid of the editing + you can also delete the javascript case switch.

Cheers,

Aravind January 6, 2012 at 8:05 am

Is this working after the recent panda update?

One of my sites lost its rankings today which uses external javascript to display products on page. Though I had blocked javascript on robots.txt page I suspect it to be cause for the damage.

John B. January 21, 2012 at 4:37 am

Thanks for article :) I also hide my affiliate links, but i use a free service: http://wordstolinks.com/

Leave a Comment