Question

Unable to use track API due to CORS error

  • 10 June 2020
  • 1 reply
  • 644 views

  • New Participant
  • 0 replies

My website has been created using Flutter and is hosted in a subdomain (e.g. web.domain.co.uk/#/page) and on my frontend I am calling the track endpoint to send data to Mixpanel, unfortunately I get a CORS error like the following:

Access to fetch at 'https://api.mixpanel.com/track/?data=[...]' from origin 'https://web.domain.co.uk' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.

 

I checked the following support pages 

https://help.mixpanel.com/hc/en-us/articles/115004511086-CORS-errors

https://help.mixpanel.com/hc/en-us/articles/115004507486-Track-Across-Hosted-Subdomains

 

But none helped, how can I fix this problem?

 


1 reply

Userlevel 5
Badge +3

@luca

 

By chance are you using Firefox to viewing your website when you see the CORS error? Late last year, Firefox started blocking all third party tracking services by default. You can see this in the Firefox security settings:
?name=Slack+%7C+support+%7C+Mixpanel+2020-06-18+15-43-23.png

It is definitely unfortunate that Firefox's new privacy features can block Mixpanel from tracking user activity. Currently, I believe the only way we can work around that is to proxy the tracked data to an internal domain before sending it to Mixpanel. You can do that either through using a server-side implementation or you can use our client-side library to proxy the calls to your own server first before sending the data to Mixpanel using the following code snippet:
mixpanel.init("YOUR TOKEN", { api_host: "api.mydomain.com" });​. You can read more on this in the following article: Ad Blockers Affect Mixpanel.

We are actively working with disconnect.me to be removed from their tracking protection services repository. Firefox uses Disconnect.me's repo to identify what type of tracking info to block. If we are able to be removed from that repo we will be able to continue to track user activity, regarding those users using Firefox, without needing to proxy that data to an internal domain first. 

 

Cherise

Reply


Mixpanel