Web analytics regression testing with WAUnit
WAUnit is a web analytics regression testing framework I created. It is written in Python and leverages Selenium webdriver and a built-in proxy server to test web analytics implementations.
With WAUnit you can automagically verify your entire web analytics implementation!
Currently, it only supports Google Analytics, but support for other platforms is under way.
How does it work?
I’m going to use the Google Store as an example. When a user clicks the ‘BUY FROM $499.00’ button (marked in red below), an event with the following specifications is fired:
- hitType: event
- eventAction: Buy Now
- eventCategory: Checkout Funnel
- eventLabel: nexus_6p
WAUnit is composed of two main components:
- a local proxy server based on mitmproxy
- one or more unit test scripts
The local proxy is started using a shell command: waunitproxy.
A simple a unit test using Selenium programmatically visits the Nexus 6P page and clicks the ‘Buy from $499.00’ button.
Meanwhile, the local proxy intercepts the web analytics hit.
The unit test connects and compares the proxy hit log with the specification. If the specification matches, the unit test will pass, if not it will fail and provide information on what doesn’t match.
WAUnit allows you to verify web analytics implementations, automatically. Trust in the implementation is invaluable to the success of web analytics.
See a 5 minute video with the complete Google Store example (view full screen)
Installation & Google Store Demo
Install WAUnit using Python package manager or download WAUnit from GitHub
Create a project folder for the sample unit test. We will use it to store the configuration file and the unit tests.
Create a file named: waunit.cfg and save it to your project folder.
Open a shell in you project folder and launch the proxy server, the default configuration file should work fine.
Configure firefox to use the local proxy 127.0.0.1:8080. Go to a website and verify you can see the google analytics hits in the proxy console.
Open your favorite Python editor and paste the code below in a file named: sample.py. Edit line 9 to reflect your WAUnit configuration file.
In the shell run sample.py. A Firefox window should open automatically and you should see the hits to Google Analytics in the proxy console.
WAUnit will soon support other web analytics platforms. Make sure you follow and star WAUnit on GitHub.