views:

222

answers:

1

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!

+2  A: 

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 http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport

Tzury Bar Yochay
Thanks so much, Tzury! I think I was concentrating on finding an event to bind to, rather than considering comparing the widget's position to the page scrolled value in relation to the viewport's size. My widget does use an <iframe> but I built a quick proof-of-concept using the linked information and it seems to work fine. I appreciate it.
Bungle