Auto-generating iTMS links with affiliate info
Music, Technology, Website 09/29/2004 |I thought I was going to need help figuring this out — turns out I’ve got more iTMS link-fu than I thought.
Earlier this month, I was accepted into the iTunes Affiliate program. All well and good, except that at that point, I couldn’t find a way to link directly to individual items with my Affiliate ID — I could put up the generic iTunes badge (which now resides towards the bottom of my sidebar), or I could put up Apple-designed ad blocks (which, aside from the Björk ad on my original post, I’ve yet to do, mostly because they apparently need to be rotated out manually), but I couldn’t link to any particular track.
As of today, however, Apple now provides a tool to let me do just that, in the form of an addition to the iTMS Link Maker. This is most definitely a Good Thing — however, it’s still a lot more cumbersome than I’d like things to be. While it will be serviceable when I want to mention a particular track or album during the course of a post (for instance, right now I’m listening to William S. Burroughs’ spoken word album Dead City Radio, a must for any WSB fan), what I really wanted to be able to do is use ecto’s ‘now playing’ feature (which I use to insert the currently playing iTunes track information into the bottom of posts I make at home) to autogenerate iTMS search links that include my Affiliate information at the beginning.
Back when the iTMS first debuted, some enterprising people figured out the URL structure that would allow you to create links to iTMS searches — in theory, all I should have to do is slightly adjust that URL structure to match the URL structure of Affiliate links, and I’d be good to go. As it turns out, that theory was right — for instance, here’s an iTMS search for U2 that passes through my Affiliate information.
Full gory details are in the extended entry… (NOTE: There are a lot of really long URLs in the following post. For the sake of readability, I’ve broken them down with spaces in this text — should you do any copy-and-pasting of any of the code I’ve posted here, please keep in mind that all the URLs should be one single line.)
Here’s what I had to do to get this working:
When I got the announcement in the e-mail from Apple, they included a link to the iTMS Link Maker. However, when I clicked through to give it a shot, the returned URL was a generic URL that didn’t include the data that LinkSynergy needs to connect the click-through with my Affiliate account:
http://click.linksynergy.com/fs-bin/stat?id=[SITE.CODE]&offerid=
[OFFER.OID]&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252F
phobos.apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewArtist
%253FartistId%253D78500%2526originStoreFront%253D143441%26 partnerId%3D30
See those [SITE.CODE] and [OFFER.OID] arguments? Without actual data in those, the link doesn’t work. Not an auspicious start to my project.
Wondering if there might be a way to get to the iTMS Link Maker through my LinkSynergy account and then generate links that included my site code and offer oid (would that be any relation to the Noid?), I headed over to my LinkShare account page. Sure enough, today’s announcement was mirrored there, and when I clicked through to the iTMS Link Maker and performed the same search, I was returned a full-formed, working URL:
http://click.linksynergy.com/fs-bin/stat?id=xLsJkztrnNY&offerid=
78941&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fphobos.
apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewArtist
%253FartistId%253D78500%2526originStoreFront%253D143441%26 partnerId%3D30
Much better! Just to be sure, I performed a few searches to be sure that neither of the variables changed — neither did, so I’m pretty certain that those are constants.
Immediately, I went back to the iTMS Link Maker through the link from within my LinkShare page and bookmarked that page, then performed a few searches using the bookmark to ensure that they’d give me consistent, well-formed URLs to play with. They did — so on to the next step.
Looking at the URL, it seemed fairly obvious that it had two parts: the URL that actually gets passed to the iTunes Music Store, and the LinkShare information that ties the click-through to my Affiliate account. In order to break it apart, I opened the iTunes Link Maker in two tabs — once ‘anonymously’, and once tied to my Affiliate account — and performed the same search twice so that I could compare the information returned by the searches.
Anonymous link:
http://phobos.apple.com/WebObjects/MZStore.woa/ wa/viewArtist?artistId=78500&originStoreFront=143441Affiliate link:
http://click.linksynergy.com/fs-bin/stat? id=xLsJkztrnNY&offerid=78941&type=3&subid=0&tmpid=1826& RD_PARM1=http%253A%252F%252Fphobos.apple.com%252FWebObjects %252FMZStore.woa%252Fwa%252FviewArtist%253FartistId%253D 78500%2526originStoreFront%253D143441%26partnerId%3D30
While the Affiliate link looks a lot nastier, it turns out that it’s exactly what I thought it would be, only all non-alphanumeric characters (except periods, for some reason) in the iTMS link have been encoded into their ASCII entities. The following is the Affiliate link with the LinkShare information in red, and the iTMS information in green:
http://click.linksynergy.com/fs-bin/stat?
id=xLsJkztrnNY&offerid=78941&type=3&subid=0&tmpid=1826&RD_PARM1=
http%253A%252F%252Fphobos.apple.com%252FWebObjects%252FMZStore.woa
%252Fwa%252FviewArtist%253FartistId%253D78500%2526originStoreFront
%253D143441%26partnerId%3D30
I’m pretty sure that that last red bit at the end actually does get passed to the iTMS, but as it’s not there with a ‘normal’ (anonymous) link, I’m including it as LinkShare-specific information.
So, now I knew that in order to create my search links, I’d need to surround an iTMS search URL with the LinkShare specific code, and encode the non-alphanumeric characters within the iTMS search URL. According to the information I had on constructing iTMS search URLs, the iTMS search string for ‘U2’ would be…
itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/com.apple.jingle.search.
DirectAction/advancedSearchResults?artistTerm=U2
…so with a little careful comparison to be sure I was substituting the right ASCII entities for the right characters, I ended up with an encoded search URL of…
http%253A%252F%252Fphobos.apple.com%252FWebObjects%252FMZSearch.woa%252Fwa
%252Fcom.apple.jingle.search.DirectAction%252FadvancedSearchResults%253F
artistTerm%253DU2
…(note that the iTMS Search URL now begins with
http, and not
itms). Surrounding that with the LinkShare code gave me a final URL of…
…and what do you know, but the fool thing worked!
Now I had the correct syntax and URL structure to be able to create Affiliate-linked searches within the iTMS for any artist that I wanted. The final step is to craft the correct ecto iTunes template for automatic generation of search strings at the end of each post. Rather than run through every step of that process, I’ll just post the final string that works for me (I have it as a single long string, I’m breaking it down here for [marginally] better readability):
<a href="http://click.linksynergy.com/fs-bin/click?id=xLsJkztrnNY&
offerid=78941.10000170&type=4&subid=0" title="Get iTunes"><img alt="iTunes" border="0" width="61" height="15" src="http://images.apple.
com/itunesaffiliates/logos/iTunes_sm_bdg61x15.png" /></a><img border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=
xLsJkztrnNY&bids=78941.10000170&type=4&subid=0" alt="" />
"<a href="http://click.linksynergy.com/fs-bin/stat?id=xLsJkztrnNY&
offerid=78941&type=3&subid=0&tmpid=1826&RD_PARM1=itms
%253A%252F%252Fphobos.apple.com%252FWebObjects%252FMZSearch.woa%252Fwa
%252Fcom.apple.jingle.search.DirectAction%252FadvancedSearchResults%253F
artistTerm%253D^p%2526songTerm=^t%26partnerId%3D30" title="Search for '^t'
on the iTMS">^t</a>"#p by <a href="http://click.linksynergy.com/fs-bin/
stat?id=xLsJkztrnNY&offerid=78941&type=3&subid=0&tmpid=
1826&RD_PARM1=itms%253A%252F%252Fphobos.apple.com%252FWebObjects%252F
MZSearch.woa%252Fwa%252Fcom.apple.jingle.search.DirectAction%252Fadvanced
SearchResults%253FartistTerm%253D^p%26partnerId%3D30" title="Search for
'^p' on the iTMS">^p</a>#p#a from the album <em><a href="http://click.
linksynergy.com/fs-bin/stat?id=xLsJkztrnNY&offerid=78941&type=
3&subid=0&tmpid=1826&RD_PARM1=itms%253A%252F%252Fphobos.apple.
com%252FWebObjects%252FMZSearch.woa%252Fwa%252Fcom.apple.jingle.search.
DirectAction%252FadvancedSearchResults%253FartistTerm%253D^p%2526
albumTerm=^a%26partnerId%3D30" title="Search for '^a' on the iTMS">^a</a>
</em>#a (#y^y, #y^l).
Update: The above code has been slightly tweaked (mostly just adding title attributes to the links) during a debugging session to ensure that it was still working as it should. As far as I can tell, it’s still working fine.
Update:: Another minor tweak to adjust for Apple’s change of location and filename for the small iTunes badge image.
While you can see the results of this (admittedly huge) code block at the end of this post, it does the following:
- Wraps the iTunes information in a CSS class that I’ve specified for positioning, font, etc.
- Creates an iTunes badge that links to the iTMS
- Links the title of the currently playing track to an iTMS search for the title, artist, and album
- Links the artist to an iTMS search for the artist
- Links the album to an iTMS search for the artist and album
- All of the links are tied to my iTunes Affiliate ID
And so, in the end, I’ve got exactly what I wanted when I first heard about the iTMS Affiliate program: dynamic iTMS searches for anything I’m listening to when I make a post. The one downside, of course, is that I listen to enough obscure music that there will be times when none of those searches return any useable results…but that’s just one of the many potential side effects of being a music whore, so I think I can live with that.
Hopefully if you’ve been able to make it through all this, my somewhat stream-of-conscious ramblings will have been of some assistance (especially if you’re an iTunes Affiliate who’d like to do the same thing, or something similar). Let me know if I can clear anything up (I’ll probably want to come back and create a condensed, ‘here’s the basics’ rundown of how to do this…but at the moment, constructing this post has taken twice as long as the actual detective work did, I still need to proofread it before posting, and that’ll be about all I’m up for at the moment).
![]()
“Heartland” by U2 from the album Rattle and Hum (1988, 5:03).
[See also: Tuesday Ten (In My Pants) | Garth Brooks is a Gateway Drug | (Another) iTunes Meme | Don’t Feel Like Dancin’ | Not Gallimaufry ]
20 Responses to “Auto-generating iTMS links with affiliate info”
Leave a Reply






