如何在 Mobile Safari (iPad) 上使用 Google Analytics/_trackEvent?
我一直希望在主要针对 iPad(特别是 Mobile Safari)的单页 JavaScript 应用程序上使用 Google Analytics _gaq.push()
函数。
我的页面仅加载一次,并在用户使用应用程序时继续异步加载数据。我想跟踪用户在应用程序中移动时的交互,因此我决定使用异步 API (_gaq.push()
)。
我听说使用这种方法,GA 数据会在文档卸载时推送。如果这是真的,我怀疑这是否能在 Mobile Safari 上正常工作,因为用户可能很长时间都不会卸载文档。
这是做我想做的事情的最佳方式吗?如果不是,那么将精细跟踪的事件从此类应用程序及时推送到 Google Analytics(分析)的首选方式是什么?
谢谢。
I've been looking to use Google Analytics _gaq.push()
function on a single-page JavaScript application that is primarily targeting the iPad (in particular, Mobile Safari).
My page loads only once and continues to load data asynchronously as the user uses the application. I want to track interactions as the user moves through the application, so I decided on the asynchronous API (_gaq.push()
).
I've heard that with this method, the GA data gets pushed on document unload. If this is true, I have doubts whether this will work well on an Mobile Safari where the user might not unload the document for a long time.
Is this the best way to do what I want, and if not, what is the preferred way to push finely-tracked events to Google Analytics from an application like this in a timely manner?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档卸载时不会发送 GA 数据;文档卸载和 Google Analytics 之间根本没有关联。
使用异步语法时,无论您将其放在何处,Google Analytics 都会异步加载到 DOM 中。同时,
_gaq.push()
创建一个函数队列,在 Google Analytics 加载后执行,并按顺序执行。所有这些都会发生,而不考虑文档卸载、加载、就绪等。当队列到达跟踪函数(
_trackPageview
、_trackEvent
、_trackSocial
等),它执行对远程像素__utm.gif
的请求,Google 使用该请求生成日志以解析和处理为分析数据。一旦
ga.js
加载,_gaq.push()
就充当即时队列;这意味着,如果您在想要跟踪事物时继续从应用程序内生成_gaq.push()
,这些跟踪请求将立即发出。GA data does NOT get sent on document unload; there is no association at all between document unload and Google Analytics.
When using the async syntax, Google Analytics is loaded into the DOM asychronously wherever you put it. At the same time,
_gaq.push()
creates a queue of functions to execute once Google Analytics is loaded, to be executed in sequence. All of this happens without regard for document unload, onload, ready, etc.When the queue reaches a tracking function (
_trackPageview
,_trackEvent
,_trackSocial
, etc.), it executes a request for a remote pixel,__utm.gif
, that Google uses to generate logs for parsing and processing into analytics data.Once
ga.js
is loaded,_gaq.push()
acts as an immediate queue; meaning, if you continue generating_gaq.push()
from within the application when you want to track things, those tracking requests will be made immediately.