Posthog properly handle Analytics ID changing from under us (#10702)
* Posthog properly handle Analytics ID changing from under us * Update testspull/28788/head^2
parent
857e22f943
commit
e4610e4672
|
@ -312,6 +312,14 @@ export class PosthogAnalytics {
|
||||||
Object.assign({ id: analyticsID }, accountData),
|
Object.assign({ id: analyticsID }, accountData),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (this.posthog.get_distinct_id() === analyticsID) {
|
||||||
|
// No point identifying again
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.posthog.persistence.get_user_state() === "identified") {
|
||||||
|
// Analytics ID has changed, reset as Posthog will refuse to merge in this case
|
||||||
|
this.posthog.reset();
|
||||||
|
}
|
||||||
this.posthog.identify(analyticsID);
|
this.posthog.identify(analyticsID);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// The above could fail due to network requests, but not essential to starting the application,
|
// The above could fail due to network requests, but not essential to starting the application,
|
||||||
|
|
|
@ -33,6 +33,10 @@ const getFakePosthog = (): PostHog =>
|
||||||
identify: jest.fn(),
|
identify: jest.fn(),
|
||||||
reset: jest.fn(),
|
reset: jest.fn(),
|
||||||
register: jest.fn(),
|
register: jest.fn(),
|
||||||
|
get_distinct_id: jest.fn(),
|
||||||
|
persistence: {
|
||||||
|
get_user_state: jest.fn(),
|
||||||
|
},
|
||||||
} as unknown as PostHog);
|
} as unknown as PostHog);
|
||||||
|
|
||||||
interface ITestEvent extends IPosthogEvent {
|
interface ITestEvent extends IPosthogEvent {
|
||||||
|
|
Loading…
Reference in New Issue