Skip to content

Instantly share code, notes, and snippets.

@Gegam
Last active March 28, 2016 12:28
Show Gist options
  • Select an option

  • Save Gegam/54f8e957fb51217428f9 to your computer and use it in GitHub Desktop.

Select an option

Save Gegam/54f8e957fb51217428f9 to your computer and use it in GitHub Desktop.
GA depth scroll
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