Integrations

Angular

Add Databuddy once and every route change in your Angular app counts as a pageview.

Add Databuddy

npm install @databuddy/sdk
src/main.ts
import { bootstrapApplication } from "@angular/platform-browser";
import { init } from "@databuddy/sdk";
import { AppComponent } from "./app/app.component";
import { appConfig } from "./app/app.config";

init({
  clientId: "YOUR_CLIENT_ID",
  autocapture: { webVitals: true, errors: true },
});

bootstrapApplication(AppComponent, appConfig);

init() does nothing during server rendering, so it's safe with Angular SSR.

Your Client ID is in the dashboard under your website's Settings → General. Router navigations are tracked automatically, so you don't need a NavigationEnd subscription.

Track an event

src/app/checkout.component.ts
import { Component } from "@angular/core";
import { track } from "@databuddy/sdk";

@Component({
  selector: "app-checkout",
  template: `<button (click)="complete('ord_123', 49)">Pay</button>`,
})
export class CheckoutComponent {
  complete(orderId: string, total: number): void {
    track("purchase_complete", { order_id: orderId, total, currency: "USD" });
  }
}

track() is typed and works with either install. Calls made before the tracker loads wait for it, and calls on the server are skipped.

Track clicks from templates

Add data-track-attributes to the script tag, or attributes: true to autocapture, then name elements in any template:

src/app/hero.component.html
<a routerLink="/pricing" data-track="pricing_click" data-location="hero">View pricing</a>

Each click sends a pricing_click event with location: "hero".

Use a different Client ID per environment

src/environments/environment.prod.ts
export const environment = { databuddyClientId: "YOUR_PROD_CLIENT_ID" };

Pass environment.databuddyClientId to init(). Angular's fileReplacements picks the right file for each build.

How is this guide?