How do you access localStorage values as embedded data? They always return null. | XM Community
Skip to main content
Solved

How do you access localStorage values as embedded data? They always return null.


Forum|alt.badge.img+2
  • Level 1 ●
  • 7 replies

I have a Website/App Insights with a Feedback button Intercept/Creative. Under Embedded Data I have Use Value from Javascript  with the following value:

window.localStorage.getItem("1")

This line works when I run it in the browser console.

However, this is reported as null in the Results of the Survey. Is this a scope issue, or is there another way to get Local Storage as Embedded Data?

Best answer by PhilB

I had to use window.postMessage to communicate between the site and the iframe (Qualtrics component) to pass the local storage variable.

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

View original

6 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • March 5, 2024

Embedded data is not local storage, you’ll need to take data from local storage and save them as embedded data. 

Please refer to this for storing ED: https://api.qualtrics.com/82bd4d5c331f1-qualtrics-java-script-question-api-class 


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 7 replies
  • March 5, 2024

Thanks Ahmed, but I already know they are not the same and I have already tried the technique that you are suggesting. Local Storage is returned as null from any component within the Qualtrics. I am thinking this is probably a scope problem on account of the iframe.


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • March 5, 2024

Okay. If you are trying to access local storage set by some other document then it isn’t possible. Local storage is scoped to that specific page.

Details: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 7 replies
  • March 5, 2024

Thanks for the help! In my original post I mentioned that this is a Website/App Insights Feedback button intercept. This component is inherently only used in other sites.


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 7 replies
  • Answer
  • March 6, 2024

I had to use window.postMessage to communicate between the site and the iframe (Qualtrics component) to pass the local storage variable.

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage


Adam_Jermain
Level 2 ●●
Forum|alt.badge.img+4
  • Level 2 ●●
  • 9 replies
  • January 17, 2025
PhilB wrote:

I had to use window.postMessage to communicate between the site and the iframe (Qualtrics component) to pass the local storage variable.

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

 

Hi Phil -  can you explain in more detail what the syntax of this looks like? I’m having the same issue, but can’t seem to get postMessage to work either.


Leave a Reply