From 066bddebb2f8d8fe7188ea878ee1a19b761d7cb9 Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Mon, 25 Nov 2024 22:48:15 +0000 Subject: [PATCH 1/2] Add better npm import, and script entrypoint for customizations --- playground/nextjs/pages/index.tsx | 2 +- rollup.config.js | 2 +- src/customizations/index.ts | 2 ++ src/entrypoints/customizations.full.ts | 7 +++++++ src/posthog-persistence.ts | 2 +- tsconfig.json | 1 + 6 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/customizations/index.ts create mode 100644 src/entrypoints/customizations.full.ts diff --git a/playground/nextjs/pages/index.tsx b/playground/nextjs/pages/index.tsx index f2a72d5fb..ba13076b8 100644 --- a/playground/nextjs/pages/index.tsx +++ b/playground/nextjs/pages/index.tsx @@ -2,7 +2,7 @@ import { useActiveFeatureFlags, usePostHog } from 'posthog-js/react' import { useEffect, useState } from 'react' import { cookieConsentGiven, PERSON_PROCESSING_MODE } from '@/src/posthog' -import { setAllPersonProfilePropertiesAsPersonPropertiesForFlags } from 'posthog-js/lib/src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags' +import { setAllPersonProfilePropertiesAsPersonPropertiesForFlags } from 'posthog-js/lib/customizations' import { STORED_PERSON_PROPERTIES_KEY } from '../../../src/constants' export default function Home() { diff --git a/rollup.config.js b/rollup.config.js index f947d51c8..b791c88eb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -106,7 +106,7 @@ const entrypointTargets = entrypoints.map((file) => { const typeTargets = entrypoints .filter((file) => file.endsWith('.es.ts')) .map((file) => { - const source = `./lib/src/entrypoints/${file.replace('.ts', '.d.ts')}` + const source = `./lib/entrypoints/${file.replace('.ts', '.d.ts')}` /** @type {import('rollup').RollupOptions} */ return { input: source, diff --git a/src/customizations/index.ts b/src/customizations/index.ts new file mode 100644 index 000000000..7cb66f40b --- /dev/null +++ b/src/customizations/index.ts @@ -0,0 +1,2 @@ +export * from './setAllPersonProfilePropertiesAsPersonPropertiesForFlags' +export * from './before-send' diff --git a/src/entrypoints/customizations.full.ts b/src/entrypoints/customizations.full.ts new file mode 100644 index 000000000..eb17c13c0 --- /dev/null +++ b/src/entrypoints/customizations.full.ts @@ -0,0 +1,7 @@ +// this file is called customizations.full.ts because it includes all customizations +// this naming scheme allows us to create a lighter version in the future with only the most popular customizations +// without breaking backwards compatibility + +import * as customizations from '../customizations' +import { assignableWindow } from '../utils/globals' +assignableWindow.posthogCustomizations = customizations diff --git a/src/posthog-persistence.ts b/src/posthog-persistence.ts index 131c85ed6..0a5546c00 100644 --- a/src/posthog-persistence.ts +++ b/src/posthog-persistence.ts @@ -224,7 +224,7 @@ export class PostHogPersistence { const campaignParams = Info.campaignParams(this.config.custom_campaign_params) // only save campaign params if there were any if (!isEmptyObject(stripEmptyProperties(campaignParams))) { - this.register(Info.campaignParams(this.config.custom_campaign_params)) + this.register(campaignParams) } this.campaign_params_saved = true } diff --git a/tsconfig.json b/tsconfig.json index 07e5b9c4c..ccc976cd8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "rootDir": "./src", "outDir": "./lib", "target": "ES5", "lib": ["dom", "dom.iterable", "esnext"], From cc0bb99ea6d91361b17d83685c26c35ead4880b5 Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Tue, 26 Nov 2024 10:32:27 +0000 Subject: [PATCH 2/2] Revert move to /lib rather than /lib/src --- playground/nextjs/pages/index.tsx | 2 +- rollup.config.js | 2 +- tsconfig.json | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/playground/nextjs/pages/index.tsx b/playground/nextjs/pages/index.tsx index ba13076b8..77f0f3ff0 100644 --- a/playground/nextjs/pages/index.tsx +++ b/playground/nextjs/pages/index.tsx @@ -2,7 +2,7 @@ import { useActiveFeatureFlags, usePostHog } from 'posthog-js/react' import { useEffect, useState } from 'react' import { cookieConsentGiven, PERSON_PROCESSING_MODE } from '@/src/posthog' -import { setAllPersonProfilePropertiesAsPersonPropertiesForFlags } from 'posthog-js/lib/customizations' +import { setAllPersonProfilePropertiesAsPersonPropertiesForFlags } from 'posthog-js/lib/src/customizations' import { STORED_PERSON_PROPERTIES_KEY } from '../../../src/constants' export default function Home() { diff --git a/rollup.config.js b/rollup.config.js index b791c88eb..f947d51c8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -106,7 +106,7 @@ const entrypointTargets = entrypoints.map((file) => { const typeTargets = entrypoints .filter((file) => file.endsWith('.es.ts')) .map((file) => { - const source = `./lib/entrypoints/${file.replace('.ts', '.d.ts')}` + const source = `./lib/src/entrypoints/${file.replace('.ts', '.d.ts')}` /** @type {import('rollup').RollupOptions} */ return { input: source, diff --git a/tsconfig.json b/tsconfig.json index ccc976cd8..07e5b9c4c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "rootDir": "./src", "outDir": "./lib", "target": "ES5", "lib": ["dom", "dom.iterable", "esnext"],