Hi @JBATX
UpdatePageActivity
isn’t designed to manually send page pings, it exists to update the time the tracker last logged activity of the user. This is important as Page Pings only fire if the user is active on the page (scrolling, mouse movement, etc.) so for content where the user is inactive (playing a video), you will want to fire UpdatePageActivity
calls to tell the tracker that the user is still active and it should send page pings when the next heart beat occurs.
Activity Tracking works by checking for activity within each heartbeat, so if the heartbeat is set to 10 seconds then there must have been some activity on the page in the last 10 seconds for the page ping event to be sent.
If you wish to send Page Pings manually, this is a little tricky! Currently, sending a Page Ping event isn’t part of the public API of the tracker.
You could perhaps mimic this by sending a custom page ping as a self describing event and then deal with your custom page ping event as data modelling step. Getting the values out of the tracker to be able to do this will require you to use the new Activity Tracking callback function (in 2.13.0).
I’m curious what your use case is for sending a manual page ping and how you intend to deal with this when modelling it with the “standard” page pings? You’d end up with unevenly spaced page ping events, which is a much harder to deal with and infer activity from.
I hope this example might help you instrument what you are after, if you want to try the custom page ping idea:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" async=1>
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","sp.js","snowplow"));
</script>
<script>
window.snowplow('newTracker', 'sp', '<<collector_url>>', {
appId: 'activity-test',
eventMethod: 'post',
contexts: {
webPage: true
}
});
var aggregatedEvent = {
pageViewId: null,
minXOffset: 0,
maxXOffset: 0,
minYOffset: 0,
maxYOffset: 0,
numEvents: 0
};
window.snowplow('enableActivityTrackingCallback', 10, 10, function () {
aggregatedEvent = {
pageViewId: event.pageViewId,
minXOffset: aggregatedEvent.minXOffset < event.minXOffset ? aggregatedEvent.minXOffset : event.minXOffset,
maxXOffset: aggregatedEvent.maxXOffset > event.maxXOffset ? aggregatedEvent.maxXOffset : event.maxXOffset,
minYOffset: aggregatedEvent.minYOffset < event.minYOffset ? aggregatedEvent.minYOffset : event.minYOffset,
maxYOffset: aggregatedEvent.maxYOffset > event.maxYOffset ? aggregatedEvent.maxYOffset : event.maxYOffset,
numEvents: aggregatedEvent.numEvents + 1
};
});
window.snowplow('trackPageView');
function sendPagePing() {
//Send whatever custom event you wish when you need your "custom" page ping.
window.snowplow('trackSelfDescribingEvent', {
schema: 'iglu:com.acme_company/page_ping/jsonschema/1-0-0',
data: {
minXOffset: aggregatedEvent.minXOffset,
maxXOffset: aggregatedEvent.maxXOffset,
minYOffset: aggregatedEvent.minYOffset,
maxYOffset: aggregatedEvent.maxYOffset,
activeSeconds: aggregatedEvent.numEvents * 10
}
});
}
</script>
<body>
<input type="button" onclick="sendPagePing()" value="Send Page Ping" />
<img src="http://via.placeholder.com/1000x1000.png?text=Scroll" /><br/>
<img src="http://via.placeholder.com/1000x1000.png?text=for" /><br/>
<img src="http://via.placeholder.com/1000x1000.png?text=activity" /><br/>
<img src="http://via.placeholder.com/1000x1000.png?text=tracking" /><br/>
</body>
</html>