When I embed intercom’s code for logged in users into an iframe and pass the user’s data into it, the delay in wix sending the data into it breaks the function. Here is the code
<script>
let data = {}
window.onmessage = (event) => {
data = event.data
console.log(data)
}
console.log(data)
window.intercomSettings = {
app_id: "my app id",
name: event.data.firstName,
email: event.data.email,
created_at: Date.now()
};
</script>
<script>...</script>
When I run the site, i get the error message 'cannot read property “firstName” of undefined.
The first console.log message returns the user object, the second returns undefined.
When I try to set the intercomsettings after the newdata is declared, the iframe returns nothing…
<script>
let data = {}
window.onmessage = (event) => {
return event.data
window.intercomSettings = {
app_id: "rvgf3b4j",
name: event.data.firstName,
email: event.data.email,
created_at: Date.now()
};
}
</script>
Has anybody gotten this to work successfully?