Plugins
Install the JavaScript SDK
Add Premely to a JavaScript app with the npm package and one client-side setup call.
npm
What it is
The @premely/analytics JavaScript SDK installs the same privacy-first tracker used by Premely's direct HTML and platform integrations. It is designed for JavaScript apps that manage their own client-side code.
Why use it
Use the SDK when your team wants a package-managed Premely installation in a React, Next.js, Vue, Svelte or other JavaScript application.
Before you start
- Create the site in Premely and copy its public
pm_site_v1_…site key from the setup instructions. - Choose one installation method. Remove a direct script or Google Tag Manager tag before you add the SDK, so the site does not send duplicate pageviews.
How to use it
- 1
Install the package
Add
@premely/analyticsto the website project withnpm install @premely/analytics.Product screenshot placeholderSite setup - JavaScript SDK
Capture focus: Package installation and site-specific configuration
1Install package2Site key3VerifyReplace this slot with the matching production surface and numbered callouts before publishing. - 2
Run the setup once on the client
Import
installPremelyorcreatePremely, then run the installation once in a client-side mount or hook with the site's public key. The SDK is safe to import in SSR applications and returns immediately on the server. - 3
Keep route tracking automatic
The SDK observes normal browser history changes. Add
pageview()only if your application changes the visible route without updating browser history. - 4
Publish and verify
Deploy the application, visit the public site once, then return to Premely and confirm the connection status.
What to expect
One configuration stays active
Repeated setup calls with the same configuration reuse the existing tracker. Conflicting site, domain or collector settings are rejected instead of creating a second tracker.
Privacy controls are respected
With the default settings, browser Do Not Track is respected. A consent manager can use setConsent(false) to stop collection and clear unsent events.
Useful ways to apply this
A framework application
Install Premely from one client-side provider or application layout so every published route is measured consistently.
A meaningful product action
Use track() for a clear completed action, keeping event properties short, non-personal and easy to read in reports.