Skip to content

Implement scroll tracking feature #24

Description

@jeremydw
  • Some sample code below, where ratios is a list of breakpoint percentages (of the page height) to track.
  • A similar utility could be written using airkit's inview module, to track events when specific elements enter view.
var ratios = [0.3, 0.6, 0.9];
var func = function(category, action, label) {
    trackEvent(category, action, label);
};
window.addEventListener('scroll', function() {
  var scrollRatio = window.scrollY /
      (document.body.offsetHeight - window.innerHeight);
  for (var i = 0; i < ratios.length; i++) {
    if (scrollRatio > ratios[i]) {
      var percent = ratios[i] * 100;
      func('EVENT NAME', 'EVENT ACTION', percent + '%');
      ratios[i] = 200; // Some number out of bounds.
    }
  }
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions