Track impressions
You can send impressions data to Heap using the track API. Our recommendation is to use a dedicated library. We've listed the following two options in order of the estimated engineering effort required.
Waypoints
Waypoints is a package you can install to abstract away all the more complicated calculations that you need to do to check whether an element is in a view, etc. For example:
var waypoint = new Waypoint({
element: document.getElementById('waypoint'),
handler: function(direction) {
heap.track('Scrolled to waypoint!')
}
})
To get started, check out the Waypoint Library.
IntersectionObservers
IntersectionObservers are relatively cutting-edge JavaScript, and are still listed as Experimental by MDN. It's very customizable, but requires more engineering effort. It isn't compatible with Internet Explorer and offers questionable support across other popular browsers. You can use a polyfill to provide compatibility for older browsers.
Review their Intersection Observer API documentation to learn more.
You can also use the Google Tag Manager's element visibility trigger for impression tracking. See Google's support documentation to learn more.
Updated 5 months ago