mixpanel / mixpanel-js

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

init loaded callback not always called. #394

Open arenoir opened 8 months ago

arenoir commented 8 months ago

What would cause the loaded callback not to fire? Is there a error callback that we can hook into? The loaded callback runs half the time the other half it is never called. Any help is greatly appreciated. Thanks

"mixpanel-browser": "^2.47.0",

import mixpanel from 'mixpanel-browser';

export default class MixpanelService {
  constructor(token) {
    this.mpInstance = new Promise(
      (resolve) => {
        mixpanel.init(token, { loaded: resolve });
      }
    );
}

The test:

  test('mixpanel service asynchronously initializes a mixpanel instance', async function (assert) {
    const service = new MixpanelService('token');

    await service.mpInstance;

    const id = service.mpInstance.get_distinct_id()

    assert.equal(typeof id, 'string');
  });