gpt4 book ai didi

google-analytics - 如何使用 Universal Analytics 跟踪 Google Analytics anchor 点击

转载 作者:行者123 更新时间:2023-12-02 06:53:45 29 4
gpt4 key购买 nike

我正在尝试根据此相关问题实现 anchor (index.html#anchor)跟踪: How to track anchor tags with Google Analytics

我使用 anchor 在进入网站时启动 javascript 复活节彩蛋,我想跟踪所有 anchor ,因为它们将是不同的页面(网址)。

所以我会跟踪:

link.html                 20 pageviews
link.html#anchor1 5 pageviews
link.html#anchor2 8 pageviews

JavaScript 复活节彩蛋函数当前加载如下:

    $(function () // on page load
{
if(window.location.hash.slice(1) != "")
launchEasterEgg(window.location.hash.slice(1));
});

$(window).bind('hashchange', function () //hash change detected
{
var hash = window.location.hash.slice(1);
launchEasterEgg(hash);
return true;
});

我不确定是否应该在以下位置启动跟踪代码:

  • “检测到哈希更改”+“页面加载时”
  • 或者直接添加到链接,例如:<a href="#anchor" onclick="eventTrackingFunction()">link</a>
  • 或者只是以某种方式设置:_gaq.push(['_setAllowAnchor', true]);正如我在之前版本的 GA 代码中所做的那样

此外,我不太明白应该跟踪哪种类型的 Google Analytics(分析)事件 ( https://developers.google.com/analytics/devguides/collection/analyticsjs/events )

除了顶部的示例问题之外,我还使用 Universal Analytics,因此我的跟踪代码有所不同:

  <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'mydomain.com');
ga('send', 'pageview');
</script>

最佳答案

我已经设法自己让它工作:我现在在复活节彩蛋启动时跟踪访客:

function launchEasterEgg(hash)
{
ga('send', 'pageview', '/#'+hash); // track hash
// + my function code
}

为了跟踪不启动复活节彩蛋的访问者,我使用:

$(function () // on page load
{
if(window.location.hash.slice(1) != "")
launchEasterEgg(window.location.hash.slice(1));
else
ga('send', 'pageview'); // track no hash pageview
});

当然,我之前加载了通用分析代码(没有“发送综合浏览量”行)。

关于google-analytics - 如何使用 Universal Analytics 跟踪 Google Analytics anchor 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23071415/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com