How and when does the Javascript tracker send page pings?

A user recently asked us to clarify exactly when the Snowplow JavaScript Tracker sends page pings.

The Tracker uses event handlers to determine whether the user is browsing actively. You can see a list of the listeners here.

The Snowplow JavaScript Tracker can be configured to send page ping events at a regular rate like this:

snowplow_name_here('enableActivityTracking', 30, 10);

If the Tracker is configured this way, it will first wait for 30 seconds before sending any page pings. After that, every 10 seconds it will decide whether to fire a page ping event based on whether any of those activity handlers have been triggered.

1 Like

Thanks for the description Fred.

Now how do you analyse the results? It’s gonna be a big gnarly query to count through all of those and work out an aggregate Time Spent metric on a particular page…

I’ll be posting a recipe soon on how to calculate time spent using page pings. Stay tuned! :slight_smile:

@christophe didi you get the time spent done? :slight_smile:

Hi @mjensen,

Not really a recipe, but our web model calculates time spent this way: https://github.com/snowplow/web-data-model/blob/master/redshift/sql/01-page-views/02-events-time.sql#L34

Hope that helps!

1 Like

@christophe yes thanks

1 Like

Here’s an approach you can start with, using page pings that start after 5 seconds and go every 5 seconds:

  app_id,
  page_urlpath,
  COUNT(event = 'page_view' OR NULL) AS page_views,
  (COUNT(event = 'page_view' OR NULL) * 5) + (COUNT(event = 'page_ping' OR NULL) * 5) AS time_spent,
  (COUNT(event = 'page_view' OR NULL) * 5) + (COUNT(event = 'page_ping' OR NULL) * 5) / NULLIF(COUNT(event = 'page_view' OR NULL),0) AS apd
FROM atomic.events
GROUP BY
  app_id,
  page_urlpath
ORDER BY page_views DESC