The stats can only be seen in console and for a split second after pressing weiter n debug shows no info.
Okay, that's probably part of the problem. If I am correct, your Javascript that copies the information into the internal variable, is triggered from leaving the page. That may be too late to send information.
window.addEventListener('beforeunload', function() {
if (currentVisibleVideoId && currentViewStart) {
var elapsed = Date.now() - currentViewStart;
videoStats.viewDurations[currentVisibleVideoId] = (videoStats.viewDurations[currentVisibleVideoId] || 0) + elapsed;
}
updateHiddenInput();
});
Instead do it before the information is sent, by using SoSciTools.questionnaire.attachCheck
for example.
SoSciTools.questionnaire.attachCheck(function() {
if (currentVisibleVideoId && currentViewStart) {
var elapsed = Date.now() - currentViewStart;
videoStats.viewDurations[currentVisibleVideoId] = (videoStats.viewDurations[currentVisibleVideoId] || 0) + elapsed;
}
updateHiddenInput();
return true;
});
Note, that the SoSciTools.questionnaire is only available after the page has loaded. So, you need a bit more code:
window.addEventListener("load", function() {
SoSciTools.questionnaire.attachCheck(function() {
if (currentVisibleVideoId && currentViewStart) {
var elapsed = Date.now() - currentViewStart;
videoStats.viewDurations[currentVisibleVideoId] = (videoStats.viewDurations[currentVisibleVideoId] || 0) + elapsed;
}
updateHiddenInput();
return true;
});
});