Forward to Other URL, Then Proceed in oTree

247 views
Skip to first unread message

Felix Bölingen

unread,
May 17, 2022, 8:18:42 AM5/17/22
to oTree help & discussion
Dear Chris, dear oTree Forum,

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:

  1. I create a individualized link for each participant and define the js_var to use it in the template
  2. 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.
  3. 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 }}

Chris @ oTree

unread,
May 17, 2022, 10:41:45 AM5/17/22
to Felix Bölingen, oTree help & discussion
As soon as the user arrives to the page from Qualtrics, access the referrer and save it in oTree using liveSend. That way even if the user refreshes the page, that link won’t be lost.

Or pass the URL via the participant_vars REST API

Sent from my phone

On May 17, 2022, at 8:18 PM, Felix Bölingen <felix.b...@gmail.com> wrote:

Dear Chris, dear oTree Forum,
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/c166efcf-072b-4cc1-b776-422b47fd7226n%40googlegroups.com.

Felix Bölingen

unread,
May 17, 2022, 10:54:06 AM5/17/22
to oTree help & discussion
Thank you Chris! This is very valuable advice.
Reply all
Reply to author
Forward
0 new messages