mixpanel / mixpanel-js

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

Clarification on opt_in_tracking() #185

Open mottalrd opened 6 years ago

mottalrd commented 6 years ago

Hello,

I am looking at the documentation of opt_in_tracking() https://mixpanel.com/help/reference/javascript-full-api-reference#mixpanel.opt_in_tracking

Could you clarify to me if the opt_in is enabled or disabled by default? What consequence does it have on what Mixpanel tracks or not?

In the application I am working on even though I see events getting sent to Mixpanel, I do often see the DISTINCT ID changing when I go to a different page and I was wondering if having opted in or not could be related to that.

Thank you

evnp commented 6 years ago

Hey, thanks for writing in. This could probably be more clear in our documentation. The default state of the SDK instance is neither opted-in or opted-out, and no behavior of the SDK will be restricted until an opt_out_tracking call is made. opt_in_tracking simply reverses opt-out and tracks an event that can be used as a record of opt-in.

Each of opt_in_tracking opt_out_tracking sets a flag (as a cookie or localStorage entry) that marks the current user as opted in or out. If you inspect your application storage in browser devtools you'll see this flag as __mp_opt_in_out_<PROJECT_TOKEN> equal to 1 (opted-in) or 0 (opted-out). This flag is not set when the SDK is initialized, so the initial state is neither opted-in or opted-out.

The exception to this would be if you pass opt_out_tracking_by_default: true during SDK init - then an opt_out_tracking call will be made internally during init and set the opt-out flag before any data is tracked. This is documented here https://mixpanel.com/help/reference/javascript#privacy

mottalrd commented 6 years ago

thank you @evnp ! Clear now