Convert Google Analytics cookies to Local/Session Storage

Posted by David Murdoch on Stack Overflow See other posts from Stack Overflow or by David Murdoch
Published on 2010-12-21T17:29:24Z Indexed on 2010/12/30 20:53 UTC
Read the original article Hit count: 263

Google Analytics sets 4 cookies that will be sent with all requests to that domain (and ofset its subdomains). From what I can tell no server actually uses them directly; they're only sent with __utm.gif as a query param.

Now, obviously Google Analytics reads, writes and acts on their values and they will need to be available to the GA tracking script.

So, what I am wondering is if it is possible to:

  • rewrite the __utm* cookies to local storage after ga.js has written them
  • delete them after ga.js has run
  • rewrite the cookies FROM local storage back to cookie form right before ga.js reads them
  • start over

Or, monkey patch ga.js to use local storage before it begins the cookie read/write part.

Obviously if we are going so far out of the way to remove the __utm* cookies we'll want to also use the Async variant of Analytics.

I'm guessing the down vote was because I didn't ask a question. DOH!

My questions are:
Can it be done as described above?
If so, why hasn't it been done?


I have a default HTML/CSS/JS boilerplate template that passes YSlow, PageSpeed, and Chrome's Audit with near perfect scores. I'm really looking for a way to squeeze those remaining cookie bytes from Google Analytics in browsers that support local storage.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about cookies