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

  ["Google Analytics" http://www.google.com/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: http://www.vdgraaf.info/google-analytics-without-javascript.html

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.

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

With the function definition of:

<pre>
function google_analytics_noscript() {
$var_utmac='UA-???????-1'; // your unique Google Analytics id
$var_utmhn=$_SERVER!["HTTP_HOST"]; //enter your 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
$var_utmp='noscript'.$_SERVER!["REQUEST_URI"];

$img='!http://www.google-analytics.com/__utm.gif?utmwv=4.3'
.'&utmn='.$var_utmn
.'&utmhn='.$var_utmhn
.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-'
.'&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';

return $img;
}
</pre>

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.
It's those types of decisions that using an analytics engine is all about. -- ''KitzKikz 08-Feb-2009''
 

 
  ·  0.0414s