analytics.publish is not a function inside Web Pixel Lax Sandbox

I am trying to call a custom event from inside my Web Pixel, like this:

analytics.subscribe("custom_event", (event) => {
  // Handle custom event
});

analytics.subscribe("product_added_to_cart", async (event) => {
  const {
    data: { checkout },
  } = event;
  // Forward data to custom event
  analytics.publish("custom_event", checkout);
});

This fails with analytics.publish is not a function. However, according to the Shopify docs, this is the correct way to call a custom event.

Is this a bug? (Note that Shopify is also undefined in the sandbox iframe)

@zz3

i was try to reproduce the error does show me the error.

import { register } from "@shopify/web-pixels-extension";
register(({ configuration, analytics, init, browser}) => {
console.log('App pixel ');
analytics.subscribe('page_viewed', (event) => {
console.log('Page viewed', event);
});
// Shopify.analytics.publish(event_name, event_data);
analytics.publish("custom_event", checkout);

console.log('No Error - App pixel ');
});

@zz3 can you please share your .toml file config

Hi, i think Zz3 is referring to the custom pixel sandbox and not the app web pixel.