Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding countdown to Prolific redirect after trial completion if Prolific completion code is populated as env var #45

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions template/experiment-ui/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
* This is the end page that is shown after the experiment
*/
function endPage() {
let link = ''
if (process.env.REACT_APP_redirect !== '') {
link = `<a href="${process.env.REACT_APP_redirect}">Back to prolific</a>`
let link = '';
let atag = '';
let interval;
// the value compared below is hardcoded in the .env file produced by Copier
// if you modify the value in the .env file or your env vars to a completion code provided by Prolific
// a link will be presented to users that redirects to Prolific with the completion code populating
// a query string parameter
if (process.env.NODE_APP_completionCode !== 'ABCD1234') {
link = 'https://app.prolific.com/submission/complete?cc=${process.env.NODE_APP_completionCode}';
let countdown = 5;
atag = `<a href=>Click here to redirect to Prolific.</a> You will be redirected automatically in <span id="countdown">${countdown}</span> seconds...`;
interval = setInterval(() => {
countdown -= 1;
document.getElementById('countdown').innerText = countdown;
}, 1000);

setTimeout(() => {
clearInterval(interval);
window.location.href = link;
}, 5000);
}
let html = `<div class="msg">Thank you for participating in our experiment.<br/>${link}</div>`
let html = `<div class="msg">Thank you for participating in our experiment.<br/>${atag}</div>`;

document.body.innerHTML = html
document.body.innerHTML = html;
}

function waitPage() {
Expand Down