Skip to content

Commit

Permalink
Merge branch 'main' into fix/survey-preview-bundle-size
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheriques committed Jan 22, 2025
2 parents 44c808b + 339092d commit d84db50
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
Expand Down
32 changes: 3 additions & 29 deletions src/__tests__/personProcessing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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)
})
})
})
7 changes: 5 additions & 2 deletions src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
6 changes: 1 addition & 5 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const isObject = (x: unknown): x is Record<string, any> => {
// eslint-disable-next-line posthog-js/no-direct-object-check
return x === Object(x) && !isArray(x)
}
export const isEmptyObject = (x: unknown): x is Record<string, any> => {
export const isEmptyObject = (x: unknown) => {
if (isObject(x)) {
for (const key in x) {
if (hasOwnProperty.call(x, key)) {
Expand Down

0 comments on commit d84db50

Please sign in to comment.