Dear community,
Qualtrics-newie here. Within my Qualtrics survey, I included a game for which I want to count the number of times the spacebar is pushed. For some reason , I never manage to get the actual number in the data output. Do you have any idea what I can do to make this work?
This is the Java Code I use in the survey, as well as the survey flow:
Code:
Qualtrics.SurveyEngine.addOnReady(function() {
    var spacebarCount = 0;
    // Funktion zum Zählen der Leertastenanschläge
    function keydownHandler(event) {
        var code = event.code || event.keyCode;
        if (code === 'Space' || code === 32 || event.key === ' ') {
            spacebarCount++;
        }
    }
    // Event-Listener hinzufügen
    document.addEventListener('keydown', keydownHandler);
    // Speichere die Leertastenanschläge beim Verlassen der Seite
    this.addOnPageSubmit(function() {
        Qualtrics.SurveyEngine.setEmbeddedData("SpacebarClicks", spacebarCount);
    });
    // Event-Listener entfernen beim Entladen der Seite
    this.addOnUnload(function() {
        document.removeEventListener('keydown', keydownHandler);
    });
});
Survey Flow:



