Documentation
Vue
Use @telemetry-tracker/core in Vue 3 SPAs (Vite, webpack, or similar). Call init() once at app startup and hook router.afterEach for page views. After init(), uncaught errors and unhandled promise rejections in the browser are reported automatically; call installVueErrorHandler(app) so errors thrown inside components (render, hooks, event handlers) are reported too. For Nuxt, see the Nuxt guide.
Install
pnpm add @telemetry-tracker/core
# or
npm install @telemetry-tracker/coreEnvironment (Vite)
Add to .env (prefix public vars with VITE_):
VITE_TELEMETRY_INGEST_URL=https://your-api.example.com
VITE_TELEMETRY_APP=my-vue-app
VITE_TELEMETRY_API_KEY=tt_live_<publicId>_<secret>Setup in main.ts
Initialize before mounting the app, then track route changes with screen():
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import { init, installVueErrorHandler, screen } from "@telemetry-tracker/core";
init({
ingestUrl: import.meta.env.VITE_TELEMETRY_INGEST_URL,
app: import.meta.env.VITE_TELEMETRY_APP ?? "my-vue-app",
apiKey: import.meta.env.VITE_TELEMETRY_API_KEY,
platform: "web",
environment: import.meta.env.MODE,
release: import.meta.env.VITE_APP_VERSION,
});
router.afterEach((to) => {
screen(to.fullPath || "/");
});
const app = createApp(App);
// Vue catches component errors itself (they never reach window.onerror),
// so hook app.config.errorHandler. An existing handler is kept and chained.
installVueErrorHandler(app);
app.use(router).mount("#app");Component errors
Vue handles errors thrown in render functions, lifecycle hooks, watchers and event handlers (including async ones) through app.config.errorHandler, so in production builds they only reach console.error. installVueErrorHandler(app) reports them with source: "vue", the component name and Vue's error info. If you set your own errorHandler, install it first: it is still called after reporting. Requires @telemetry-tracker/core 1.6.0 or later.
Optional: plugin
Wrap init in a plugin if you prefer dependency-injection style setup:
// plugins/telemetry.ts
import type { App } from "vue";
import { init, installVueErrorHandler, type TelemetryConfig } from "@telemetry-tracker/core";
export function telemetryPlugin(config: TelemetryConfig) {
return {
install(app: App) {
init(config);
installVueErrorHandler(app);
},
};
}
// main.ts
import { telemetryPlugin } from "./plugins/telemetry";
app.use(
telemetryPlugin({
ingestUrl: import.meta.env.VITE_TELEMETRY_INGEST_URL,
app: "my-vue-app",
apiKey: import.meta.env.VITE_TELEMETRY_API_KEY,
})
);Custom events and errors
import { trackEvent, trackError, identify } from "@telemetry-tracker/core";
trackEvent("button_click", { id: "submit" });
trackError(new Error("Checkout failed"), { step: "payment" });
identify(user.id); // after loginUse trackError() in Pinia action catch blocks or other try/catch code when you want extra context beyond the global and component handlers.