Amplitude-TypeScript icon indicating copy to clipboard operation
Amplitude-TypeScript copied to clipboard

Provide a modular build of the browser SDK that does not bundle the plugins

Open stof opened this issue 6 months ago • 2 comments

Summary

BrowserClient currently defines an API allowing to enable or disable autocapture features through boolean options. This implies that it has to bundle the associated plugins even if the options will disable them.

A modular API should be provided, supporting the code features for the browser, but without any bundled plugins. This will give choices to projects:

  1. use the modular core and register wanted plugins explicitly
  2. use the existing BrowserClient that would use that modular core and keep bundling the plugins for ease of use (maybe excluding experimental plugins from the bundle plugins, requiring them to be registered directly).

See https://github.com/amplitude/Amplitude-TypeScript/issues/325#issuecomment-3206610944 for a comment (by me) proposing this solution to the bundle size bloat issue. This modular core would at least solve this partially (it won't help much projects using autocapture).

Motivations

The bundle size of @amplitude/analytics-browser is quite big, and tends to grow bigger when adding new autocapture plugins. When not using autocapture (which is my case), half of that bundle size is wasted by autocapture-related plugins

stof avatar Aug 22 '25 13:08 stof

Thanks @stof . I'll add this to our backlog as a feature request.

daniel-graham-amplitude avatar Aug 22 '25 15:08 daniel-graham-amplitude

Would just like to add to this. This large bundle size prevents integrating this SDK into a 3rd party web pixel build environment, which caps the maximum bundle size to 128kb. We are unable to use the @amplitude/analytics-browser SDK at all, as this dependency is too large even by itself.

The plugin removal would be a great benefit. Work around we may use is to directly invoke the HTTP V2 API for the time being.

bryant-route avatar Dec 12 '25 18:12 bryant-route