Skip to content

Instantly share code, notes, and snippets.

@Gegam
Forked from BorisChumichev/scrolldepth.js
Last active December 5, 2016 12:04
Show Gist options
  • Save Gegam/fb7ec7d3b19087af377ab45283e261a6 to your computer and use it in GitHub Desktop.
Save Gegam/fb7ec7d3b19087af377ab45283e261a6 to your computer and use it in GitHub Desktop.
var scrollDepthtracking = {}
var contentMaxHeight = Math.max( document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight)
window.addEventListener('scroll', function () {
var currentPos = document.body.scrollTop || window.pageYOffset || document.documentElement.scrollTop
, documentHeight = document.body.offsetHeight
, windowHeight = window.innerHeight
, scrollPercent = Math.ceil((currentPos + 5) / (contentMaxHeight * 10) * 10
if (!scrollDepthtracking[scrollPercent]) {
scrollDepthtracking[scrollPercent] = true
ga('b.send', 'event', new String('Глубина прокрутки', "UTF-8"), scrollPercent)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment