Appearance
Install with Plasmo
Plasmo builds the manifest from your files and package.json. The AnalyticsTrend extension SDK needs nothing Plasmo-specific: start it in the background, and send from pages through it.
Tested with Plasmo 0.90.5 on Node 24. Plasmo's own releases have slowed since 2025; for a new project, WXT is the framework these guides cover most closely.
bash
npm install @analyticstrend/extensionThe background
ts
// background.ts
import { initBackground } from "@analyticstrend/extension";
const analytics = initBackground({
writeKey: process.env.PLASMO_PUBLIC_ANALYTICSTREND_WRITE_KEY,
uninstallTracking: true,
});
analytics.track("background_started");At the top level, so it runs on every background start, and not awaited: Chrome will not run a service worker that uses top-level await. Plasmo inlines variables that start with PLASMO_PUBLIC_ at build time, from your .env file or the environment.
From the popup
tsx
import { trackFromContentScript } from "@analyticstrend/extension";
trackFromContentScript("popup_opened");The manifest
Plasmo reads manifest settings from manifest in package.json:
json
{
"manifest": {
"permissions": ["storage"],
"browser_specific_settings": {
"gecko": {
"id": "your-extension@example.com",
"strict_min_version": "140.0",
"data_collection_permissions": {
"required": ["none"],
"optional": ["technicalAndInteraction", "locationInfo"]
}
}
}
}
}Plasmo leaves browser_specific_settings out of the Chrome build by itself, so one package.json serves both browsers.
Build for Firefox
bash
plasmo build --target=firefox-mv3The build is in build/firefox-mv3-prod, with background scripts in place of Chrome's service worker. The SDK honours the person's data-collection choice itself, as the Firefox guide explains.
The Plasmo example builds for both browsers in CI.