Skip to content

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

Open
@nazarHnatyuk

Description

@nazarHnatyuk

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions