javascript 谷歌分析自定义事件跟踪不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18705439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 12:56:28  来源:igfitidea点击:

Google Analytics Custom Event Tracking Not Working

javascriptgoogle-analyticsevent-tracking

提问by Andrew

I am trying to add custom event tracking to a link on a site I built. For some reason it does not seem to be working. The code I have is:

我正在尝试向我构建的网站上的链接添加自定义事件跟踪。出于某种原因,它似乎不起作用。我的代码是:

onClick="_gaq.push(['_trackEvent', 'SOU Links', 'Click', 'Top edu banner']);"

The site URL is http://sou.wpengine.com/. The link with the event tracking is the "Sign Up Now" link at the top of the page. Any ideas?

站点 URL 是http://sou.wpengine.com/。事件跟踪链接是页面顶部的“立即注册”链接。有任何想法吗?

回答by Homer6

I had an issue with events not tracking (using Universal Analytics).

我遇到了无法跟踪事件的问题(使用 Universal Analytics)。

I installed the official Google Analytics Debugger from

我安装了官方的 Google Analytics Debugger

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

And it showed me a warning message that event value was expecting an integer, but receiving an empty string. Once I cleared that up, the events showed up in the realtime tracker right away.

它向我显示了一条警告消息,事件值需要一个整数,但收到一个空字符串。一旦我清除了它,事件就会立即显示在实时跟踪器中。

回答by bbone

It appears you're using the advanced configuration setup described by google here. To track events, you'll want to use the event tracking methods described by google here.

看来您正在使用 google此处描述的高级配置设置。要跟踪事件,您需要使用 google此处描述的事件跟踪方法。

Hope this helps.

希望这可以帮助。

Adding another helpful link: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

添加另一个有用的链接:https: //developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

This will work for older tracking version: Tracking Basics (Asynchronous Syntax)

这适用于较旧的跟踪版本:Tracking Basics (Asynchronous Syntax)

回答by Blexy

As bbone said, you are using the event tracking syntax for ga.js (Classic Analytics) and you have analytics.js (Universal Analytics) on your site.

正如 bbone 所说,您正在使用 ga.js(经典分析)的事件跟踪语法,并且您的网站上有 analytics.js(通用分析)。

If you want to track the "Sign Up Now" link, use this:

如果您想跟踪“立即注册”链接,请使用:

ga('send', 'event', 'SOU Links', 'Click', 'Top edu banner');

回答by Vero O

you should send also _gaq.push(['_setAccount', 'UA-XXXXXX-1']); before the tracking event and install for chrome this extension to debug https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

你也应该发送 _gaq.push(['_setAccount', 'UA-XXXXXX-1']); 在跟踪事件之前并为 chrome 安装此扩展程序以调试 https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

it worked for us

它对我们有用