Google Analytics from PHP

by 13 replies
17
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.
#programming #analytics #google #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.
    • [ 1 ] Thanks
    • [1] reply
    • 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
      • [ 1 ] Thanks
  • ... 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 ... ;-)
    • [ 1 ] Thanks
    • [1] reply
    • Detlev, that's a creative idea but I don't believe it will work. When you fopen() the file, the JavaScript is not going to execute. Where would it run? It needs a browser environment to run in, and PHP doesn't provide that.

      This was asked and answered in the Google Analytics Forum recently.

      Steve
      • [ 1 ] Thanks
      • [1] reply
  • 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..
  • Banned
    [DELETED]

Next Topics on Trending Feed

  • 17

    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.