KitzKikz  KitzKikz: GoogleAnalyticsNoScript   RecentChanges 
 Home | Trail - GoogleAnalyticsNo...

Google Analytics without Javascript (using the <noscript> tag)

Google Analytics gathers a good deal of useful information and presents it in some nice ways, but only if ALL your users have javascript turned on in their browsers. People who browse your site with javascript turned off are essentially invisible when it comes to the Google Analytics code.

However, the Google code just builds a special url to a 1x1 image and then loads that image each time the page is browsed. It is this loading of the image and all the additional information in the url that gives Google Analytics the statistics it needs.

Therefore, by determining the actual url used, you can include it as an image tag inside the <noscript>...</noscript> tags. Then, if users have javascript turned on, the normal Google code is used. If they have javascript turned off, the <noscript> area is used, loading the image directly.

Determining this special url is not easy. Fortunately, someone has already done that for us:

Unfortunately, it's based upon some older version of Google Analytics. With some minor modifications, however, I came up with the following in my php served pages.

    <noscript><img src="<? echo google_analytics_noscript(); ?>" /></noscript>

With the function definition of:

     function google_analytics_noscript() {
        $var_utmac='UA-???????-1'// your unique Google Analytics id
        $var_utmhn=$_SERVER!["HTTP_HOST"]; // domain
        $var_utmn=rand(1000000000,9999999999); //random request number
        $var_cookie=rand(10000000,99999999); //random cookie number
        $var_random=rand(1000000000,2147483647); //number under 2147483647
        $var_today=time(); //today
        $var_referer=$_SERVER!['HTTP_REFERER']; //referer url
        $var_uservar='-'//enter your own user defined variable

        return $img;

Now I can find out how many visitors have javascript turned off by looking at the statistics for items in the "noscript" fake directory. If it's 10-20%, then I'll know to spend some effort writing portions of my site for those types of visitors. If it's less than 1-2%, then I'll know it's probably not worth the additional effort.

It's those types of decisions that using an analytics engine is all about. -- KitzKikz 08-Feb-2009



 EditThisPage · LinksToPage · PageInfo 10/19/09 20:59:28  ·  0.0264s