Get page URL when using Qualtrics in iFrame? | Experience Community
Skip to main content
Solved

Get page URL when using Qualtrics in iFrame?

  • Feb 27, 2019 4:14 PM UTC
  • 9 replies
  • 482 views

I am including a Qualtrics survey in an iFrame on an external page, as in this question, which seems to work great. I'd like to collect the URL for the page the iFrame appears on, however. Is this possible? My current idea: can I populate a hidden question/answer with JavaScript?

Best answer by TomG

You can use an embedded variable (initialize the variable in survey flow). Try this JS (untested): ``` var parentUrl = (parent != window) ? document.referrer : ""; Qualtrics.SurveyEngine.setEmbeddedData("parentUrl", parentUrl); ```
View original

9 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • Feb 27, 2019 5:41 PM UTC
You can use an embedded variable (initialize the variable in survey flow). Try this JS (untested): ``` var parentUrl = (parent != window) ? document.referrer : ""; Qualtrics.SurveyEngine.setEmbeddedData("parentUrl", parentUrl); ```

  • Author
  • Feb 28, 2019 6:21 PM UTC
@TomG, sorry for being dense, but I can't seem to figure out how to add an "embedded variable" in the Survey Flow. I can create an "Embedded Data" element; the most similar fields I see are "ExternalDataReference", which doesn't seem to do anything, and "Q_URL", which seems to get the Qualtrics URL itself. I don't see anyplace where I can inject JavaScript?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Feb 28, 2019 6:30 PM UTC
Put this at the beginning of your survey flow: !

  • Author
  • Feb 28, 2019 8:02 PM UTC
Thanks. I don't see that option: !

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Feb 28, 2019 8:06 PM UTC
@ab> @aberry3 said: > Thanks. I don't see that option: > Type the name "parentUrl"

  • Author
  • Feb 28, 2019 8:13 PM UTC
lol, well slap me with a hammer. Done and published. I'm not seeing any additional data appear in my "Data & Analysis" tab, though, after taking a test submission. Am I still missing something? :/

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Feb 28, 2019 8:16 PM UTC
> @aberry3 said: > lol, well slap me with a hammer. Done and published. > > I'm not seeing any additional data appear in my "Data & Analysis" tab, though, after taking a test submission. Am I still missing something? > :/ parentUrl should be blank unless it is in an iframe.

  • Author
  • Feb 28, 2019 8:43 PM UTC
OK, I figured it out. Thanks for all your help @TomG. Besides my other confusion, I didn't know you can add JavaScript to a question. ! I used TomG's JS, which was perfect. Then I had to add the "Embedded Data" thing in Survey Flow, set to "parentUrl". Works good now. Thanks.

  • Oct 7, 2020 3:05 PM UTC

I've done my best to follow these instructions...added parentUrl to the ED list:
Screen Shot 2020-10-07 at 9.19.49 AM.pngand then added the suggested JS to one of the questions:
Qualtrics.SurveyEngine.addOnReady(function(){
var parentUrl = (parent != window) ? document.referrer : "";
Qualtrics.SurveyEngine.setEmbeddedData("parentUrl", parentUrl);
});
and I can see the results in the "Reporting" tool -but sometimes it's only the root of the URL. 2nd one is an actual customer, 1st one is me going to same URL trying to test it. WHY is this?
Screen Shot 2020-10-07 at 4.35.01 PM.png