简体   繁体   English

在页面加载时发送Google Analytics(分析)事件

[英]Send Google Analytics Event on Page Load

In our website, we need to send an event with an event value on some pages when the page is loaded. 在我们的网站中,当页面加载时,我们需要在某些页面上发送带有事件值的事件。

When we've added the following code to the bottom of our page (after the google analytics script) we don't receive any event record on Google analytics reports. 将以下代码添加到页面底部时(在Google Analytics(分析)脚本之后),我们不会在Google Analytics(分析)报告中收到任何事件记录。

<script>
    ga('send', 'event', 'Showed a page', 'Showed a page', 'Page Type', 12);
</script>

where the 12 is an example event value. 其中12是示例事件值。

We get the events triggered when they're connected to onClick event of something but couldn't find the optimised way of doing it on page load. 当事件与某些事件的onClick事件相关联时,我们将触发事件,但找不到在页面加载时执行事件的优化方法。

First I believe you should place your analytics.js tracking snippet as high in the as possible(not before tags ofc) as per the instructions here . 首先,我相信您应该按照此处的说明将您的analytics.js跟踪代码段放置在尽可能高的位置(而不是c的标记之前)。 One issue is that your command is never put inside the ga() command queue. 一个问题是您的命令永远不会放在ga()命令队列中。 One thing you can do is put your required function after the pageview command that I believe you already get correctly in your Analytics Interface. 您可以做的一件事是,将所需的功能放在pageview命令之后,我相信您已经正确进入了Analytics(分析)界面。 Also are there any errors being logged in your web browsers console?Also you can try and send your event when the analytics.js library has fully loaded. 此外,您的网络浏览器控制台中是否记录了任何错误?还可以在analytics.js库完全加载后尝试发送事件。 A discussed implementation can be found here . 可以在此处找到讨论的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM