Skip to content

Commit

Permalink
and distinct_id
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Mar 23, 2024
1 parent 33999c7 commit a9433e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('posthog core', () => {
})

describe('bootstrap()', () => {
it('handles reasonable typos', async () => {
it('handles reasonable typo of distinctId', async () => {
const ph = await createPosthogInstance(uuidv7(), {
advanced_disable_decide: false,
// NB typo of `distinctID` as `distinctId` (lower csae `d`)
Expand All @@ -44,7 +44,16 @@ describe('posthog core', () => {
expect(ph.config.bootstrap.distinctID).toEqual('anon-id')
})

it('handles reasonable typos without overidding', async () => {
it('handles reasonable typo of distinct_id', async () => {
const ph = await createPosthogInstance(uuidv7(), {
advanced_disable_decide: false,
// NB typo of `distinctID` as `distinctId` (lower csae `d`)
bootstrap: { distinct_id: 'anon-id' },
})
expect(ph.config.bootstrap.distinctID).toEqual('anon-id')
})

it('handles reasonable typos without overriding', async () => {
const ph = await createPosthogInstance(uuidv7(), {
advanced_disable_decide: false,
// NB typo of `distinctID` as `distinctId` (lower csae `d`)
Expand Down
6 changes: 3 additions & 3 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ export class PostHog {
if (
!_isUndefined(config.bootstrap) &&
_isUndefined(config.bootstrap.distinctID) &&
(config.bootstrap as any).distinctId
((config.bootstrap as any).distinctId || (config.bootstrap as any).distinct_id)
) {
// distinctId (lowercase d) is a reasonable typo for distinctID
// that we have seen in the wild
logger.warn('bootstrap distinctId is a typo. It should be distinctID (capital D). Copying the value.')
config.bootstrap.distinctID = (config.bootstrap as any)?.distinctId
logger.info('bootstrap distinctId is a typo. It should be distinctID (capital D). Copying the value.')
config.bootstrap.distinctID = (config.bootstrap as any).distinctId || (config.bootstrap as any).distinct_id
}

// isUndefined doesn't provide typehint here so wouldn't reduce bundle as we'd need to assign
Expand Down

0 comments on commit a9433e0

Please sign in to comment.