addEventListener being overridden in Customer Events, and breaking some tracking scripts

addEventListener being overridden in Customer Events, and breaking some tracking scripts

SGSdev
Shopify Partner
18 2 7

I've noticed that with certain scripts added to Customer Events - Custom Pixels (in my case an Amazon AWS script), the execution will fail and I will see this error in the console: "In a sandboxed environment, addEventListener may not behave as expected.". It looks like the native addEventListener function has been overridden by a custom Shopify function that displays this error message. I understand that people shouldn't be trying to add event listeners to the DOM in a sandbox environment, but sometimes addEventListener is used for XHR requests and other things related to data transmission. I'd like to request that Shopify update this so that a warning message is displayed without actually breaking the functionality of addEventListener, so that it doesn't disrupt data tracking. Thanks.

Screen Shot 2024-02-15 at 3.56.40 PM.png

Replies 2 (2)

Liam
Community Manager
3108 341 879

Hi SGSdev,

 

What exact component is the event listener being added to? If it's on a checkout that is using checkout extensibility then `addEventListener` will not work as these functions are intentionally limited to ensure the checkout remains secure. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Zakaria
Shopify Partner
15 0 6

I am running into the same issue on mobile when doing this: `window.addEventListener("load", () => {})` in a web component injected by a theme app extension. On desktop everything seems to be working fine though.

Beehive Apps Founder - Currently building Bundle Bee, the best quantity breaks, free gifts and bundles app.