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

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

  • 4 March 2024
  • 5 replies
  • 104 views

Badge +2

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?

icon

Best answer by PhilB 6 March 2024, 21:31

View original

5 replies

Userlevel 7
Badge +21

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 

Badge +2

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.

Userlevel 7
Badge +21

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

Badge +2

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.

Badge +2

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

Leave a Reply