0

Does anyone know of a piece of code that can run on a server that pipes the data from Apache logs into Google Analytics? I've got a bunch of websites that generate logs, but the users would likely object to injecting Google tracking codes into them. This might be a nice way to get the basics, what's being requested from where, and have it all sorted for me in with my other Google Analytics pages.

Chris J. Vargo
  • 2,266
  • 7
  • 28
  • 43

3 Answers3

3

You can use the new measurement protocol (available for universal analytics account only) to implement a serverside solution.

Piping logs would probably not work very well (at least if you want to do a batch job - I don't think you can send a timestamp via the measurement protocol, so it would look as if all hits occured at the same time) but it shouldn't be necessary anyway, just create an url with the relevant parameters pointing to the google endpoint and sent it in the background via CURL (or similiar).

If you're in the European Union remember privacy guidelines still apply and you need to inform users and provide an opt-out link.

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
1

For non-Universal Analytics accounts, you can use php-ga - Server-Side Google Analytics Client -- it's essentially a server-side implementation of ga.js.

One caveat: If you want the location metrics to record something other than the location of your server, you'll need to log with a Google Analytics mobile tracking ID. Just replace the "UA" in the tracking ID with "MO", like "MO-12345678-1"

mike
  • 7,137
  • 2
  • 23
  • 27
  • 2
    Actually Google just announced on their blog that all accounts will be forced to upgrade to universal analytics within "the next months" (and php-ga is therefore marked deprecated by its developer) so nobody should put any more effort in php-ga based solutions. – Eike Pierstorff Oct 24 '13 at 16:01
  • Many thanks for the info... I missed the part "Classic Analytics properties that don’t initiate a transfer will be auto-transferred to Universal Analytics in the coming months" – mike Oct 24 '13 at 20:15
0

GA needs JavaScript, I think, so that various things like screen resolution can be grabbed. So even if this were possible, you'd be missing a good deal of info for some of your users, skewing your other percentages. Also, if your users are suspicious of Google, they probably would not want you to upload their IP addresses to GA.

With all that in mind, I wonder whether a self-hosted GA-like system would fit the bill? If so, try Piwik.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Thanks. I realize that a lot of the features, such as screen resolution would be missing. Just wondered if anyone has successfully piped in what they do have to GA. Does Piwik just use the apache logs, or does it need code on pages like GA? – Chris J. Vargo Oct 22 '13 at 20:16
  • I believe it uses a JS widget, just like GA does, to capture all that extra data. – halfer Oct 22 '13 at 20:32
  • Piwik uses a javascript tracker and an image pixel as fallback (which will not gather information about the browser). However since the data sits in a mysql database presumably on the same server you could of course parse the logs and insert them into the database. However Piwik does not scale well and is pretty useless if you want to track advertising campaigns, so check before if it suits your needs. – Eike Pierstorff Oct 23 '13 at 09:16