Tracking Digital Content
One of our clients an electronic entertainment company provides movie trailers on their site. They also want to provide their partners with a simple EMBED tag for a flash player similar to what youtube does with it videos. Naturally they want to be able to track how often the movie clip or trailer is viewed on their partners sites by using google analytics, or as yet to be determined tracking methods.
The most typical method is to create a server side page that will return the binary object, but before it sets the header and returns the object you first need to call the google analytics. The problem is that you can't use the urchin tracker Javascript code, you have to use a URL. You can figure out how the URL looks by using Firebug. I also found a pretty good example from LinkLove for php which describes some of the different parameters.
Naturally it's dead easy to do in coldfusion requiring only cfhttp and cfcontent tags to make the google analytics call and serve the digital content. I took the example php code and converted it to CFML and set it to return a customized flash player.
<cfset var_utmac='UA-0000000-0'> <!--- enter the new urchin code --->
<cfset var_utmhn='www.mysite.com'> <!--- enter your domain --->
<cfset var_utmn=RandRange(10000000,99999999)> <!--- random request number --->
<cfset var_cookie=RandRange(10000000,99999999)> <!--- random cookie number --->
<cfset var_random=RandRange(1000000000,2147483647)> <!--- number under 2147483647 --->
<cfset var_today=now()> <!--- today --->
<cfset var_referer=#cgi.HTTP_REFERER#> <!--- referer url if it exists --->
<cfset var_uservar='-'> <!--- enter your own user defined variable --->
<cfset var_utmp= ''> <!--- this example adds a fake file request to the (fake) tracker directory (the image/pdf filename). --->
<cfset urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1.3&utmn=#var_utmn#&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=#var_utmhn#&utmr=#var_referer#&utmp=#var_utmp#&utmac=#var_utmac#&utmcc=__utma%3D#var_cookie#.#var_random#.#var_today#.#var_today#.#var_today#.2%3B%2B__utmb%3D#var_cookie#%3B%2B__utmc%3D#var_cookie#%3B%2B__utmz%3D#var_cookie#.#var_today#.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D#var_cookie#.#var_uservar#%3B'>
<cfhttp method="get" url="#urchinURL#" throwonerror="false"/>
<cfset fileToReturn=expandPath('/flashplayer/player.swf)>
<cfcontent type="application/x-shockwave-flash" file="#fileToReturn#" reset="false">
Worked like a charm, and as the other php examples show you can set it to work for other content as well.
Happy Coding...

Subscribe
Subscribe via RSS
Follow me on Twitter
Or, Receive daily updates via email.
Tags
adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui
Recent Entries
Converting structkeys to lowercase
Blogroll
An Architect's View
CFSilence
Rey Bango
TalkingTree

<cfset var_today = now().getTime()> ?