I am aware of the
REST API. However, I would like to forward users to Qualtrics from an ongoing oTree session. After they finished the survey, I would like them to proceed in the same oTree session. Qualtrics should additionally open in the same window, such that the transition is as seamless as possible. I came up with the following solution:
- I create a individualized link for each participant and define the js_var to use it in the template
- In the template, detect whether participant comes from another otree page or whether participant comes from otree. In the first instance, the js code "(
linkOfTheWebsiteUserCame )" is true and the button that forwards to qualtrics is shown. In the second instance, the qualtrics button is hidden and the otree-submit button is shown.
- In qualtrics, I redirect participants back to the survey, by using the same URL than the one they came from.
This works. However, if someone clicks into the URL-line and reloads the "MyPage", the Qualtrics button remains hidden (because ( linkOfTheWebsiteUserCame ) = false).
Is there a better solution? Thanks a lot for your help!
Best,
Felix
Here's my code:
in __init__.py:
class MyPage(Page):
def js_vars(player):
label = player.participant.code
player.link = "https://[...].qualtrics.com/[...]" + "?id=" + str(label)
return dict(
link=player.link,
)
Teamplate:
{{ block scripts }}
<script>
let linkOfTheWebsiteUserCame = document.referrer;
if (linkOfTheWebsiteUserCame ) {
document.getElementById("id_submit_button").style.display = "none";
document.getElementById("qualtrics").style.display = "block";
} else {
document.getElementById("id_submit_button").style.display = "block";
document.getElementById("qualtrics").style.display = "none";
}
</script>
{{ endblock }}
{{ block content }}
<button id="qualtrics" type="button" onclick="window.open(js_vars.link, target='_self');" class="otree-btn-next btn btn-primary next-button otree-next-button" >Go to Qualtrics</button>
<button id="id_submit_button" class="otree-btn-next btn btn-primary next-button otree-next-button" >Next oTree page</button>
{{ endblock }}