diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f38d8380..4be64c63a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.207.2 - 2025-01-21 + +- fix(): prevent person processing if /decide fails to fetch remote config (#1658) + ## 1.207.1 - 2025-01-21 - fix: expose getNextSurveyStep to use in posthog (#1661) diff --git a/package.json b/package.json index 9e0172b85..d62b5fe6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthog-js", - "version": "1.207.1", + "version": "1.207.2", "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", "repository": "https://github.com/PostHog/posthog-js", "author": "hey@posthog.com", diff --git a/src/__tests__/personProcessing.test.ts b/src/__tests__/personProcessing.test.ts index ce0e92361..931732a9b 100644 --- a/src/__tests__/personProcessing.test.ts +++ b/src/__tests__/personProcessing.test.ts @@ -721,19 +721,19 @@ describe('person processing', () => { }) describe('decide', () => { - it('should change the person mode from default when decide response is handled', async () => { + it('should default the person mode to identified_only when an incomplete decide response is handled', async () => { // arrange const { posthog, beforeSendMock } = await setup(undefined) posthog.capture('startup page view') // act - posthog._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig) + posthog._onRemoteConfig({} as RemoteConfig) posthog.capture('custom event') // assert expect(beforeSendMock.mock.calls.length).toEqual(2) expect(beforeSendMock.mock.calls[0][0].properties.$process_person_profile).toEqual(false) - expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(true) + expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(false) }) it('should NOT change the person mode from user-defined when decide response is handled', async () => { @@ -750,31 +750,5 @@ describe('person processing', () => { expect(beforeSendMock.mock.calls[0][0].properties.$process_person_profile).toEqual(false) expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(false) }) - - it('should persist when the default person mode is overridden by decide', async () => { - // arrange - const persistenceName = uuidv7() - const { posthog: posthog1, beforeSendMock: beforeSendMock1 } = await setup( - undefined, - undefined, - persistenceName - ) - - // act - posthog1._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig) - posthog1.capture('custom event 1') - const { posthog: posthog2, beforeSendMock: beforeSendMock2 } = await setup( - undefined, - undefined, - persistenceName - ) - posthog2.capture('custom event 2') - - // assert - expect(beforeSendMock1.mock.calls.length).toEqual(1) - expect(beforeSendMock2.mock.calls.length).toEqual(1) - expect(beforeSendMock1.mock.calls[0][0].properties.$process_person_profile).toEqual(true) - expect(beforeSendMock2.mock.calls[0][0].properties.$process_person_profile).toEqual(true) - }) }) }) diff --git a/src/__tests__/posthog-core.ts b/src/__tests__/posthog-core.ts index e6ede1f11..97b37f340 100644 --- a/src/__tests__/posthog-core.ts +++ b/src/__tests__/posthog-core.ts @@ -342,14 +342,17 @@ describe('posthog core', () => { expect(posthog.compression).toEqual('gzip-js') }) - it('uses defaultIdentifiedOnly from decide response', () => { + it('ignores legacy field defaultIdentifiedOnly from decide response', () => { const posthog = posthogWith({}) posthog._onRemoteConfig({ defaultIdentifiedOnly: true } as RemoteConfig) expect(posthog.config.person_profiles).toEqual('identified_only') posthog._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig) - expect(posthog.config.person_profiles).toEqual('always') + expect(posthog.config.person_profiles).toEqual('identified_only') + + posthog._onRemoteConfig({} as RemoteConfig) + expect(posthog.config.person_profiles).toEqual('identified_only') }) it('defaultIdentifiedOnly does not override person_profiles if already set', () => { const posthog = posthogWith({ person_profiles: 'always' }) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 25edc327b..720effb99 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -587,11 +587,7 @@ export class PostHog { } this.set_config({ - person_profiles: this._initialPersonProfilesConfig - ? this._initialPersonProfilesConfig - : config['defaultIdentifiedOnly'] - ? 'identified_only' - : 'always', + person_profiles: this._initialPersonProfilesConfig ? this._initialPersonProfilesConfig : 'identified_only', }) this.siteApps?.onRemoteConfig(config) diff --git a/src/utils/type-utils.ts b/src/utils/type-utils.ts index c3ea4ade5..cdc556286 100644 --- a/src/utils/type-utils.ts +++ b/src/utils/type-utils.ts @@ -35,7 +35,7 @@ export const isObject = (x: unknown): x is Record => { // eslint-disable-next-line posthog-js/no-direct-object-check return x === Object(x) && !isArray(x) } -export const isEmptyObject = (x: unknown): x is Record => { +export const isEmptyObject = (x: unknown) => { if (isObject(x)) { for (const key in x) { if (hasOwnProperty.call(x, key)) {