prijatelilab / PrijateliTree

A FastAPI application used to play lab games and collect survey data.
MIT License
1 stars 0 forks source link

Link from platform to Qualtrics for survey #80

Closed anisfeld closed 9 months ago

anisfeld commented 9 months ago

What Issue Are You Seeing or What Feature Needs To Be Added?

Are There Any Links That Would Be Helpful?

anisfeld commented 9 months ago

~The iframe idea ran into a snag. For some reason, I can't see anything inside the iframe!!~

Update: If using ghostery or similar tracker blockers Qualtrics will fail to load in an iframe. Hopefully, they school laptops aren't running something like this.

Screenshot 2023-12-07 at 11 28 53 PM
anisfeld commented 9 months ago

It's tricky to get back to the platform from the iframe. Ideally, we have some information pass from qualtrics / iframe telling the webpage to close the iframe.

https://community.qualtrics.com/custom-code-12/embedded-survey-is-there-a-way-to-detect-end-of-survey-13654

This post says we can pass a message back to the platform using parent.postMessage() (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). Trying to figure this out. Current idea is when the "End of Survey" message is passed we

anisfeld commented 9 months ago

hat tip: https://javascriptbit.com/transfer-data-between-parent-window-and-iframe-postmessage-api/

Inside the html with the iframe.

{% block helper_script %}
<script>

window.addEventListener("message", receiveMessage, false);

function receiveMessage(event) {
  if(event.data.includes("End of Survey")){
      console.log("We're getting information across iframe")
      window.location.href = "/games/{{game_id}}/player/{{player_id}}/round"
  }
}
</script>
{% endblock helper_script %}

JavaScript on the Qualtrics side--afaik can be in any question on the last page of the survey. Try to keep it on the last question.

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/
    parent.postMessage("End of Survey", "*");
});
anisfeld commented 9 months ago

Superceded by #95 and #96