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=''> <!--- 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=''>
<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...

1 Comments to "Tracking Digital Content"- Add Yours
Max's Gravatar Wouldn't you have to convert your var_today = now() into epoch time? Maybe do this:

<cfset var_today = now().getTime()> ?
# Posted By Max | 7/21/09 4:53 PM

Powered By Railo


Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.


adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript jquery max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.


An Architect's View
Rey Bango

Wish List

My Wish List