Skip to content

Commit d84db50

Browse files
committed
Merge branch 'main' into fix/survey-preview-bundle-size
2 parents 44c808b + 339092d commit d84db50

6 files changed

+15
-38
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.207.2 - 2025-01-21
2+
3+
- fix(): prevent person processing if /decide fails to fetch remote config (#1658)
4+
15
## 1.207.1 - 2025-01-21
26

37
- fix: expose getNextSurveyStep to use in posthog (#1661)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthog-js",
3-
"version": "1.207.1",
3+
"version": "1.207.2",
44
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
55
"repository": "https://github.com/PostHog/posthog-js",
66
"author": "[email protected]",

src/__tests__/personProcessing.test.ts

+3-29
Original file line numberDiff line numberDiff line change
@@ -721,19 +721,19 @@ describe('person processing', () => {
721721
})
722722

723723
describe('decide', () => {
724-
it('should change the person mode from default when decide response is handled', async () => {
724+
it('should default the person mode to identified_only when an incomplete decide response is handled', async () => {
725725
// arrange
726726
const { posthog, beforeSendMock } = await setup(undefined)
727727
posthog.capture('startup page view')
728728

729729
// act
730-
posthog._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig)
730+
posthog._onRemoteConfig({} as RemoteConfig)
731731
posthog.capture('custom event')
732732

733733
// assert
734734
expect(beforeSendMock.mock.calls.length).toEqual(2)
735735
expect(beforeSendMock.mock.calls[0][0].properties.$process_person_profile).toEqual(false)
736-
expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(true)
736+
expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(false)
737737
})
738738

739739
it('should NOT change the person mode from user-defined when decide response is handled', async () => {
@@ -750,31 +750,5 @@ describe('person processing', () => {
750750
expect(beforeSendMock.mock.calls[0][0].properties.$process_person_profile).toEqual(false)
751751
expect(beforeSendMock.mock.calls[1][0].properties.$process_person_profile).toEqual(false)
752752
})
753-
754-
it('should persist when the default person mode is overridden by decide', async () => {
755-
// arrange
756-
const persistenceName = uuidv7()
757-
const { posthog: posthog1, beforeSendMock: beforeSendMock1 } = await setup(
758-
undefined,
759-
undefined,
760-
persistenceName
761-
)
762-
763-
// act
764-
posthog1._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig)
765-
posthog1.capture('custom event 1')
766-
const { posthog: posthog2, beforeSendMock: beforeSendMock2 } = await setup(
767-
undefined,
768-
undefined,
769-
persistenceName
770-
)
771-
posthog2.capture('custom event 2')
772-
773-
// assert
774-
expect(beforeSendMock1.mock.calls.length).toEqual(1)
775-
expect(beforeSendMock2.mock.calls.length).toEqual(1)
776-
expect(beforeSendMock1.mock.calls[0][0].properties.$process_person_profile).toEqual(true)
777-
expect(beforeSendMock2.mock.calls[0][0].properties.$process_person_profile).toEqual(true)
778-
})
779753
})
780754
})

src/__tests__/posthog-core.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,17 @@ describe('posthog core', () => {
342342

343343
expect(posthog.compression).toEqual('gzip-js')
344344
})
345-
it('uses defaultIdentifiedOnly from decide response', () => {
345+
it('ignores legacy field defaultIdentifiedOnly from decide response', () => {
346346
const posthog = posthogWith({})
347347

348348
posthog._onRemoteConfig({ defaultIdentifiedOnly: true } as RemoteConfig)
349349
expect(posthog.config.person_profiles).toEqual('identified_only')
350350

351351
posthog._onRemoteConfig({ defaultIdentifiedOnly: false } as RemoteConfig)
352-
expect(posthog.config.person_profiles).toEqual('always')
352+
expect(posthog.config.person_profiles).toEqual('identified_only')
353+
354+
posthog._onRemoteConfig({} as RemoteConfig)
355+
expect(posthog.config.person_profiles).toEqual('identified_only')
353356
})
354357
it('defaultIdentifiedOnly does not override person_profiles if already set', () => {
355358
const posthog = posthogWith({ person_profiles: 'always' })

src/posthog-core.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,7 @@ export class PostHog {
587587
}
588588

589589
this.set_config({
590-
person_profiles: this._initialPersonProfilesConfig
591-
? this._initialPersonProfilesConfig
592-
: config['defaultIdentifiedOnly']
593-
? 'identified_only'
594-
: 'always',
590+
person_profiles: this._initialPersonProfilesConfig ? this._initialPersonProfilesConfig : 'identified_only',
595591
})
596592

597593
this.siteApps?.onRemoteConfig(config)

src/utils/type-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const isObject = (x: unknown): x is Record<string, any> => {
3535
// eslint-disable-next-line posthog-js/no-direct-object-check
3636
return x === Object(x) && !isArray(x)
3737
}
38-
export const isEmptyObject = (x: unknown): x is Record<string, any> => {
38+
export const isEmptyObject = (x: unknown) => {
3939
if (isObject(x)) {
4040
for (const key in x) {
4141
if (hasOwnProperty.call(x, key)) {

0 commit comments

Comments
 (0)