我当前的项目需要(如果可能)跟踪 JavaScript 小部件的实际视图,以便我们可以将此数据与我们的分析软件报告的页面浏览总数进行比较/控制(Clicky 和/或 Google Analytics)。
基本上,我们将此小部件出售给客户,并希望能够提供可靠的指标来证明该小部件在激发客户兴趣方面的功效。
为此,我们希望能够将点击率报告为总小部件浏览次数的比例,而不是总页面浏览次数(因为我们的假设是许多人浏览页面小部件打开后可能实际上看不到它,因为它位于页面底部附近的一长列文章文本下方)。
我的问题是 - 有什么方法可以可靠地跟踪 HTML 元素(例如,小部件的容器元素或其所在的元素)何时进入浏览器视口?当小部件出现在浏览器视口中时,我们希望增加分析统计数据,而不是当它刚刚加载到页面上并且从未进入视口时。
如果这有影响的话,小部件将加载 jQuery。感谢您的帮助!
My current project requires (if possible) tracking actual views of a JavaScript widget, so that we can compare/control this data against the total number of pageviews reported by our Analytics software (Clicky and/or Google Analytics).
Basically, we're selling this widget to a client and want to be able to provide solid metrics to demonstrate the efficacy of the widget in generating customer interest.
To do this, we want to be able to report clickthrough rates as a proportion of total widget views, not total page views (since our assumption is that many people viewing the pages that the widget is on may not actually see it, since it lives beneath a long column of article text near the bottom of the page).
My question is - is there any way to reliably track when an HTML element (e.g., the widget's container element, or the that it lives in) comes into the browser viewport? We would want increment the analytics stats when the widget appears within the browser viewport, but not when it is just loaded on the page and doesn't ever make it into the viewport.
The widget will have jQuery loaded, if that makes a difference. Thanks for any help!
发布评论
评论(1)
我不确定这个小部件是如何注入到容器页面中的。
如果不是使用 iframe 完成的,而是使用
那么您的问题已经在 如何判断 DOM 元素在当前视口中是否可见?
I am not sure how this widget is injected into the container page.
If it is not done by using iframe but say a
<script src="widget-generator-url">
then your question is already answered at How to tell if a DOM element is visible in the current viewport?