Last night, as I was fooling around with Facebook’s new timeline feature, I noticed something rather odd. Facebook appeared to be altering some of the Amazon affiliate links that people were posting; removing any reference to their affiliate ID, and taking credit for the referral itself.

After experimenting a bit and confirming my preliminary findings, I posted the following incendiary nugget on Twitter:

When you post an Amazon affiliate link on Facebook, THEY REPLACE YOUR AFFILIATE ID WITH THEIR OWN in the preview/thumbnail links. Wow.

— Grettir Asmundarson (@grettir) on December 19, 2011

…and promptly went to bed. My plan was to do more research in the morning and figure out what was really going on.

(“Facts can wait until morning!” That’s my motto, and I’m sticking with it.)

Anyway, as I was driving my daughter to school this morning, my phone started going crazy with notifications of re-tweets and replies. And while I answered people’s questions as best I could based on the previous night’s experiments, I hadn’t yet had a chance to delve back into it, so I didn’t have all the answers.

Well, I still don’t have all the answers, but I have enough of them now to provide people with a more detailed explanation of exactly what’s going on.

If you want to cut to the chase you won’t hurt my feelings. But for lovers of minutiae, we’ll start with the basics.

Facebook Link Previews

As you’re typing your status updates on Facebook, if you happen to type (or cut and paste) a URL, Facebook will take that URL and auto-generate a “link preview” that features a nice, clickable icon as well as a title and description of the link’s destination. It then appends that pretty link preview to the bottom of your status update.

Here’s a basic example:

Facebook Link Preview

I quite like them. They add some visual interest to your wall/timeline and make your status updates stand out from the text-heavy crowd. I’ve also found that people are much more likely to click on the links in the pretty link preview than they are to click on the ugly, raw, auto-linked URL in the body of the status update itself.

And you’d think that the links in the auto-generated link preview would point to the same URL that you just typed in your status update, right? Well, in a lot of cases, they do. For instance, if you look at the previous screenshot, you’ll see that when you mouseover either of the links in the link preview area, the URL (which shows up in the browser’s status bar) matches the one you typed in your status update.

But this isn’t always the case, and it certainly isn’t the case for Amazon affiliate links.

Amazon Affiliate Links

Amazon affiliate links contain a unique affiliate ID that ensures you get credit for any traffic you send their way. In my case, a typical bare-bones affiliate link might look something like this:

http://www.amazon.com/exec/obidos/ASIN/B001ADOWO6/ref=nosim/tinypineapple

That bit at the end is the important part. Without it, Amazon has no way of knowing that I was the one who referred the customer to them and, as a result, I wouldn’t receive my annual check for less than $10.

(It’s true. So far this year, I’ve earned less than $10 from Amazon affiliate links, so I don’t really have a dog in this fight. I’m just doing this out of curiosity.)

When you post that Amazon affiliate link on Facebook, the auto-linked URL in the body of the status update points to the URL you’d expect it to (again, note the browser’s status bar):

Facebook Link Preview: Amazon Link A

…but when you mouseover either of the two links in the link preview, you discover that they send you somewhere else entirely:

Facebook Link Preview: Amazon Link B

Instead of pointing to the intended Amazon affiliate link…:

http://www.amazon.com/exec/obidos/ASIN/B001ADOWO6/ref=nosim/tinypineapple

…Facebook is sending people here:

http://www.amazon.com/dp/B001ADOWO6/ref=tsm_1_fb_lk

In this new mystery URL, my affiliate ID (tinypineapple) is nowhere to be found, having been replaced by some “ref=tsm_1_fb_lk” nonsense that appears to credit Facebook with the referral. (ref=something_something_facebook_like/link?)

I initially thought the problem might be that I was using old-school affiliate links, but all the modern variants produced the same result.

I also tried using bit.ly to shorten the URLs, thinking that Facebook might then leave them alone. Unfortunately, when creating the link preview, Facebook automatically expands shortened URLS and follows all the redirects, leaving you exactly where you were before.

Speculation

Some people were speculating that Facebook hates affiliate programs and is trying to foil them by stripping the affiliate IDs from the links. But if that’s was the case, why would they only alter the two links in the link preview and leave the URL in the body of the status update untouched?

Others speculated that Facebook was merely sanitizing the URLs and stripping off any query strings in the process. But:

  1. Amazon affiliate link URLs don’t contain a query string, per se. There’s no separator followed by one or more field-value pairs. (e.g. ?wubba=null) There’s nothing to strip.

  2. Surely the indiscriminate stripping of query strings from URLs would break too many sites. They’d never get away with it.

