In websites/BEN#30 I'm working on replacing my javascript video embeds with standard <video>
tags, allowing them to display in RSS feed readers etc.
However, the JS embed pings analytics to note that a video has been played, so that I can see what's doing well:
function BensVidgatherInfo(vid, state){
var tz = new Date().getTimezoneOffset();
return {
domain : "videos.bentasker.co.uk",
page: "/" + vid.replace(window.BensPD,""),
referrer: document.location.href,
referrer_domain: document.location.hostname,
platform: navigator.platform,
timezone: tz,
sess_id: getSessionId(),
state: state,
responseTime: Date.now() - window.performance.timing.navigationStart
}
}
function submit(info){
var xml = new XMLHttpRequest();
xml.onreadystatechange = function () {}; // Do nothing
// If we're being viewed on a .onion, use the .onion instead
// (keeps everything within the tor network)
var tld = window.location.hostname.toLowerCase();
if (tld.endsWith(".onion")){
xml.open("POST", window.analytics_endpoint_onion + "/write");
} else if (tld.endsWith(".i2p")) {
xml.open("POST", window.analytics_endpoint_i2p + "/write");
} else {
xml.open("POST", window.analytics_endpoint);
}
xml.setRequestHeader("Content-Type", "application/json");
xml.send(JSON.stringify(info));
}
There are two JS events which get logged
PlayerReady
(i.e. initial load time)playing
(i.e. the user has opted to watch the video)I'd like to retain that visibility.
The aim of this ticket is to have PFAnalytics add an event hook to video objects to fire when they're played. Failure to fire obviously should not block playback
Activity
07-Dec-24 10:06
assigned to @btasker
07-Dec-24 10:21
Based on the original implementation, the play counter looks something like this
I don't know if it's actually worth adding a hook for
PlayReady
. The analytics hook should be the last thing to run on most pages, at which point the player should already be ready - it made sense when the embed was being triggered by JS, because the start was also under our control.I guess, though, that the whole point it to catch times when that's not true - if it's not loaded by the time analytics fires, there's almost certainly an issue.
OK, I'll add it and we'll see how it goes. The next step is to transform this into the format used by the agent - we shouldn't actually need to construct an object in the way we have above.
07-Dec-24 10:34
mentioned in commit 6299340ab773e0852848ed37720be728c5fb3b23
Message
feat: add hook to video tags (websites/privacy-sensitive-analytics#23)
07-Dec-24 10:37
I know why
OnPlayerReady
seemed odd to me now - it's VideoJS specific. We actually want thecanplay
event.I think, whilst we're at it, we may want to hook the events indicating playback issues:
07-Dec-24 10:38
mentioned in commit c5f63d24287b3acf5c774b319584b36232155ded
Message
feat: fire event when video is ready to play (websites/privacy-sensitive-analytics#23)
07-Dec-24 10:40
mentioned in commit d8cd475cfc14a0d85335b42695715fc03da601d0
Message
feat: fire event if video playback breaks (websites/privacy-sensitive-analytics#23)
07-Dec-24 10:46
Have just tested, as expected,
canplay
didn't fire because the video had loaded before analytics, but this is fine.07-Dec-24 10:54
mentioned in issue BEN#30