跟踪发送给客户端的流量
我有一个带有 Google Analytics 4 的新目录网站。
当有人单击将他们带到外部网站的链接时,我试图记录 website_click 事件。这是为了了解并报告我向这些客户端发送了多少流量。
不幸的是,我看不到正在记录的事件。我已尝试安装和使用 Google Analytics 调试器,但我在控制台中没有看到新的输出。
这是我正在使用的代码
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-HIDDENTAG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-HIDDENTAG');
</script>
<script>
$( document ).ready(function(event) {
$( ".link_to_provider" ).click(function(event) {
event.preventDefault();
setTimeout(visitProvider, 1000);
var visited = false;
function visitProvider() {
if (!visited) {
visited = true;
window.open('https://www.example.com');
}
}
// Sends the event to Google Analytics and
// resubmits the form once the hit is done.
ga('send', {
hitType: 'event',
eventCategory: 'provider',
eventAction: 'website_visit',
eventLabel: 'CID-10',
hitCallback: visitProvider
});
});
});
</script>
</head>
<body>
....
<a href="https://www.example.com" rel="nofollow" class="link_to_provider"><button class="btn btn-primary px-4 mb-1 mt-0">Visit Website</button></a>
.....
</body>
感谢您的帮助。
I have a new directory website with Google Analytics 4.
I am trying to record website_click events when someone clicks a link that takes them to the external website. This is to understand and report on how much traffic I am sending to these clients.
Unfortunately, I can't see the event being recorded. I have tried installing and using Google Analytics Debugger but I see no new output in my Console.
Here is the code I am using
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-HIDDENTAG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-HIDDENTAG');
</script>
<script>
$( document ).ready(function(event) {
$( ".link_to_provider" ).click(function(event) {
event.preventDefault();
setTimeout(visitProvider, 1000);
var visited = false;
function visitProvider() {
if (!visited) {
visited = true;
window.open('https://www.example.com');
}
}
// Sends the event to Google Analytics and
// resubmits the form once the hit is done.
ga('send', {
hitType: 'event',
eventCategory: 'provider',
eventAction: 'website_visit',
eventLabel: 'CID-10',
hitCallback: visitProvider
});
});
});
</script>
</head>
<body>
....
<a href="https://www.example.com" rel="nofollow" class="link_to_provider"><button class="btn btn-primary px-4 mb-1 mt-0">Visit Website</button></a>
.....
</body>
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论