One thing that seemed to bolster the anti-affiliate argument was the discovery that iTunes affiliate links are also being stripped of their affiliate IDs…but that’s because the entire query string is disappearing.

iTunes affiliate links that start out like this…:

http://itunes.apple.com/us/album/wish-list-single/id401188569?uo=4&partnerId=30&partnerId=30&siteID=_oX3u15HhzE-lHjNxoUPkor7doSOJEls2A

…end up like this:

http://itunes.apple.com/us/album/wish-list-single/id401188569

To see if query strings might really be the issue, I posted some links to LandsEnd.com, which relies pretty heavily on query strings, and this was the result:

Facebook Link Preview: Lands End

It’s a little hard to see in the cropped screenshot, but here’s the original URL:

http://canvas.landsend.com/pp/TurtleneckSweater~214496_-1.html?bcc=y&action=order_more&sku_0=%3A%3AAN9&CM_MERCH=IDX_Women-_-Sweaters&origin=index

And here’s what you end up with in the link preview:

http://canvas.landsend.com/pp/TurtleneckSweater~214496_-1.html?cm_mmc=SocialMedia-_-Canvas-_-ProductShare-_-facebook

Where in the world did that come from? Well, I’ll tell you where it came from…

What’s Really Going On

When Facebook detects a URL in your status update, the first thing it does is perform a basic “auto-link” on the URL in the body of your status update. But to build the link preview, it tries to get fancy. It sends its crawler to the destination site and grabs the web page you’re linking to.

  1. If the web page in question has an Open Graph Protocol property="og:url" meta tag, Facebook will completely ignore the URL you entered in favor of the URL specified in the meta tag.

    So, since our LandsEnd.com destination page contains the following meta tag:

    <meta property="og:url" content="http://canvas.landsend.com/pp/TurtleneckSweater~214496_-1.html?cm_mmc=SocialMedia-_-Canvas-_-ProductShare-_-facebook"/>

    …that’s the URL Facebook will use in the link preview, no matter what we originally typed.

  2. If the Facebook crawler can’t find the proper Open Graph meta tag, it looks for a rel="canonical" link tag instead. And, if it finds one, Facebook will completely ignore the URL you entered in favor of the URL specified in the link tag.

    So, since our iTunes affiliate destination page contains the following link tag:

    <link rel="canonical" href="http://itunes.apple.com/us/album/wish-list-single/id401188569" />

    …that’s the URL Facebook will use in the link preview, no matter what we originally typed.

  3. If neither of the above conditions are met, only then will Facebook concede that you might actually know what you’re doing and build the link preview using the URL you told it to use in the first place.

The Missing Link

The “canonical URL” angle had occurred to me earlier, but it didn’t seem to explain that Amazon mystery URL. If you look at our destination page on Amazon, it doesn’t contain any Open Graph meta tags, and even though it does have a rel="canonical" link tag…:

<link rel="canonical" href="http://www.amazon.com/Strange-Beautiful/dp/B001ADOWO6" />

…that doesn’t match the mystery URL we’ve been looking for.

The trick is that Amazon is sniffing user-agent strings and is only inserting Open Graph meta tags when the page request comes from Facebook’s crawler.

But if you spoof your user-agent string and set it to “facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)” you’ll get the full complement of Open Graph Protocol tags which are normally hidden from users, including…:

<link rel="canonical" href="http://www.amazon.com/dp/B001ADOWO6/ref=tsm_1_fb_lk" />

Bingo.

Conclusion

Let me make this perfectly clear: I was wrong.

What my original tweet should have said was:

When you post an Amazon affiliate link on Facebook, FACEBOOK DOES NOT REPLACE YOUR AFFILIATE ID WITH THEIR OWN in the preview/thumbnail links.

What they do instead is throw your affiliate link out the window entirely in favor of the one that Amazon is insisting is the canonical link, and that canonical link doesn’t include your affiliate ID (so HARD CHEESE!), but it does contain a snippet of code that gives Facebook (rather than you) credit for the referral.

As to whether Facebook earns any affiliate dough from that referral, I don’t know…but is there any link on Facebook that they don’t monetize?

Of course, the real irony here is that this problem is caused by the fact that Facebook is trying to do the right thing. It’s allowing sites to specify their own canonical links, which (in theory) is supposed to be the ideal. But when that ideal results in two-thirds of your links pointing to the wrong destination, that’s a problem.

So, if you’re posting Amazon affiliate links on Facebook, please keep in mind that the two links that are arguably the most attractive links in your status update (the icon and the title in the link preview) aren’t really your Amazon affiliate links…which means you’re probably not getting credit for most of the traffic you’re sending their way.