September 29th, 2004 at 8:45 pm
This is great: I may try it out, even though I have already tracked down all the ASIN numbers to use with the Amazon affiliate program. Nice work …
September 29th, 2004 at 9:12 pm
Well, this kicks … trouble is, iTMS doesn’t have as big a catalog as Amazon. I may end up posting links to both AMZN and iTMS.
Thanks for taking the time to work this out: I wonder how it was supposed to work without an affiliate ID and the idea of rotating in ads by hand: how 1995.
October 11th, 2004 at 4:45 pm
The sincerest form of flattery
Now Playing: »Vertigo« by U2 From the 2004 album Vertigo CDS “Vertigo” by U2 from the album Vertigo CDS(2004, 3:11).
October 26th, 2004 at 10:17 am
Let there be music!
Thanks to Michael Hanscom for posting a solution to a problem I had with the music entry at the bottom. Works like a charm!…
February 4th, 2005 at 8:31 am
Ok, you freaking rock. Thanks for the info, I thought all was lost when I first saw the links linkshare generated.
July 1st, 2005 at 8:42 am
Seems Apple’s changed something. You title link still works, but artist and album are broken. But it is a start.
Cool comment preview feature. Where did you get it? I use WordPress too and would like to use it.
July 1st, 2005 at 12:23 pm
Hmm…thanks for the heads-up. Looks like I’ll have a project as soon as I can spare some time.
Thanks! It should work fine on WordPress — all the instructions for how I got it working are in this post. Have fun!
July 5th, 2005 at 9:55 pm
I’ve been working on something similar over here, and noticed stuff is broken.
This site seems to still have it working: http://www.tunestracker.com/latest/artist/u2/ (lame site otherwise though)
July 11th, 2005 at 6:04 pm
The reason it’s broken is cause you don’t fill out all the variables. You need to have “albumTerm=”, “songTerm”, and “artistTerm=” for every link even if they are blank.
So to get it to work your link needs to look more like this:
U2
Awesome work man I got it up and running on my site much quicker thanks to you.
November 30th, 2005 at 5:05 pm
Absolutely a life saver. Got it working in Ecto in 15 minutes, a gold star to you!
December 14th, 2005 at 1:10 am
FWIW, here are my notes the frustrations involved with dealing with the iTMS affiliate program:
http://www.oreillynet.com/pub/wlg/8724
December 14th, 2005 at 3:34 pm
Glad this is coming in handy for all of you. I’ve double-checked my code to check some of the issues that were brought up over the past few months, and I do believe everything is working as it should.
Scot — no diagreement at all with the issues you bring up in your post. iTMS affiliation sounds great (and if I got more traffic, might even bring in more than a few pennies), but I really do wish they’d put some work into making it less of a headache to deal with.
December 21st, 2005 at 3:32 pm
great article dude - let’s hope Apple come up with something better soon though. Anyone managed to get this working across multiple locales for different stores (I want to change the store at runtime depending on visitor’s IP)?
February 24th, 2006 at 3:24 pm
Michael,
Thanks for your code. It works great.
I am also interested in similar links for other music stores, like MusicMatch.
June 1st, 2006 at 6:03 pm
Great article and really appreciated the in-depth process you’ve related that shows the ins and outs of developing it.
I’m looking at how to solve the exact issue you’ve described but my ability to turn the article into reality failed.
While this must have once worked (and quite recently) I don’t show that any of the links in the article remain functional today, June 1st, 2006. I simply get a 302 error page though itunes does launch with the correct album. I just don’t think this is the way it was intended to work.
Your input appreciated!
Sincerely, KAM
June 1st, 2006 at 6:12 pm
Kevin —
I’m afraid I’m not sure where the 302 is coming from. I’ve just checked all the links in the article and they worked fine for me with no errors.
For reference, I’m running Safari 2.0.3 under Mac OS X 10.4.6, perhaps different brower/OS combinations are choking on the redirection that Apple uses to translate the
httplink into a link into iTunes?November 1st, 2006 at 8:05 pm
I’m having a major issue with iTunes links right now. I tried the method above and had mixed success in various browsers (tried IE, FireFox, Opera). So, I went thru a major effort to try to link a number of albums and aritists directly to the proper iTunes location.
I’m getting a lot of 500 errors. Even when the links appear to work and iTunes launches successfully, I’m getting a lot of “iTunes is unavailable” messages within iTunes itself. However, if I look for the exact same sone within iTunes, it finds it, of course.
I’ve also noticed the same issue with a number of other sites who also use iTunes affiliate links - even this one.
Did LinkShare / Apple change something recently? Or, are links from affiliates just low on the iTunes server priority list and so they just return a server error?
April 30th, 2007 at 3:28 am
Hi,
In the above code we are passing the target html page as “RD_PARM1=”, now the question is this, suppose I have to create a new link in linkshare, then how can I get a link containing “RD_PARM1=”, so that I can pass my own url.
Thanks.
August 6th, 2008 at 2:11 pm
Does this still work for the most recent versions of ITMS an iTunes?
August 6th, 2008 at 6:41 pm
I’m afraid I have no idea, CHris, I haven’t played with this in a few years. Good luck, though!