Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Last active August 8, 2019 09:32
Show Gist options
  • Select an option

  • Save pbojinov/21e0d9535121f30e4e7e to your computer and use it in GitHub Desktop.

Select an option

Save pbojinov/21e0d9535121f30e4e7e to your computer and use it in GitHub Desktop.
Parse Google Analytics __utmz cookie
// inspiration from http://stackoverflow.com/questions/1688657/how-do-i-extract-google-analytics-campaign-data-from-their-cookie-with-javascript
// readCookie is from // http://www.quirksmode.org/js/cookies.html
// utmcsr = utm_source
// utmccn = utm_campaign
// utmcmd = utm_medium
// utmctr = utm_term
// utmcct = utm_content
var parseAnalyticsCookie = function() {
var values = {};
var cookie = getCookie("__utmz");
if (cookie) {
var z = cookie.split('.');
if (z.length >= 4) {
var y = z[4].split('|');
for (i = 0; i < y.length; i++) {
var pair = y[i].split("=");
values[pair[0]] = pair[1];
}
}
}
return values;
}
/*
More information and examples for each parameter
Campaign Source (utm_source)
---
Required. Use utm_source to identify a search engine, newsletter name, or other source.
Example: utm_source=google
Campaign Medium (utm_medium)
---
Required. Use utm_medium to identify a medium such as email or cost-per- click.
Example: utm_medium=cpc
Campaign Term (utm_term)
---
Used for paid search. Use utm_term to note the keywords for this ad.
Example: utm_term=running+shoes
Campaign Content (utm_content)
---
Used for A/B testing and content-targeted ads. Use utm_content to differentiate ads or links that point to the same URL.
Examples: utm_content=logolink or utm_content=textlink
Campaign Name (utm_campaign)
---
Used for keyword analysis. Use utm_campaign to identify a specific product promotion or strategic campaign.
Example: utm_campaign=spring_sale
*/
@shujaatonline
Copy link
Copy Markdown

you can we set this to hidden fields separately?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment