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

Get page URL when using Qualtrics in iFrame?

  • February 27, 2019
  • 9 replies
  • 420 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); ```

9 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • February 27, 2019
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
  • February 28, 2019
@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 ●●●●●●●●
  • February 28, 2019
Put this at the beginning of your survey flow: !

  • Author
  • February 28, 2019
Thanks. I don't see that option: !

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

  • Author
  • February 28, 2019
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 ●●●●●●●●
  • February 28, 2019
> @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
  • February 28, 2019
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.

  • October 7, 2020

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