Get page URL when using Qualtrics in iFrame? | XM Community
Solved

Get page URL when using Qualtrics in iFrame?

  • 27 February 2019
  • 9 replies
  • 142 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?
icon

Best answer by TomG 27 February 2019, 18:41

View original

9 replies

Userlevel 7
Badge +27
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);
```
@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?
Userlevel 7
Badge +27
Put this at the beginning of your survey flow:
!
Thanks. I don't see that option:

!
Userlevel 7
Badge +27
@ab> @aberry3 said:
> Thanks. I don't see that option:
>
Type the name "parentUrl"
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?
😕
Userlevel 7
Badge +27
> @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.
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.

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

Leave a Reply