Skip to content

Commit

Permalink
fix: sanitize set_once properties (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra authored Oct 14, 2024
1 parent 4f73d88 commit bab074e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,24 @@ describe('posthog core', () => {
})
})

it('calls sanitize_properties for $set_once', () => {
posthog = posthogWith(
{
api_host: 'https://custom.posthog.com',
sanitize_properties: (props, event_name) => ({ token: props.token, event_name, ...props }),
},
overrides
)

posthog.persistence.get_initial_props = () => ({ initial: 'prop' })
expect(posthog._calculate_set_once_properties({ key: 'prop' })).toEqual({
event_name: '$set_once',
token: undefined,
initial: 'prop',
key: 'prop',
})
})

it('saves $snapshot data and token for $snapshot events', () => {
posthog = posthogWith({}, overrides)

Expand Down
6 changes: 5 additions & 1 deletion src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,11 @@ export class PostHog {
return dataSetOnce
}
// if we're an identified person, send initial params with every event
const setOnceProperties = extend({}, this.persistence.get_initial_props(), dataSetOnce || {})
let setOnceProperties = extend({}, this.persistence.get_initial_props(), dataSetOnce || {})
const sanitize_properties = this.config.sanitize_properties
if (sanitize_properties) {
setOnceProperties = sanitize_properties(setOnceProperties, '$set_once')
}
if (isEmptyObject(setOnceProperties)) {
return undefined
}
Expand Down

0 comments on commit bab074e

Please sign in to comment.