Posted By

IanLewis on 05/13/08


google mobile Analytics

Versions (?)

Who likes this?

10 people have marked this snippet as a favorite


Google Analytics without Javascript

 / Published in: PHP

  1. $var_utmac=GOOGLE_ANALYTICS_CODE; //enter the new urchin code
  2. $var_utmhn=WEB_DOMAIN; //enter your domain
  3. $var_utmn=rand(1000000000,9999999999);//random request number
  4. $var_cookie=rand(10000000,99999999);//random cookie number
  5. $var_random=rand(1000000000,2147483647); //number under 2147483647
  6. $var_today=time(); //today
  7. $var_referer=$_SERVER['HTTP_REFERER']; //referer url
  9. $var_uservar=$storeinfo["storeid"]; //enter your own user defined variable
  10. $var_utmp="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  12. $urchinUrl=''.$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';
  14. $handle = fopen ($urchinUrl, "r");
  15. $test = fgets($handle);
  16. fclose($handle);

Report this snippet  


RSS Icon Subscribe to comments
Posted By: section31 on July 6, 2008

This is dumb, why would you want to do this?

Posted By: jdstraughan on July 6, 2008

You are not getting a job at Google any time soon...

Posted By: IanLewis on August 8, 2008

The reason you would do this is so that you could track hits to mobile devices that don't support javascript. The original author used it do to server side tracking of hits to rss feeds. There are probably a number of things you could use it for.

Posted By: dellme on October 29, 2008


I have a problem with your script. fopen send my Ip Address (server), so when I look my results, all my visitors comes from my city. Do I have to change my php.ini or Apache configuration ?

Thanx a lot for you work


Posted By: IanLewis on December 28, 2008


There is unfortunately no way to get around that problem at present by doing the request from the server. The ip address or location are not parameters to the tracking url but are rather recorded by the analytics server via the client ip address.^

You would have to negotiate the client to do the get request for you by putting the url in an image tag or doing it with javascript like the standard analytics javascript.

Posted By: tencentt on September 16, 2009

@IanLewis @delime

What about doing an HTTP redirect and making a or any type of request in the server?

Like this:

The idea is doing:

Would solve the problem I think, anyway you would require another request, and the referrer is sort-of lost.

Posted By: managerchannel on August 8, 2010

If you just want to capture a single page or action, like track opened emails, try There you just set the email identifiers and get a pixel code. This pixel code does all the posting for you.

You need to login to post a comment.