googleanalytics / autotrack

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

How to test it? #189

Closed dennisat closed 7 years ago

dennisat commented 7 years ago

Really nice work... thank you guys.

I am using the maxScrollTracker but I don't know really if this really works. Scrolling the page I don't see any xhr or ws actions in the network monitor. There are no any provided events from this plugin to test when and what this plug in sends to the GA. Any help is appreciated. Thanks.

philipwalton commented 7 years ago

maxScrollTracker only sends hits to GA when the max scroll percentage increases per page per session. If you're not seeing any data sent, it could be that you've already scrolled to the bottom of the page you're looking at this session.

Try opening up the page in an incognito window and watching the network tab. You can also use the debug version of analytics.js, as it's generally useful in seeing what's going on in development.

Lastly, since you asked about hooks, you should look into the hitFilter option. You can set a breakpoint there to inspect the hit model prior to the hit being sent.

Try something like this:


ga('require', 'maxScrollTracker', {
  sessionTimeout: 30, // Use your session timeout (default is 30 minutes)
  timeZone: 'America/Los_Angeles', // Use your time zone
  maxScrollMetricIndex: 1, // Use your custom metric index
  hitFilter: function(model) {
    console.log(model.get('hitPayload'));
    debugger;
  },
});
``
dennisat commented 7 years ago

awesome, thanks!