What is the best way to limit time frame when use anonymous survey link? | XM Community
Question

What is the best way to limit time frame when use anonymous survey link?

  • 12 March 2024
  • 6 replies
  • 58 views

Badge +1

Hi,

 

We plan to send the survey every 3 months to 100 participants. However, we want the survey to be accessible only during specific time frames. For instance, participants may only complete the survey between March 1st and March 31st.

 

The challenge is that all 100 participants will be enrolled at different times, resulting in varying availability periods for each of them.

 

For example, participant A enrolls on January 1st. So, their survey window period would be between March 1-31. Participant B enrolls on February 1st. So, So, their survey window period would be between April 1-30. Participant C enrolls on February 15th. So, their survey window period would be between April 15 to May 15. And so on. 

 

What would be the best way to implement this using the same anonymous link for all 100 participants

 

P.S. we do not plan on using unique survey link as some participants may not have reliable email and phone number. 

 

Thank you! 


6 replies

Userlevel 5
Badge +11

You need to create 2 embedded variable.

Enrolment date: “EnrollmentDate”

Text set variable: “surveyAccessible” Answer codes “true” and “false”

 

Paste this in first question. It can be a text info question.

Qualtrics.SurveyEngine.addOnload(function() {

/* Place your JavaScript here to run when the page loads */

var enrollmentDate = "${e://Field/EnrollmentDate}"; // Replace with the actual embedded data for enrollment date
var currentDate = new Date();

var enrollmentDateObj = new Date(enrollmentDate);

// Calculate the start and end dates of the survey window period based on enrollment date
var surveyStartDate = new Date(enrollmentDateObj);
surveyStartDate.setMonth(surveyStartDate.getMonth() + 2); // Start survey window 2 months after enrollment
surveyStartDate.setDate(1); // Set the start date to the 1st day of the month

var surveyEndDate = new Date(surveyStartDate);
surveyEndDate.setMonth(surveyEndDate.getMonth() + 1); // End survey window 1 month after the start date
surveyEndDate.setDate(0); // Set the end date to the last day of the month

// Check if the current date falls within the survey window period
if (currentDate >= surveyStartDate && currentDate <= surveyEndDate) {
Qualtrics.SurveyEngine.setEmbeddedData("surveyAccessible", "true");
} else {
Qualtrics.SurveyEngine.setEmbeddedData("surveyAccessible", "false");
}
});

 

Now you can screen out condition based on the variable “surveyAccessible”

Badge +1

Thank you! 

 

Follow-up question is how exactly should I implement this? 

What I am trying to do is that if this embedded variable (in this case, surveyAccessible) you created is false, I want them out of the survey.

Here, I have the branch set up but I am not sure what would be the condition of the branch. 

 

Thank you again!

 

 

Badge +1

@praveengeorgeix 

Userlevel 5
Badge +11

I hope you didn the below step of adding embedded data. Set the type from options as text set

 

and set as below.

you need to type in false. its case sensitive

Badge +1

@praveengeorgeix Thank you! 

 

One last question, what would be the JavaScript code that would determine survey accessible for let’s say 6 months after the enrollment date? 

For example, if the current date is in between 3 months period, then surveyAccessible will equal 3 (instead of false in this case). If the current date is in between 6 months period, then surveyAccessible will equal 6. And so on. 

 

I am just trying to see if I can modify your code to further assess the other time period when the survey should become available. Or if you have other suggestions, I am all ears! 

 

Thank you again! 

Badge

Thank you for this thread! I’m looking to do something similar on the time-span of weeks instead of months (e.g., open for 2 weeks after completing survey 1, closing 4 weeks after completing survey 1). How might I change the code accordingly? 

Leave a Reply