Posted by mumme 4 years 6 weeks ago
I am trying to get some statistics with my mobile site, so I extend the Device Atlas API. What do you think about this PHP code?
$properties = da_get_properties($tree, $_SERVER['HTTP_USER_AGENT']); $var_utmac='UA-000000-00'; //enter the new urchin code $var_utmhn='devi.mobi'; //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='&ua='.urlencode($_SERVER['HTTP_USER_AGENT']); //enter your own user defined variable $var_uservar.='&vendor='.urlencode($properties[vendor]); $var_uservar.='&device='.urlencode($properties[_matched]); $var_uservar.='&model='.urlencode($properties[model]); $var_utmp=$_SERVER['PHP_SELF']; $sr = urlencode($properties[displayWidth].'x'.$properties[displayHeight]); // screen size $sc = urlencode($properties[displayColorDepth].'-bit'); // color depth $ul = '?'; // user language, I am not setting $je = '0'; // support for javascrip, I am not setting $fl = urlencode($properties[vendor].'-'.$properties[_matched].'-'.$properties[model]); // flash version, I am sending device information instead. Don't know if it work yet $dt = $var_utmp; // page title, I am sending page URL $urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr='.$sr.'&utmsc='.$sc.'&utmul='.$ul.'&utmje='.$je.'&utmfl='.$fl.'&utmdt='.$dt.'&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'; $handle = fopen ($urchinUrl, "r"); $test = fgets($handle); fclose($handle);




Posted by skolesnyk 4 years ago
Did you take the code from this http://www.vdgraaf.info/google-analytics-without-javascript.html and expanded it?
Anyways, I'll try it on my mobile site and will tell you the results in day.
Posted by skolesnyk 4 years ago
I changed it a bit for tera-wurfl use. But looks like it's working...
Posted by atrasatti 4 years ago
Mobile Genius
Very interesting piece of code.
I've installed this on a test site. It's still not perfect for me, I need to debug a bit, but seems to be sending data to Google. I'll post more feedback here as I improve the script.
Very good tip.
Posted by skolesnyk 4 years ago
I put it on mine and setup device filltering like this
Field A -> Extract A :User Defined: .*brand=(.*)&model=(.*)
Output to -> Constructor:Visitor Browser Program: $A1 / $A2
I still have to figure out how to transmit user IP address to google for geo location decoding.
Andrea, did you manage to do it?
Posted by Fareed (not verified) 4 years ago
This comment has been moved here.
Posted by dbl 4 years ago
If you replace the last 3 lines in your code by these
From now you can send the USER_AGENT from your manually-custom request to analytics.
Cheers.
Posted by kbelange (not verified) 3 years ago
Does the above method still work?
I've set up a Unit Test based on Peter v.d. Graaf's example that's not generating any Google Analytics data, although the HTTP request/response appears to work:
Get Google Analytics...
GA get request:
GA get response: GIF89a�����,D;
TestCase AGoogleAnalyticsOriginalCodeTestCase->testGoogleAnalytics() passed
Posted by kbelange (not verified) 3 years ago
are there any tricks to setting the cookie number so that google correctly recognizes user sessions?
GA is still not recognizing user sessions: i.e, each hit is seen as an Absolute Unique Visitor, so none of the Visitor Trending or site crawling stats make sense
here are the cookie values i'm sending, with a uniquely generated session id of: "73305051" in this case (my session management code also handles cookieless browsers):
&utmcc=__utma%3D73305051.1572483978.1215112280.1215112280.1215112280.2%3B%2B
__utmb%3D73305051%3B%2B__utmc%3D73305051%3B%2B__utmz%3D73305051.1215112280.2.2.
utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D73305051.unit+test%3B
my mostly working code is a version of Ian Lewis' customization of Peter v.d. Graaf's example
in case it helps others, the tricks that got the USER_AGENT working for me were:
1) using CURL as above (thanks to 'dbl'):
// using curl()
$handle = curl_init($this->fUrchinUrl);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $httpOptions);
curl_setopt($handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$this->fContent = curl_exec($handle);
curl_close($handle);
2) being careful to set the Host in the HTTP headers like so:
$header = 'Host: www.google-analytics.com\r\n';
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$header .= 'User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'\r\n';
}
//Set the language to that of the client so analytics can track it.
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$header .= 'Accept-language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE'].'\r\n';
}
$httpOptions = array(
'http'=>array(
'method'=>'GET',
'header'=>$header,
'request_fulluri'=>'true'
)
);
Posted by dpowers 3 years ago
How would one set the page that the user leaves from?
How would you set how long the user spent on a page? Maybe set a session when the user arrives on the page and then check that session when they arrive on the next page and subtract it from the current time, BUT then you would not update the GA for the previous page!
I would think it might be an idea to create GALogging.php script that would run on a cron and loop through a log file. This way for each record in the log file it can look ahead to the next log for the same session if there is one then is can check the time and see how long the user spent on the current page/log and if there is not another log for that session then it knows that the current log/session was the page the user exited on.
It would loop through each long and use curl to send the info to GA.
Any thoughts?
Posted by vvslaura 21 weeks ago
I think it is possible for mobile to optimize with Google analytics. Most of the search engine provide this feature for mobile versions currenlty.
Payday Loan
Posted by MarkCooper 21 weeks ago
Google Analytics for Mobile use java script .use script after take care of collect the related tracking parameters and sending them to the Analytics service .
payday loan
Posted by Gofree Sing 21 weeks ago
Isn't this just working as usual?
Download Full PC Games FREE!Posted by shreyasm89 18 weeks ago
Your thoughts are partly correct. However tracking data in Google Analytics is heavily dependent on the time when the cookie is set, when a user arrives on a particular page. Google Analytics calculates time by tracking the time stamp on Page B and subtracting it from the time stamp on Page A. Therefore, it needs at least two pageviews to calculate a duration. If it's a bounce, only one pageview, then the time value is 0 for that visit. Shreyas - The Convonix Analytics Team
Posted by iPhoneappsexpert 14 weeks ago
Quite useful for me... Thanks
Posted by Bernard86 5 weeks ago
Thanks. I've implemented this piece of code and it works superb!
-----------------------------------------------
doorlopend krediet
Posted by xiaopy12 1 week ago
Christian Louboutin Sale sfryhsey