Search code examples
coldfusiongoogle-analyticscoldfusion-9cfhttp

google analytics, hitting it from coldfusion server cfhttp


I have used this: Generate Google Analytics events (__utm.gif requests) serverside

and this: http://www.garyrgilbert.com/blog/index.cfm/2008/10/21/Tracking-Digital-Content

to build a cfhttp string so that when a user hits a page it calls google analytics. I'm doing it like this because the pages I'm serving are XML pages and I can't mix javascript with xml.

My problem is that google analytics is ignoring my requests. I have activated my bucket code on a normal html server, so it thinks/knows it exists, but now when i call any of my xml server pages and make the cfhttp request from coldfusion server, it doesn't get registered.

Update:

Following Sergii advice, I have done a dump to find out what the cfhttp is doing (i was previously missing a variable which was causing it to error), i am now getting a http return of 200, though analytics is not applying the request to my account.

Update the 2nd, including code:

    <cfset var_utmac='UA-myUA'> <!--- enter the new urchin code --->
    <cfset var_utmhn='www.myaddress.co.uk'>
    <cfset var_utmn = RandRange(10000000,99999999)>
    <cfset var_cookie = RandRange(10000000,99999999)>
    <cfset var_random = RandRange(1000000000,2147483647)>
    <cfset var_today = now()>
    <cfset var_referer = #cgi.HTTP_REFERER#>
    <cfset var_uservar = 'jevans'>
    <cfset var_utmp= ''>
    <cfset apiname = 'listings.getlistings'>

    <cfhttp method="get" url="http://www.google-analytics.com/__utm.gif">
        <cfhttpparam type="url" name="utmwv" value="1" />
        <cfhttpparam type="url" name="utmn" value="#var_utmn#" />
        <cfhttpparam type="url" name="utmsr" value="-" />
        <cfhttpparam type="url" name="utmsc" value="-" />
        <cfhttpparam type="url" name="utmul" value="-" />
        <cfhttpparam type="url" name="utmje" value="0" />
        <cfhttpparam type="url" name="utmfl" value="-" />
        <cfhttpparam type="url" name="utmdt" value="#apiName#" />
        <cfhttpparam type="url" name="utmhn" value="#var_utmhn#" />
        <cfhttpparam type="url" name="utmr" value="#var_referer#" />
        <cfhttpparam type="url" name="utmp" value="#var_utmp#" />
        <cfhttpparam type="url" name="utmac" value="#var_utmac#" />
        <cfhttpparam type="url" name="utmcc" value="__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>

any thoughts?

cheers


Solution

  • Looking at your code, I'm guessing that you need to replace &amp's in your code with regular & symbols. You only need to escape the ampersands to validate XML documents and such. If you send them over the URL, then they may not be recognized as separators.

    I would actually construct it like so:

    <cfhttp method="get" url="http://www.google-analytics.com/__utm.gif">
        <cfhttpparam type="url" name="utmwv" value="5.1.2" />
        <cfhttpparam type="url" name="utmn" value="#var_utmn#" />
        ... all your other URL variables
    <cfhttp>
    

    This will make your code a little easier to read, as well as make sure that all of your variables are sent over in the property format, without needing to concatenate a huge string.