googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.92k stars 560 forks source link

Is this the way to implement stepped scroll tracking? #252

Open Jogai opened 4 years ago

Jogai commented 4 years ago

What I want is to send only one event per range. So if I divide my page in quarters I send an event for 25, 50, 75 and 100%.

A user that scrolls to 33%, then to 44%, then back to 36% would once send an event with 25 as eventLabel.

Sorry I was rubber ducking, I think this should work:


    ga('require', 'maxScrollTracker', {
            increaseThreshold: 25,
            hitFilter: function(model) {
                var scrollPercentage = model.get('eventLabel');
                // round to 25's
                model.set('eventLabel', 25 * Math.round(scrollPercentage / 25), true);
            }
        });