Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add better npm import, and script entrypoint for customizations #1550

Merged

Conversation

robbie-c
Copy link
Member

@robbie-c robbie-c commented Nov 25, 2024

Changes

Add a script entrypoint, cutomizations.full.js for adding all of the cutomizations for posthog-js.

Right now this is the sampling functions and the setAllPersonPropertiesAsPropertiesForFlags function.

I've also added a central import for npm users who want to use customizations, so now they can do import { sampleByDistinctId } from 'posthog-js/lib/src/customizations'

I tweaked tsconfig.json so tha it's not import { sampleByDistinctId } from 'posthog-js/lib/src/customizations'. This will mean a very small number of customers will need to update their imports when they update to this version (see https://posthog.slack.com/archives/C03P7NL6RMW/p1732554807615089?thread_ts=1730464902.575749&cid=C03P7NL6RMW )

This is true of anyone who imports /lib/src, it's now just /lib

(We could do this in a backwards compat way, I'm just not sure we need the extra complexity for something that was previously not officially supported)

I removed the above change /lib/src/ -> /lib/ - it was causing an increase in the bundle size and I'll figure it out separately

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Nov 26, 2024 10:39am

Copy link

github-actions bot commented Nov 25, 2024

Size Change: -520 B (-0.02%)

Total Size: 3.15 MB

Filename Size Change
dist/array.full.es5.js 255 kB -52 B (-0.02%)
dist/array.full.js 358 kB -52 B (-0.01%)
dist/array.full.no-external.js 357 kB -52 B (-0.01%)
dist/array.js 172 kB -52 B (-0.03%)
dist/array.no-external.js 171 kB -52 B (-0.03%)
dist/main.js 173 kB -52 B (-0.03%)
dist/module.full.js 358 kB -52 B (-0.01%)
dist/module.full.no-external.js 357 kB -52 B (-0.01%)
dist/module.js 173 kB -52 B (-0.03%)
dist/module.no-external.js 171 kB -52 B (-0.03%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 206 kB
dist/customizations.full.js 12.1 kB
dist/dead-clicks-autocapture.js 14.3 kB
dist/exception-autocapture.js 9.37 kB
dist/external-scripts-loader.js 2.29 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/surveys-preview.js 57.6 kB
dist/surveys.js 63.2 kB
dist/tracing-headers.js 1.75 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

@pauldambra
Copy link
Member

it's a big size bump for a convenience change...

i guess they're either not pure or rollup isn't detecting them as pure...

need some kind of /*@__NO_SIDE_EFFECTS__*/ marker somewhere so that these are only available in NPM not in the bundles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry should have commented here


it's a big size bump for a convenience change...

i guess they're either not pure or rollup isn't detecting them as pure...

need some kind of /@NO_SIDE_EFFECTS/ marker somewhere so that these are only available in NPM not in the bundles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the size bump tells me that this hasn't worked as expected.

I'll look into it

Apologies for the premature tagging for review

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I removed the tsconfig change, and this seems to have prevented the increase in bundle size. I'll figure this part out separately.

@robbie-c robbie-c force-pushed the feature/add-a-better-npm-and-script-export-for-customizations branch from 65c11c7 to cc0bb99 Compare November 26, 2024 10:34
@robbie-c robbie-c requested a review from pauldambra November 26, 2024 10:49
@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by, saw this could be smaller

@robbie-c robbie-c added the bump minor Bump minor version when this PR gets merged label Nov 26, 2024
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely quality of life improvement

wanna update the before_send docs too? #cheeky

🚀

@robbie-c robbie-c merged commit 45016d5 into main Nov 26, 2024
18 checks passed
@robbie-c robbie-c deleted the feature/add-a-better-npm-and-script-export-for-customizations branch November 26, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants