google analytics - multiple trackers on one page (cookie conflict)

后端 未结 9 2565
自闭症患者
自闭症患者 2020-12-02 13:04

I\'m writing a web application that\'s supposed to be embedded in other people\'s websites (kind of a widget). I\'m using Google Analytics to track all the people that visit

相关标签:
9条回答
  • 2020-12-02 13:46

    This person is having the same problem on the Google Analytics help fourm. I'd suggest taking a look at the thread. But regularly GA doesn't support multiple trackers.

    I like Clicky myself, but it costs money.

    0 讨论(0)
  • 2020-12-02 13:47

    According to the documentation listed by Török, it seems the correct answer is to use _setCookiePath. This causes each tracker to use completely different cookies.

    Example code from website:

    <script type=”text/javascript”>
        var pageTracker = _gat._getTracker(”UA-11111-1″);
    
        pageTracker._setDomainName(’domain.com’);
    
        pageTracker._setCookiePath(’/subdirectory/’);
        pageTracker._trackPageview();
    
        var otherTracker = _gat._getTracker(”UA-22222-1″);
        otherTracker._setDomainName(’domain.com’);
        otherTracker._trackPageview();
    </script>
    

    When you link from one domain to another, every link that posts to the other domain has to look like this:

    <a href="pageTracker._linkByPost('otherdomain.com/petStoreCart/legalTerms.php');"
    

    This will add Google Analytics specific query string values that will be used by the above script to set the cookie (source).

    0 讨论(0)
  • 2020-12-02 13:47

    I have used this structure on our site and clients sites and it works like a charm...

    <script type="text/javascript"> 
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");    
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'     type='text/javascript'%3E%3C/script%3E")); 
    </script> <script type="text/javascript"> 
    
    try {
    
    //Original tracking
    var pageTracker_ORIG = _gat._getTracker("UA-XXXXXXX-1");
    pageTracker_ORIG._setDomainName('.sleepinggiantmedia.co.uk');
    pageTracker_ORIG._trackPageview();
    
    //New Analytics tag
    var pageTracker_SGM = _gat._getTracker("UA-XXXXXXX-1");
    pageTracker_SGM._setDomainName('.sleepinggiantmedia.co.uk');
    pageTracker_SGM._trackPageview();
    
    
    } catch(err) {}
    

    0 讨论(0)
提交回复
热议问题