Hello everyone!
I've inherited a survey that has some custom JS meant to capture respondent timezone, but it works inconsistently and doesn't capture it for everyone. I know next to nothing about JS, and was wondering if anyone can see where the issue might lie:
// Capturing respondent's time zone
Qualtrics.SurveyEngine.addOnReady(function()
{
waitForElement();
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
});
function waitForElement(){
if(typeof moment !== "undefined"){
setEmbeddedTimezone("timezone", "timezone_abbrev");
}
else{
setTimeout(waitForElement, 250);
}
}
function setEmbeddedTimezone(tzEmbed, abrEmbed){
try{
if ((tzEmbed === null || tzEmbed === undefined) || (abrEmbed === null || abrEmbed === undefined)){
console.log("No Embedded Data fields provided.")
return;
}
var timezone = moment.tz.guess();
if (timezone === null || timezone === undefined){
console.log("Unable to retrieve timezone");
return;
}
Qualtrics.SurveyEngine.setEmbeddedData(tzEmbed, timezone);
var date = new Date();
var timestamp = date.getTime();
var abbr = moment.tz.zone(timezone).abbr(timestamp);
Qualtrics.SurveyEngine.setEmbeddedData(abrEmbed, abbr);
}
catch(e){
console.log(e);
}
}
Best answer by bgooldfed
View original