Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you troubleshot google analytics code?

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 working.

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.

like image 951
Ted Avatar asked Aug 07 '11 19:08

Ted


People also ask

How do I share my Google Analytics code?

Change your data sharing settingsSign in to Google Analytics. Click Admin, and navigate to the account you want to edit. In the ACCOUNT column, click Account Settings. Edit any setting and click Save.


2 Answers

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:

enter image description here

like image 56
Yahel Avatar answered Nov 11 '22 22:11

Yahel


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.

like image 22
doug Avatar answered Nov 12 '22 00:11

doug