Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Javascript Tracker
  6. Advanced Usage
  7. Extracting the Google Analytics cookie ID

Extracting the Google Analytics cookie ID

Use the following function to extract ID stored in GA’s first-party cookie:

// Find the utma cookie and extract the unique user ID function getGoogleId() { var id, a, c = document.cookie.split('; '); for (var i in c) { a = c[i].split('='); if (a[0]==='__utma') { id = a[1].split('.')[1]; } } return id || 'unknown'; }

You can then set a user’s Snowplow business user ID to be equal to the user’s GA ID:

snowplow('setUserId', getGoogleId());