Last active
March 28, 2016 12:28
-
-
Save Gegam/54f8e957fb51217428f9 to your computer and use it in GitHub Desktop.
GA depth scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var currentPos = body.scrollTop || window.pageYOffset || document.documentElement.scrollTop, | |
| body = document.body, | |
| windowHeight = window.innerHeight, | |
| documentHeight = document.body.offsetHeight, | |
| scrollPercent = parseInt( (currentPos + 5) / (documentHeight - windowHeight) * 10) * 10; | |
| //b.send - первый обязательный аргумент, где 'b' - имя счетчика, которое задается в самом счетчике: | |
| /* кусок кода из счетчика | |
| ga('create','UA-59280394-9','auto',{'name':'b'}); | |
| ga('b.require', 'displayfeatures'); - эта строчка обязательна для показа подробной статистики по посетителям (интересы. география и т.д.) | |
| ga('b.send','pageview'); | |
| */ | |
| var scrollDepthtracking = {}; | |
| window.addEventListener ('scroll', function () { | |
| if (!scrollDepthtracking[scrollPercent]) { | |
| scrollDepthtracking[scrollPercent] = true; | |
| ga('b.send', 'event', 'Глубина прокрутки', scrollPercent); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment