Window.ShopifyAnalytics in sandbox iframe

Window.ShopifyAnalytics in sandbox iframe

Dani2510
Visitor
2 0 0

We have been trying to setup a function such as below on a Sandbox pixel page that tracks Checkout and thank you. There is no one publicly available link that states that clearly and I just wanted to know  for a Checkout and thank you Sandbox will this work?

function(){
var meta = window.ShopifyAnalytics && ShopifyAnalytics.meta;
if (meta && meta.page && meta.page.pageType) {
return meta.page.pageType;
}
var path = window.location.pathname || '';
if (path.indexOf('/checkouts/') === 0) {
return path.indexOf('/thank-you') > -1 ? 'thank_you' : 'checkout';
}
return 'storefront';
}

 

There is no single publicly available link that explicitly states:

“Inside Shopify’s sandbox iframe for web pixels, the global window.ShopifyAnalytics and its property ShopifyAnalytics.meta are available.”

Replies 2 (2)

Ugurcan
Shopify Partner
351 7 34

If you are referring to sandbox in Pixels API, the window element is not available in sandbox environment so you cannot use this code, 

Pasilobus | eCommerce Experts, Shopify Apps & Development since 2015 -- www.pasilobus.com

Dani2510
Visitor
2 0 0

So What would be a better way to Track Sandboxes Page type in Shopify
I did run a sample JS and gave me this
So this wont happen inside a Sandbox Thank you or checkout page ?