Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement scroll tracking feature #24

Open
jeremydw opened this issue Sep 22, 2016 · 0 comments
Open

Implement scroll tracking feature #24

jeremydw opened this issue Sep 22, 2016 · 0 comments
Assignees

Comments

@jeremydw
Copy link
Member

jeremydw commented Sep 22, 2016

  • 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.
    }
  }
});
@jeremydw jeremydw self-assigned this Oct 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant