Customer Events Pixel Access-Control-Allow-Origin Error

mthdvd
Shopify Partner
24 0 7

Can anyone explain to me why I cannot seem to use a custom, customer events pixel to post data to an externally hosted server?

I have a simple script intended to post data to an external server:

 

analytics.subscribe('product_viewed', (event) => {
  const product_data = {
    attribute_one: “xxxxxxx”,
    attribute_two: “xxxxxxx”,
    data: event.data
  };
  fetch('https://mysecureendpoint.com/product_views, {     method: 'POST',     headers: {       'Content-Type': 'application/json'     },     body: JSON.stringify(product_data),     keepalive: false,   }) …. });


But I consistently get errors like:

 

Access to fetch at 'https://mysecureendpoint.com/product_views' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

If I make the same exact call outside of the customer events section, the request is successful and I receive no errors. No issues.

I'm using the same data, the same server & configurations, the same endpoint. The only difference is where the call takes place i.e. inside the customer events section vs directly on the product.liquid file.

This seems like a pretty obvious use case for the customer events utility. The external server, of course, is hosted on a different domain than the shopify store but is this intended behavior? What am I missing?

 

Thanks for any help!

Replies 5 (5)

kbarber
Shopify Partner
2 0 2

Following

ecbLR
Tourist
9 0 1

I suspect our team is likely to run across this as we migrate our checkout.liquid pixels to extensibility. Also following. 

Bob-9x
Shopify Partner
1 0 0

Hi. I also posted the same problem. Can only be called for 3rd party url. It doesn't work for url stores. Is there any way to resolve it?

ecbLR
Tourist
9 0 1

@Bob-9x do you have a link to your post? Would like to subscribe.

 

ecbLR
Tourist
9 0 1

Bumping this as we have indeed run into this issue.