Track how far down your site's homepage visitors scroll
This file contains 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
// This code assumes that each section of your homepage uses a "section" tag | |
// and each one has an id corresponding to its purpose: "testimonials", "pricing", etc | |
( function() { | |
var viewedSections = []; | |
$( window ).on( 'scroll', function() { | |
$( 'section' ).each( function() { | |
var sectionName = $( this ).attr( 'id' ); | |
var distanceToTopOfViewport = this.getBoundingClientRect().top; | |
if ( sectionName && distanceToTopOfViewport < 600 ) { | |
var hasAlreadyBeenTracked = viewedSections.indexOf( sectionName ) !== -1; | |
if ( ! hasAlreadyBeenTracked ) { | |
viewedSections.push( sectionName ); | |
analytics.record( 'Viewed Homepage Section', { | |
name: sectionName | |
} ); | |
} | |
} | |
} ); | |
} ); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment