How do I extract Google Analytics campaign data from their cookie with Javascript?

后端 未结 4 1539
抹茶落季
抹茶落季 2020-12-24 15:41

I\'d like to be able to pull out the data stored in the Google Analytics tracking cookie with all the campaign tracking information using Javascript. It needs to work with

4条回答
  •  悲&欢浪女
    2020-12-24 16:13

    I've rewritten this to parse the values onto an associative array and make use of quicksmode cookie functions:

    function parseAnalyticsCookie() {
        // 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 values = {};
        var cookie = readCookie("__utmz");
        if (cookie) {
            var z = cookie.split('.'); 
            if (z.length >= 4) {
                var y = z[4].split('|');
                for (i=0; i

提交回复
热议问题