![]() |
Google Analytics from PHP 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. |
Re: Google Analytics from PHP 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. |
Re: Google Analytics from PHP 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 |
Re: Google Analytics from PHP ... 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 ... ;-) |
Re: Google Analytics from PHP Quote:
This was asked and answered in the Google Analytics Forum recently. Steve |
Re: Google Analytics from PHP 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 |
Re: Google Analytics from PHP 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 |
Re: Google Analytics from PHP 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 |
Re: Google Analytics from PHP 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 |
Re: Google Analytics from PHP ... 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 |
Re: Google Analytics from PHP 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. |
Re: Google Analytics from PHP Quote:
Steve |
Re: Google Analytics from PHP 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.. |
Re: Google Analytics from PHP |
| All times are GMT -6. The time now is 09:49 PM. |