【问题标题】:How do you get location.hashtag from the referrer url - Google Analytics您如何从引荐来源网址获取 location.hashtag - Google Analytics
【发布时间】:2012-10-10 02:49:34
【问题描述】:

有一个网站在其网址中使用页面按钮和主题标签 (#) 来控制其内容(链接)的排序方式。他们链接到我的网站,我想知道人们在最终找到我的网站并点击之前点击了哪些按钮。

例如,引荐来源网址看起来像这样 - http://www.example.com/page1?content=1234#button1

有没有办法提取主题标签 (#) 之后的值,以便我可以知道人们是如何排序以找到我的网站的?我考虑过使用 document.referrer.location.hashtag,但我认为这行不通...

我最终希望将这些数据导入 Google Analytics(分析)(我可能可以使用自定义变量来做到这一点),但任何其他关于如何在 GA 中做到这一点的提示都值得赞赏。

感谢您对此提供的任何帮助!

【问题讨论】:

    标签: javascript google-analytics


    【解决方案1】:

    URL 的哈希部分永远不会发送到服务器,它似乎没有存储在 document.referrer 的 javascript 对象中。

    访问 URL 的哈希部分的唯一方法是在浏览器位于该页面时从该页面内访问它。

    翻译:除非您控制引用页面,并在链接中传递哈希片段,否则无法获取它。

    更多信息:http://www.razzed.com/2009/02/12/uh-oh-ajax-powered-search-kills-keywords-in-referrers/

    【讨论】:

      【解决方案2】:
      <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-XXXXX-X']);
      
        /*
         * Function: Hash Custom Variable
         *   Pass everything after # in document.referrer to GA custom variable
         */
        (function() { 
      
          // Parse out the hash part of the referrer
          var referrerHash = document.referrer.split("#")[1];
      
          // If the hash exists, pass it back to GA
          if(typeof referrerHash !== "undefined") {
            _gaq.push(['_setCustomVar', 1, 'Sort', referrerHash, 3]);
          }
      
        })(); // IIFE to not leak global vars
      
        // Have to _trackPageview after custom variable is pushed    
        _gaq.push(['_trackPageview']);
      
        (function() {
          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);
        })();
      </script>
      

      有用的来源:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-04
        • 2012-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多