Hi all,
I'm trying to implement geofencing logic in my Qualtrics survey using JavaScript to restrict access to users within a 1-mile radius of a specific location. Here's what I'm trying to achieve:
-
Prompt the respondent for location access
-
Calculate the distance from a fixed latitude/longitude
-
If the respondent is outside the radius or blocks location access, they should be redirected to an external SharePoint page
-
If they are within the radius, the survey continues as normal
Here's what I've done so far:
-
Added a Descriptive Text question at the start of the survey
-
Placed the geolocation JavaScript in that question’s JavaScript editor
-
The script uses
navigator.geolocation.getCurrentPosition
, calculates distance, and sets embedded data -
I’ve tried both branch logic in the Survey Flow and full redirect via
window.location.href
The issue:
The JavaScript seems to run (alerts appear), but the redirect does not consistently work, and sometimes the survey still continues even when the user is outside the radius or blocks location. I've tested this with page breaks and minimal Survey Flow setup, and I’ve hidden the Next button until the location is verified.
I’d love help with:
-
Ensuring the redirect reliably triggers when outside the radius or on blocked location
-
Understanding if there’s a better approach within Qualtrics
-
Any limitations I should know about when using JavaScript this way
Any working examples or guidance would be really appreciated!
Thanks so much in advance,