Extract Google Analytics campaign data from their cookie
Inspiration from http://stackoverflow.com/questions/1688657/how-do-i-extract-google-analytics-campaign-data-from-their-cookie-with-javascript
I use https://github.com/carhartl/jquery-cookie to extract data from cookie.
parseAnalyticsCookie = () ->
# utmcsr = utm_source
# utmccn = utm_campaign
# utmcmd = utm_medium
# utmctr = utm_term
# utmcct = utm_content
result = {}
cookie = $.cookie("__utmz")
if cookie
z = cookie.split('.')
if z.length >= 4
for p in z[4].split('|')
params = p.match /(.*)=(.*)/
result[params[1]] = params[2] if params != null
return result
Written by Carlos Hernández
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffesscript
Authors
polimorfico
1.074K
Related Tags
#coffesscript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#