mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
886 stars 312 forks source link

Mixpanel still dropping a cookie even though `opt_out_tracking_by_default` set to true #324

Open crevulus opened 2 years ago

crevulus commented 2 years ago

I have a React application that triggers the init function on mount:

const mixpanelInitOptions = {
  token:
    process.env.NODE_ENV === Environments.Prod
      ? process.env.REACT_APP_MP_PROD_PROJECT_TOKEN
      : process.env.REACT_APP_MP_DEV_PROJECT_TOKEN,
  options: {
    debug: process.env.NODE_ENV === Environments.Dev,
    opt_out_tracking_by_default: true,
    api_host: "https://api-eu.mixpanel.com",
  },
};

useEffect(() => {
    mixpanel.init(mixpanelInitOptions.token!, mixpanelInitOptions.options);
  }, []);

I'm trying to be GDPR-compliant, so as you can see I'm opting out by default. A cookie acceptance banner triggers the opt in user event:

const handleAccept = () => {
    handleAddBooleanToLocalStorage(LocalStorageKeys.Cookies, true);
    mixpanel.opt_in_tracking();
  };

However, I notice that mixpanel is dropping a cookie and a localStorage value on page load - before the opt in function is called.

The localStorage value is simply an opt/in out flag with a number to serve as a boolean. The cookie, however, contains some client data like device id, initial referrer etc.

I'm worried about this, as it may not be GDPR-compliant. Ideally no cookies should be dropped until the user has consented.

Does anyone know why this cookie is dropped? Is it needed and is there a way to prevent it? I was under the impression that opting out by default = 0 cookies.

DanielBrito21 commented 2 years ago

Hi, I am facing the same problem. Have you find any solution?