javascript - Parsing _utmz cookie substrings to Google Tag Manager variables -
i'm attempting set custom javascript variables in google tag manager utmcsr, utmccn, utmcmd, , utmctr portions of google's legacy analytics _utmz cookie.
the _utmz cookie looks this:
utmz=123456789.1234567890.1.1.utmcsr=[source]|utmgclid=[ad click id]|utmccn=[campaign]|utmcmd[medium]|utmctr=[keyword]
i'm not great @ javascript or regex, here's closest i've gotten gtm doesn't give me token error. grabbed bit website , attempted modify grab utmcsr.
function() { var __utmzcookie = document.cookie.match(/utmcsr=(.*)/); if(__utmzcookie && __utmzcookie[1]) { var utmzvals = __utmzcookie[1].split('.'); if(utmzvals[2]) { return utmzvals[1] + '.' + utmzvals[2]; } } }
Comments
Post a Comment