Posted By

daisuke103 on 11/07/08


Tagged

php textmate info html google access Analytics


Versions (?)

PHP GoogleAnalyticsを携帯で利用する


 / Published in: Other
 

  1. <?php
  2. function mobile_analytics($uid = '', $domain = '')
  3. {
  4. echo '<!-- Google Analytics for mobile START -->';
  5.  
  6. $var_utmac=$uid; //enter the new urchin code
  7. $var_utmhn=$domain; //enter your domain
  8. $var_utmn=rand(1000000000,9999999999);//random request number
  9. $var_cookie=$session; //cookie number
  10. $var_random=rand(1000000000,2147483647); //number under 2147483647
  11. $var_today=time(); //today
  12. $var_referer=$_SERVER['HTTP_REFERER']; //referer url
  13. $var_uservar='btmx_mobile';//$storeinfo['storeid']; //enter your own user defined variable
  14. $var_utmp=$_SERVER['REQUEST_URI']; // request uri
  15.  
  16. $urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$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';
  17.  
  18. $header = '';
  19.  
  20. //Set the language to that of the client so analytics can track it.
  21. if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  22. $header = 'Accept-language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE'].'
  23. ';
  24. }
  25. //Set the user agent to that of the client so analytics can track it.
  26. if (!empty($_SERVER['HTTP_USER_AGENT'])) {
  27. $header = 'User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'
  28. ';
  29. }
  30.  
  31. $opts = array(
  32. 'http'=>array(
  33. 'method'=>'GET',
  34. 'header'=>$header
  35. )
  36. );
  37.  
  38. $handle = fopen($urchinUrl, 'r', false, stream_context_create($opts));
  39. $test = fgets($handle);
  40. fclose($handle);
  41.  
  42. echo '<!-- Google Analytics for mobile END -->';
  43. }
  44. mobile_analytics('UA-xxxxxx-x', 'サイトのドメイン');
  45. ?>

Report this snippet  

You need to login to post a comment.