How google analytics can alter your web performance
Google analytics is often used by Marketing teams to have a feedback of the web site usage, track visits, entry and leave points. Google analytics is easy to use but it has some drawbacks that you don't see at the beginning. Altering the performance of your AJAX operation is a serious drawback.
When the Cookie Crumbles
The famous Yahoo!'s Exceptional Performance team studied and defined the best practices for designing performant web pages. Steve Souders turned this study into the famous High Performance Web Sites book (I strongly recommend this book!). The team continued his work and studied the impact of cookies on a web site. Tenni Theurer explains in Performance Research, Part 3: When the Cookie Crumbles that cookies impact the performance of requests. Indeed, cookies have to be sent by the browser for each request. Having lots of cookies or a big cookie part in the request will slow down each request.
To track visits, GA sets several cookies on the domain (See From __utma to __utmz (Google Analytics Cookies)). If you look at those cookies, you'll be amazed of their number and their size.
Case study on Planzone
For Planzone, after browsing the marketing site and entering in the application, I've found that my browser was sending 583 bytes for cookies, 76% for Google analytics and 23% for the application itself.
The planzone application cookies have been optimized. The number of cookies is reduced to the minimum and their size is small. Each time an AJAX request is made, we must send arround 135 bytes for the application cookies (which is reasonably small).
Application Cookies: 135 bytes (23%)
(46 bytes) AID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; (43 bytes) JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; (46 bytes) SPID=bb8001.121aee.p5/na8fcrGLz0YsfM04nSHET9w8;
The google analytics cookies are amazingly big: 8 cookies and a total size of 448 bytes.
GA Cookies: 448 bytes (76%)
(34 bytes) __qca=1171833534-90015634-27218739; (63 bytes) __utma=68692688.1831257980.1215462364.1238622130.1238700076.158; (103 bytes) __utmz=68692688.1238622130.157.47.utmccn=(organic)|utmcsr=google|utmctr=planzone+referal|utmcmd=organic; (60 bytes) __utma=23092397.781561637.1237016736.1237016736.1238443952.2; (123 bytes) __utmz=23092397.1238443952.2.2.utmccn=(referral)|utmcsr=planzone.com|utmcct=/planzone/f10-team.planzone.com|utmcmd=referral; (15 bytes) __utmc=68692688; (15 bytes) __qcb=295201554; (15 bytes) __utmb=68692688;
This cookie overhead is small and not visible when you display a page. For an AJAX request, you expect some interaction and you expect the request to be fast. In many cases, the AJAX request has been optimize to get a short request and a short response.
The reason why Google Analytics pollutes the Planzone service is that it sets the qca, utma and utmz-like cookies on the domain. Since the marketing site and the application share the same domain, the cookies are passed.
- Do not add Google Analytics within your AJAX application.
- If your marketing site uses GA, consider removing those cookies once the user is logged.