![]() | | ||||||||
| | #1 |
| The Architect War Room Member Join Date: Jun 2009 Location: Cambridgeshire, UK
Posts: 113
Thanks: 18
Thanked 17 Times in 17 Posts
|
Hi, Just wondering if anyone has successfully executed the Google Analytics code from PHP (server side). The reason I ask is because I'm not seeing a match between google and my own site stats (captured by the server). I'm guessing that if anyone visiting my sites has Javascript disabled, then the google code won't execute. Is it possible to call the google code from the server? Thanks in advance, Lee. |
| Lee Harding The Architect | |
| | |
| | #2 |
| Active Warrior War Room Member Join Date: Jun 2009
Posts: 68
Thanks: 10
Thanked 12 Times in 9 Posts
|
I doubt that it would work. The Google Analytics tracking code tracks activity performed by the user on the page to give you info like bounce rates, etc. which can be done on the client-side only using javascript.
|
| | |
| | #3 |
| Senior Warrior Member War Room Member Join Date: Apr 2006 Location: Tucson, AZ, USA.
Posts: 1,025
Thanks: 120
Thanked 158 Times in 115 Posts
|
Lee, AFAIK it can't be done. Certainly not in PHP, and even if you had server-side JavaScript available (e.g. SpiderMonkey) I believe it wouldn't be compatible with what the GA script is doing. According to the latest stats I've seen, you can expect about 5% of your site visitors to have JavaScript unavailable or disabled. One reason your GA stats are off by more than that is probably that folks click away before a page finishes loading, and the GA script is near the bottom of the page, so it never executes. There may be other reasons too. I know I've stared at my browser's status bar while the message "waiting for google-analytics.com" displayed for a long time. IOW sometimes their servers don't respond or your server can't reach theirs. Steve |
| Executive I.T. consulting for small/medium business Website development | PHP - MySQL - JavaScript expert programming Software requirements analysis | Specification writing Project management | Vendor relationship management | |
| | |
| | #4 |
| Detlev Eller War Room Member Join Date: Aug 2009 Location: Republic of San Marino (RSM)
Posts: 41
Thanks: 22
Thanked 2 Times in 2 Posts
|
... since it is javascript, it works on a webpage. If you would want to track something within php (server side) ... you could configure a dummy page, maybe on a "hidden" sub.domain.com .... with the Google Analytics code implemented ... then do an fopen() ... and pass your tracking parameter in the call ... this way, you would get tracking data from within php into Google Analytics ... ;-) |
| | |
| | #5 | |
| Senior Warrior Member War Room Member Join Date: Apr 2006 Location: Tucson, AZ, USA.
Posts: 1,025
Thanks: 120
Thanked 158 Times in 115 Posts
| Quote:
This was asked and answered in the Google Analytics Forum recently. Steve | |
| Executive I.T. consulting for small/medium business Website development | PHP - MySQL - JavaScript expert programming Software requirements analysis | Specification writing Project management | Vendor relationship management | ||
| | |
| | #6 | |
| Detlev Eller War Room Member Join Date: Aug 2009 Location: Republic of San Marino (RSM)
Posts: 41
Thanks: 22
Thanked 2 Times in 2 Posts
| Quote:
i was conceptualizing ... hmm. thanks for better thinking, i see your point! ... so what about the curl lib ... would it provide the environment ... (?) It is a curious problem. I would think, there is some way to configure an environment 'somewhere' and execute that ... the basic idea is building some kind of bridge, not doing it in a direct way ... Detlev | |
| | |
| | #7 | |
| Senior Warrior Member War Room Member Join Date: Apr 2006 Location: Tucson, AZ, USA.
Posts: 1,025
Thanks: 120
Thanked 158 Times in 115 Posts
| Quote:
And if you did send the result to the site visitor's browser (in a hidden iframe, for example) it would be subject to same settings (JavaScript disabled) that caused this question to be asked in the first place. Google would have to provide an API accessible from the server side, and AFAIK they don't. Steve | |
| Executive I.T. consulting for small/medium business Website development | PHP - MySQL - JavaScript expert programming Software requirements analysis | Specification writing Project management | Vendor relationship management | ||
| | |
| | #8 |
| Detlev Eller War Room Member Join Date: Aug 2009 Location: Republic of San Marino (RSM)
Posts: 41
Thanks: 22
Thanked 2 Times in 2 Posts
|
Steve, I think the flaw in our thinking is, that we would actually need Javascript - and we do not. I would think, we would be able to emulate whatever the javascript in the the users browser would do aka what the _gat._getTracker() function does. when "calling home", passing all parameters. the code in ga.js or embedded files should have the answer. Once we found it, we could either proceed with fopen() or curl depending on the method used by the original ga.js call to actually pass the data over the net. Wether it would fit the Google Analytics TOS, is another question ... Detlev |
| | |
| | #9 |
| Senior Warrior Member War Room Member Join Date: Apr 2006 Location: Tucson, AZ, USA.
Posts: 1,025
Thanks: 120
Thanked 158 Times in 115 Posts
|
Hi, Detlev. Try it if you think so. I believe you'll find that http://www.google-analytics.com/ga.js is constructing all the critical calls that cause GA to store the tracking data, and those calls are themselves in JavaScript. I agree that it's theoretically possible that if you could construct and request the right URLs, you might be able to replicate on the server side what their script does on the client. But I wonder if you'd just run into cross-site scripting restrictions that would make the whole exercise fail anyway. Plus, their script is collecting and storing some data that I believe just aren't available on the server side. At best, you'd have gaps. Steve |
| Executive I.T. consulting for small/medium business Website development | PHP - MySQL - JavaScript expert programming Software requirements analysis | Specification writing Project management | Vendor relationship management | |
| | |
| | #10 |
| Detlev Eller War Room Member Join Date: Aug 2009 Location: Republic of San Marino (RSM)
Posts: 41
Thanks: 22
Thanked 2 Times in 2 Posts
|
... well, i just thought, if Lee needs this, there would be a way to do it. Personally, I prefer to let Google Analytics fetch whatever it can and have a real time tracking system running that gives me the data i need. Generally, i read 'GA stats' more like trends than like 'absolutes' and use its information to complete the picture. best, Detlev |
|
--- working on http://2-u.eu/SuperSecretSoftware.com | |
| | |
| | #11 | |
| Detlev Eller War Room Member Join Date: Aug 2009 Location: Republic of San Marino (RSM)
Posts: 41
Thanks: 22
Thanked 2 Times in 2 Posts
| Quote:
... isnīt the whole concept cross-site by nature ... ;-) As you pointed out earlier, the javascript lives in a `bubble` in the visitors browser ... whatever it does to communicate with the GA Tracking Server can be emulated. If it is worth having it, it can be done. Detlev P.S: As long as the Google Analytics Terms of Service would allow it. | |
|
--- working on http://2-u.eu/SuperSecretSoftware.com | ||
| | |
| | #12 |
| Senior Warrior Member War Room Member Join Date: Apr 2006 Location: Tucson, AZ, USA.
Posts: 1,025
Thanks: 120
Thanked 158 Times in 115 Posts
| Yes, you're right. But I wonder whether Google can't protect its own scripts that execute on its servers (the ones called by http://www.google-analytics.com/ga.js) by prohibiting them from executing unless they're called from the proper context. I'm not sure about this. You'd have to try it to find out. Steve |
| Executive I.T. consulting for small/medium business Website development | PHP - MySQL - JavaScript expert programming Software requirements analysis | Specification writing Project management | Vendor relationship management | |
| | |
| | #13 |
| Advanced Warrior War Room Member Join Date: Sep 2009
Posts: 653
Thanks: 2
Thanked 27 Times in 24 Posts
|
google analytics is a javacript code provided by google to track websites uses in many manners page view page visit geo location coutry browser city etc..
|
| | |
| | |
| | #14 |
| Lisa Dozois War Room Member Join Date: Jan 2006 Location: Florida, USA.
Posts: 612
Thanks: 85
Thanked 221 Times in 110 Posts
| |
|
-- Lisa G
| |
| | |
![]() |
|
| Tags |
| analytics, google, php |
| Thread Tools | |
| |
![]() |