【问题标题】:Google Analytics Referral from 301 Redirect来自 301 重定向的 Google Analytics(分析)引荐
【发布时间】:2012-11-15 18:15:11
【问题描述】:

我们有一个网站,我们使用一些自定义 javascript 将所有子域和外部域汇总到一个域中。这一切都在起作用。但是,主域显示为引用并破坏了页面流。

我们在 IIS 中使用 ISAPI ReWriter 将所有流量 301 重定向到“example.com”到“www.example.com”。

然后在所有网站上,无论是内部网站还是外部网站,我们都使用相同的通用代码来确定是否应该设置域或是否应该推送链接。

问题: 1)如果我们要跟踪子域blog.example.com,将域设置为“.example.com”是否正确(在_gaq.push(['_setDomainName','.example.com']);), store.example.com 等.example.com?

2) 如果我们将 IIS 中的 example.com 站点重定向到 www.example.com 而不是使用 ISAPI ReWrite 会怎样?

3) 为什么 example.com 显示为推荐,如何阻止这种情况?

 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXETC']);
      var locText = window.location.host;

        // vars to check domain
        var exampleDomain = new RegExp('www.example.com', 'i');
        var exampleRedirect = new RegExp('^example.com', 'i');

        //check if we are on the main domain
        if(exampleDomain.test(locText) || exampleRedirect.test(locText)){

            //Roll Up (domain and subdomains)
              _gaq.push(['_setAllowLinker', true]);
            _gaq.push(['_setDomainName', '.example.com']);

        } else {
            _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);
        })();

        // this function is an exclusion blacklist of sites we don't want to push
        function donotpushlinks(linkpattern)
        {
            var blacklist = [
                "twitter"
                ,"facebook"
                ,"tumblr"
                ,"youtube"
                ,"pinterest"
                ,"infantino"
                ,"exampleuk"
            ];
            var re = new RegExp('\\b' + blacklist.join("|") + '\\b', 'i');

            return(linkpattern.match(re) != null);
        }

jQuery(document).ready(function(){
        //for each anchor on the page, check whether we need to push
        jQuery('a').each(function() {
               var a = new RegExp('/' + window.location.host + '/');
               //do not touch javascript links
               var b = new RegExp('^javascript', 'i');
                  var c = new RegExp('javascript', 'i');
                  //test against the blacklist
               var d = donotpushlinks(this.href);

               //1) check if link is not internal
               if(!a.test(this.href))
               {
                   //2) Check if it is javascript
                   if (!b.test(this.href) || !c.test(this.href))
                   {
                           //3) check if it not one of the blackklist test patterns
                           if (!d)
                           {
                               //console.log(d + " " + this.href);
                               jQuery(this).click(function(event)
                               {
                                   event.preventDefault();
                                   event.stopPropagation();

                                   // Google it
                                   _gaq.push(['_link',this.href]);

                                    return false;
                               });
                           }
                           //3) Otherwise, it is a link to an external site outside of example. Open in new window with NO tracking
                           else
                           {

                            jQuery(this).click(function(event)
                               {
                                   event.preventDefault();
                                   event.stopPropagation();
                                   window.open(this.href, '_blank');
                                    return false;
                               });

                           }
                   }
                   //2) Otherwise, it is javascript, so leave it alone
                   else{

                           }
               }
               //1) otherwise it is internal, so leave it alone
               else
               {
                //console.log('Internal link: ' + this.href);  
               }
            });
});

【问题讨论】:

    标签: javascript jquery google-analytics


    【解决方案1】:

    我不喜欢使用 _setDomainName 'none',它有一些缺点。

    但是,我将首先重新选择 window.location.host 以支持 window.location.hostname_addIgnoredRef,甚至建议使用 window.location.hostname.split('.')[window.location.hostname.split('.').length]

    host 的问题在于它包含端口号,因此它限制了它匹配推荐值的机会。

    https://developer.mozilla.org/en/docs/DOM/window.location

    【讨论】:

    • 有什么替代 setDomainName none 的?该块适用于需要将链接从一个域推送到另一个域的外部站点。
    • _gaq.push(['_setDomainName', '.'+ window.location.hostname]); 会做你需要做的事情,而不需要做一个隐式的 _setAllowHash false line 'none' 做
    • 但这会将外部站点添加到另一个 cookie 中,对吗?他们希望子域汇总到主域——就好像只有一个站点一样。
    • 如果您需要连续导航到子域/主域,您应该在所有站点上使用_gaq.push(['_setDomainName', '.example.com']);,而不是“无”。如果您今天在 example.com 上没有 _setDomainName,那么您应该删除前导点,而不是重置主域的 cookie。
    • example.com 是来自 IIS Isapi Rewriter 模块的 301 重定向。如果您键入 example.com/store 它 301 是您访问 www.example.com/store。因此,对于前导点,如果我删除它,blog.example.com 和 store.example.com 的 cookie 会发生什么?我的理解是,跨较低级别的子域的跟踪仍将在主“.example.com”cookie 中进行跟踪。对吗?
    猜你喜欢
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 2014-07-17
    • 2021-05-23
    • 1970-01-01
    • 2011-11-01
    相关资源
    最近更新 更多