Skip to content

Commit

Permalink
fix(): prevent person processing if capture is called before SDK conf…
Browse files Browse the repository at this point in the history
…ig is set
  • Loading branch information
havenbarnes committed Jan 17, 2025
1 parent 8d70a9b commit 262dec7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,12 @@ export class PostHog {
}

_hasPersonProcessing(): boolean {
// If the SDK config is not set, we can't determine if we should process the person. Default to false
// as later events will have the config set and persons will be processed correctly.
if (!this.config || isEmptyObject(this.config)) {
return false
}

return !(
this.config.person_profiles === 'never' ||
(this.config.person_profiles === 'identified_only' &&
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 262dec7

Please sign in to comment.