3
votes

We use google and doubleclick calls track how the users behave. We have many tracking components. Does anyone know if there is a tool to "test" these analytics calls to make sure they are being fired and sending the right data? it can be free or pay.

What I am looking for is an automated test tool that works like fiddler except, based on the called web page, examines the results and regex's out important pieces, then gives a pass/fail. An easy to use tool would be good but is not necessary.

2

2 Answers

2
votes

I know this is an old question, but assuming that all the trackers you do want to test are Javascript-based, you could achieve this with JS-Unit-Tests. The basic idea is this and can be achieved using all popular JS-Unit-Testing frameworks (for example Jasmine or Mocha):

  • Swap out the actual tracking-objects of your tracking-libraries with stubs, e.g. the push-method of the Google Analytics tracker
  • Invoke the actions you have defined events for, e.g. clicking a link with some JS-code (like jQuery's trigger-method)
  • Instead of the push-method of the actual _ga-object the stub will be called and you can check if the parameters of the function-call are how you expect them to be
  • You could do this against HTML-Fixtures or, if you want to do full functional testing on your live site, couple it with a script for PhantomJS (or use CasparJS) to inject the testing scripts in the webpage and run them right there.

Here is an article that discusses an approach similar to the one I am suggesting: http://viget.com/extend/testing-google-analytics-with-phantomjs

There might be limitations to the approach depending on what you want to test, but if the user interaction you want to track is doable with PhantomJS your should be able to get quite far.

1
votes

Although it might not be exactly what you're looking for, google analytics has a debug mode which displays all tracking data in the console. This is a manual rather than automated testing option, but I still find it very very useful.

If you're testing a site you own, you can change the analytics tracking code to use this mode: replace all references to /ga.js with /u/ga_debug.js in the tracking code for that page

(https://developers.google.com/analytics/resources/articles/gaTrackingTroubleshooting#gaDebug)

Note that you only want to do this temporarily or on a test site as the debugging file is larger and will slow the page down.

Easier option is available if you use Chrome browser - install the Google Analytics debugger extension, and when you turn it on, all GA tracking data of any site you visit will be logged in the console. The extension is found here:

https://chrome.google.com/webstore/detail/jnkmfdileelhofjcijamephohjechhna

I'm still looking for a way to automate testing, so that you can get the output and test it with a regex or something similar. If anyone knows how to capture GA debugging output in a form that can be tested - by redirecting to a text file etc, then I'd love to know!