我的 HTML 文件中有 和 之间的所有 Google Analytics(分析)代码。这些统计数据得到正确处理。
在我的 onclick 事件之后,下面的函数被调用,我想向 Google Analytics 发送一个事件,但从未收到。我做错了什么?
public static native void googleAnalyticsEvent(String boxId) /*-{
_gaq.push(['_trackEvent', boxId , 'Click']);
}-*/;
仅供引用,如果我将此代码替换为以下代码,则会正确显示警报:
public static native void googleAnalyticsEvent(String boxId) /*-{
alert(boxId);
}-*/;
最佳答案
尝试:
public static native void googleAnalyticsEvent(String boxId) /*-{
$wnd._gaq.push(['_trackEvent', boxId , 'Click']);
}-*/;
"Note that the code did not reference the JavaScript window object directly inside the method. When accessing the browser's window and document objects from JSNI, you must reference them as $wnd and $doc, respectively. Your compiled script runs in a nested frame, and $wnd and $doc are automatically initialized to correctly refer to the host page's window and document."
关于javascript - 使用 JSNI 从 GWT 向 Google Analytics 发送事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663834/