Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Shopify's web pixel not loading base pixel code

Shopify's web pixel not loading base pixel code

yash100ni
Shopify Partner
10 0 10

Shopify has recently mandated that pixel apps use the new Web Pixel App Extension, which has some notable shortcomings. The Shopify Web Pixel operates within a strict sandbox environment, meaning it does not have access to the global window and document objects.

This presents a challenge for pixels like Facebook and TikTok, which require their base code to be loaded. These libraries need access to the global window and document objects to function correctly. Unfortunately, this does not appear to be possible within the strict sandbox environment enforced by Shopify.

Facebook base code example

 

 

 

 

 

 

 

 

 

 !function (f, b, e, v, n, t, s) {if (f.fbq) return; n = f.fbq = function () {n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments)}; if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0; t.src=v; s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s)}(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');

 

 

 

 

 

From this above code we get window is not defined in strict sandbox environment. 

Replies 4 (4)

Enkhbaatar
Shopify Partner
1 0 1

I have same issue for GTM. Is there any update?

yash100ni
Shopify Partner
10 0 10

No reply yet from anyone.

BaoJay
Shopify Partner
5 1 0

I'm having the same issue when applying the Meta pixel base code from Facebook to web pixel shopify. The issue is that shopify web pixel is running on strict environment so that we couldn't define fbq function to the web pixel. 
If anyone has the solution it will be great! 

I'm a passionate Shopify Theme Developer, weaving seamless and stunning digital experiences for e-commerce ventures.
yash100ni
Shopify Partner
10 0 10

The solution I found is to avoid using pixel-based libraries and instead directly call tracking APIs with the appropriate parameters. You can view the details of these API requests in the Network tab of your browser's developer tools.