Skip to content

Instantly share code, notes, and snippets.

View tanyagupta's full-sized avatar

tanyagupta tanyagupta

  • Washington DC
View GitHub Profile
@tanyagupta
tanyagupta / client_id_in_ga.js
Last active October 2, 2016 19:04
Tracking users using Google Analytics
/*
The most common way to track users in Google Analytics is by using cookies. But sometimes
there are platform and security limitations that will not allow cookies to be set or
stored for multiple sessions. The following code uses the localStorage property (available
now in most browsers) to provide an alternate way to the cookie-based solution. The code
is heavily commented to help even the most casual users understand the overall workings
of the code. Feel free to ignore this part if you know what you are doing.
This work is based on a Google example:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id