开发者

How do you troubleshot google analytics code?

开发者 https://www.devze.com 2023-03-26 06:49 出处:网络
Can anyone share best practices for troubleshooting google anlytics code? Has anyone built a debugging tool?Does google have a linter hidden somewhere? Does anybody have a good triage logic diagram?

Can anyone share best practices for troubleshooting google anlytics code?

Has anyone built a debugging tool? Does google have a linter hidden somewhere? Does anybody have a good triage logic diagram?

I'll periodically set up different parts of GA and it seems like every time I do it takes 4 or 5 days to get it wo开发者_运维百科rking.

The workflow looks like this:

Read the docs on the feature (e.g. events, custom variables).
Implement what appears to be the correct code based on the docs.
Wait a day.
See no data.
Google every version of the problem I can imagine.  Find what may be a solution.
Change my code.
Wait a day.
See no data.
Loop:
    Randomly move elements of the tracking code around.
    Wait a day.
    If other parts break, tell ceo, get yelled at, revert changes.
    If data appears, break.
Pray it continues to work/I never have to change the tracking code again.

For obvious reasons, I'm not satisfied with this workflow and hoping someone has figured out something I haven't.


Everything I do, debugging GA code, stops and starts with the Google Analytics Debugger Chrome Extension. It prints out to the console a summary of the data it has sent to Google Analytics which, for all purposes except testing profile filters, is all you need. It'll eliminate the "wait a day" step.

If you're not a fan of Google Chrome, you can inspect the HTTP requests yourself to see how the data is parsing. You can use this guide to figure out what each paramater in the URL represents.

In terms of ensuring the features I've installed or the code itself is working, I'll open a fresh browser (cleared of cookies), and navigate to the site I'm testing via Google search. I'll proceed to navigate to all of the pertinent pages, and trigger all the pertinent events, all the while ensuring that the requests are being sent to Google, and that the session isn't broken at any point (by either keeping an eye on the Session Count, or ensuring that the traffic source doesn't change from organic/google to direct or a self-referral.

Screenshot:

How do you troubleshot google analytics code?


To begin with, this answer isn't at odds with any portion of either of the two answers before mine--i.e. you could certainly implement them all without conflict.

My answer just reflects my own priority, which is that the latency issue. Latency makes debugging far more difficult than it should be. Ten minutes of latency while waiting for the compiler to finish is irritating, four hours (minimum GA latency) is painful.

So for me, the first step in building a GA de-bugging framework was to somehow get the GA results in real-time--in other words, if i changed a regular expression filter, i needed to catch the traffic processed by that filter. So removing the 4-24 hour latency in getting results from the GA server was critical.

The easiest way i have found so far to do this is to modify the GA tracking code on each page of your Site so that it sends a copy of each GIF Request to your own server.

To do this, immediately before the call to trackPageview(), add this line:

pageTracker._setLocalRemoteServerMode();

This will send the entire request header to your server access log, which you can parse in real time. (Specifically, your server writes to the access log one line at a time--one line corresponds to one request. All of the GA data is packaged and set as a request header, so there's perfect coincidence between the two.


yahelc answer is great, but I'd like to add my 2c here.

Get yourself a nice sniffer to see the hits flowing. Nice options:

  • Wasp
  • Charles
  • HTTPFox
  • Fiddler

Then implement your changes on QA.

Test this new setup on QA. Things you should keep an eye on.

  • Always make sure that the basic pageview fires. It should have at least an utmp value and no utmt set.
  • Make sure the visitor Id doesn't get overwritten. This is the second number on the __utma cookie. This number should be your userid, if it changes then things are broken.
  • Make sure your pageviews contain the page and session variables you set. If you set any. They are coded into the param utme.
  • Make sure that any Visitor custom var is fired before your basic pageview. utmt=custom variable
  • Make sure the source data is not overwritten (Campaign/medium/source/content/keyword) - These are set on the __utmz cookie. If it gets overwritten by direct or a referral of you own site there's something wrong.
  • If you miss any event it may be due a reqired field missing or the last value being a float or string. The value of an event must be an integer.
  • If you're using the ecomerce double check all your parameters. Make sure that you're firing everything as strings here and that unused parametrs are empty strings.
  • triple check your account number. UA-XXXXX-X.
  • If your doing something with custom JS make sure to test on all browsers, and try to get at least the basic tracking on a safe zone where you are sure things won't break.
  • Send debug info about javascript code that might break GA to GA. Check this.
0

精彩评论

暂无评论...
验证码 换一张
取 消