Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixpanel.identify() works even when it is turned off. #423

Open
nazarHnatyuk opened this issue Apr 1, 2024 · 1 comment
Open

mixpanel.identify() works even when it is turned off. #423

nazarHnatyuk opened this issue Apr 1, 2024 · 1 comment

Comments

@nazarHnatyuk
Copy link

nazarHnatyuk commented Apr 1, 2024

Hello everyone, I encountered such a problem: mixpanel.identify(); works even when shouldEnableMixpanel = false. What could be the problem?

import mixpanel from "mixpanel-browser";

classMixpanelTracker {
  constructor(shouldEnableMixpanel = false) {
    this.shouldEnableMixpanel = shouldEnableMixpanel && !window.location.host.includes('localhost');
}
 
  initialize() {
    if (this.shouldEnableMixpanel) {
      mixpanel.init(MIXPANEL_API_TOKEN, { track_pageview: false });
      mixpanel.identify();
    }
    else {
      console.log(`Mixpanel identifying is disabled or in localhost.`);
    }
  }
 
  logEvent(eventName, eventParams) {
    if (this.shouldEnableMixpanel) {
      try {
        mixpanel.track(eventName, eventParams);
      } catch (error) {
        console.error(error);
      }
    } else {
      console.log(`Mixpanel tracking is disabled or in localhost.`);
    }
  }
 
  logUserProperty(property, value) {
    if (this.shouldEnableMixpanel) {
      try {
        mixpanel.people.set({ [property]: value });
      } catch (error) {
        console.error(error);
      }
    } else {
      console.log(`Mixpanel tracking is disabled or in localhost.`);
      }
    }
}
 
export default MixpanelTracker;
@doc-han
Copy link

doc-han commented Apr 18, 2024

mixpanel.identify() is not bound by the class you've written. Hence, to enforce that restriction you need a method in this class that will be called whenever you want to identify. And that will enforce your restriction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants