A Primer on Cookies in Web Analytics, Part 2: What about Web Storage?
Last week I wrote about cookies, and how they are used in web analytics. That post was really just the first in a series of posts I wanted to write about how cookies are used by web analytics tools to identify visitors to your site, and I’ll get to that shortly. But a few readers reached out to me and asked why I hadn’t mentioned web storage, so I wanted to mention it briefly before moving on.
- Cookies are included with every HTTP request, but web storage is only available to the browser. So for tools that need to communicate with the server and give it access to client-side data (like many analytics tools), cookies are still the best solution – even though they clutter up the network as they get passed back and forth, and are limited to about 4KB of data.
- Cookies can be shared across subdomains of the same website, but web storage is subdomain-specific. That means that a cookie with scope of webanalyticsdemystified.com can be read by my blog or any of my partners – but a value stored in web storage is available only to my blog, josh.webanalyticsdemystified.com. For a company that operates many subdomains and tries to track their users across each one, this is a major limitation of web storage.
When I worked at salesforce.com, that second reason had a major impact on the reason we used a cookie to store all sorts of cool personalization data about our visitors, rather than local storage. In fact, at one point I was challenged by my manager with migrating that cookie to local storage – a really exciting project for me because I got to try out some really new technology. But after all our initial testing passed, I remember frantically having to revert all my code prior to our next code release because my own visitor history disappeared once I started browsing our staging site instead of our development site!
So keep that in mind when thinking about whether to use local storage or cookies. Web storage is much more considerate of your users, and much for forward thinking, since it’s utilizing the latest and greatest technology built into browsers. But there are some things it can’t do, so keep it in your toolbelt but remember that there are many times when cookies are still the best way to solve your analytics challenges.