Recently a client asked Altentee to generate some load against their subscription to Google Analytics (GA). Calls to GA and other 3rd party monitoring tools are typically requests we blacklist or consider out of scope. So it was unusual to think the other way around, how would you performance test GA?
The solution as it turns out is quite simple. Google Analytics is well documented here in terms of what query parameters constitute the GIF request that registers traffic.
The key parameters which need to be catered for when spoofing traffic are:
utmn => Unique ID generated for each GIF request to prevent caching of the GIF image.
utmhid => Another unique ID not documented but I think is related to AdSense
plus all the GA cookies including utma, utmb, utmc and utmz
The best way to parametize this is to observe real traffic with a tool like FireBug in the Net(work) panel. That way you can make a copy of a real GIF request. Essentially you are going to fake the call to __utm.gif. An example request looks like this:
http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=123456789&utmhn=www.altentee.com&utmcs=UTF-8&utmsr=1920×1200&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.0%20r45&utmdt=AlteneeBlog&utmhid=1697634062&utmr=-&utmp=%2F&utmac=UA-12345678-3&utmcc=__utma%3D199946558.28502083.1280297456.1280637882.1281056979.6%3B%2B__utmz%3D199946558.1280297456.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&gaq=1
All you need to do to spoof traffic or generate page views to your GA account is make repeated calls to this URL after parametizing key fields previously mentioned. An example request in JMeter with corresponding parametized functions in bold (random and time) looks like this:
/__utm.gif?utmwv=4.7.2&utmn=${__Random(10000000,60000000,utmn)}&utmhn=www.altentee.com&utmcs=UTF-8&utmsr=1366×768&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.1%20r53&utmdt=PerformanceTest&utmhid=${__Random(100000000,900000000,utmhid)}&utmr=-&utmp=%2F&utmac=UA-12345678-3&utmcc=__utma%3D199946558.1448353202.${__time()}.${__time()}.${__time()}.4%3B%2B__utmz%3D199946558.${__time()}.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&gaq=1
You could also build this URL from scratch although it’s much easier to copy and modify the target URL for the site you’re actually testing. Please don’t use the URLs above as I’ve faked other things like the Google Analytics account code (utmac). It’s also worth changing the page title (utmdt) so you can separate real traffic from the fake traffic generated during performance testing.
Build a simple test plan in JMeter with a HTTP sampler generating requests to the aforementioned URL, put in a constant timer (or similar) so you don’t spam GA’s servers and away you go. You can then measure response time to this service for as many threads as you like. I generated 10K page views in 5 minutes which was more than sufficient to satisfy the client’s requirements.



