tracking
tracking
Hi
I was able to create a site where I was able to count how many people scrolled to a section of the page. I've been looking but I don't seem to be able to figure out how to track how many people has left the site.
Can someone help me with this?
Here is the code that I have
- var hasScrolled = "blank";
$(window).scroll(function() {
var y_scroll_pos = window.pageYOffset;
if(isIE()<9 && isIE() != false){
var y_scroll_pos = document.body.scrollTop || document.documentElement.scrollTop;
}
if(y_scroll_pos > 200){
$(".header-inner").addClass("sticky");
$(".mazda-logo-left").addClass("sticky");
}else{
$(".header-inner").removeClass("sticky");
$(".mazda-logo-left").removeClass("sticky");
}
//console.log("hasScrolled" +hasScrolled)
$(".scrollpos").each(function(index, element) {
//$("body").append("#"+$(this).parent().attr("id"))
var scroll_pos_test = $("#"+$(this).parent().attr("id")).offset().top;
if(y_scroll_pos >= scroll_pos_test && y_scroll_pos < Number(scroll_pos_test)+$(this).parent().innerHeight()) {
if(hasScrolled != $(this).parent().attr("id")){
hasScrolled = $(this).parent().attr("id");
tracker($.trim(hasScrolled));
if ( hasScrolled == 'the-idea' ) {
//$(".wrapper").css("background","red")
$.getJSON('update_count.php?section=idea');
}
if ( hasScrolled == 'the-tech' ) {
//$(".wrapper").css("background","blue")
$.getJSON('update_count.php?section=tech');
}
if ( hasScrolled == 'the-result' ) {
//$(".wrapper").css("background","yellow")
$.getJSON('update_count.php?section=result');
}
}
}
});
});
- $(".nav a").click(function(){
$(".nav a").removeClass("active");
$(this).addClass("active");
tracker($.trim($(this).attr("data-id")));
var dataCo = $(this).attr("data-id");
if ( dataCo == 'the-idea' ) {
$.getJSON('update_count.php?section=idea');
}
if ( dataCo == 'the-tech' ) {
$.getJSON('update_count.php?section=tech');
}
if ( dataCo == 'the-result' ) {
$.getJSON('update_count.php?section=result');
}
});