From a9433e0f345574bceb7ea7307d60f06f86f35117 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Sat, 23 Mar 2024 18:25:00 +0000 Subject: [PATCH] and distinct_id --- src/__tests__/posthog-core.js | 13 +++++++++++-- src/posthog-core.ts | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/__tests__/posthog-core.js b/src/__tests__/posthog-core.js index 8f2c78bc0..c1208d431 100644 --- a/src/__tests__/posthog-core.js +++ b/src/__tests__/posthog-core.js @@ -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`) @@ -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`) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 9054d2eff..2555983dd 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -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