【问题标题】:Google Analytics: Cross Domain Rollup to Single Entity with Single Jquery Link PushGoogle Analytics:使用单个 Jquery 链接推送跨域汇总到单个实体
【发布时间】:2026-01-31 13:00:01
【问题描述】:

目标是将被视为一个网站一部分的外部域汇总到一个属性和实体中,以便转化不会显示推荐媒介或退回。我想在所有站点共享的单个实体和单个 JS 文件下设置跨域跟踪。

三个不同的域真正属于一个站点:www.example.com、exampleblog.com、examplestore.com。

我已阅读 Google 建议在外部站点上使用不同代码块的解决方案,但我想为所有站点创建一个文件并链接到主域上的该文件。我创建了一个我希望使用的 JS 文件,这样代码更容易维护,而且我不必弄乱外部域。我想使用 Jquery 为不是 www.example.com 的外部域推送 _link。因此,如果它不是主域,则将域设置为 none 并将 _link 推送到 cookie 中。

但是,外部域在媒体中仍显示为“引荐”并显示引荐来源。相反,我们希望来源是直接的,而媒介是无的。

以下是分析中显示的内容:

  • www.example.com/page1.html
  • 来源:(直接)
  • 中等:(无)

  • exampleblog.com/page2.html

  • 来源:example.com
  • 媒体:推荐

  • examplestore.com/page3.html

  • 来源:exampleblog.com
  • 媒体:推荐

  • www.example.com/page4.html

  • 来源:(直接)
  • 中等:(无)

问题在于 examplestore 和 exampleblog 的页面条目。当它们应该被强制显示为直接时,它们显示为推荐。

注意:我有一个过滤器可以在页面名称中显示域。我们有完整的资料和不同的属性设置来显示推荐,因此这仅用于转化和目标渠道的特定目的。

// Cross Domain Tracking Under a Single Entity
alert("Loading Google...");

 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-3']);


    var locText = document.location + '';
    console.log(window.location.host);

    // one if statement just needs to know if it's at our primary domain
    var exampleDomain = /example\.com/i;

    if(exampleDomain.test(locText)){
        //Roll Up (domain and subdomains)
        _gaq.push(['_setDomainName', '.example.com']);

    } else {
        //Tag
        _gaq.push(['_setDomainName', 'none']);
            _gaq.push(['_addIgnoredRef', window.location.host]);

    }

    _gaq.push(['_setAllowLinker', true]);
    _gaq.push(['_trackPageview']);



    (function() {

    // load the ga.js file.  This happens last now.
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();


jQuery(document).ready(function(){
alert("Ready");
    jQuery('a').each(function() {
           var a = new RegExp('/' + window.location.host + '/');
            alert(a + " " + this.href);        
           //check if it is external
           if(!a.test(this.href)) {
               alert("external link");

               jQuery(this).click(function(event) {
                   event.preventDefault();
                   event.stopPropagation();
                   alert("GOOGLED");
                   // Google it
                   _gaq.push(['_link',this.href]); 
                   return false;
               });
           }
        });
});

【问题讨论】:

    标签: javascript jquery google-analytics cross-domain


    【解决方案1】:

    您应该同时使用跨域跟踪和_addIgnoredRef() 以防止 GA 将域显示为引荐来源。

    一定要测试您的跨域 jQuery 方法,以确保在您进行跳转后正确设置 GA __utma cookie。当用户跳转时,听起来好像正在启动一个新会话。

    【讨论】:

    • 谢谢,我今晚试试,明天告诉你。
    • 所有警报都按预期触发。我想知道,我是否需要设置 gaq.push(['_setDomainName', '.example.com']);到 www.example.com,因为正在进行一些 IIS ISAPI 重写,迫使域到 www。像这样? gaq.push(['_setDomainName', 'www.example.com']);
    • _addIgnoredRef 和 _setAllowLinker 行必须位于 _trackPageview 之前。这些是跟踪器的属性。
    • 好的,我编辑了上面的代码。我将 addIgnoredRef 移动到我将 setDomainName 设置为 none 的块中。我将它移出 jquery A click 功能,并离开了_link。这一切看起来都对吗?万维网呢。与 Isapi Rewriter 合作?
    • 我测试了您的脚本,它正确地执行了 _link 并将 GA cookie 传递到外部 URL。在该外部 URL 上,您还需要确保 _setAllowLinker 设置为 true。 isapi 重写器应该没有影响。
    最近更新 更多