Alytica Docs
Guides

Angular

Integrate Alytica with your Angular application.

1. Installation

npm install alytica-js

2. Create an Injectable Service

import { Injectable } from '@angular/core';
import { Alytica } from 'alytica-js';
 
@Injectable({
  providedIn: 'root'
})
export class AlyticaService {
  private alytica: Alytica;
 
  constructor() {
    this.alytica = new Alytica({
      clientId: 'your-client-id',
      clientSecret: 'your-client-secret',
      trackPageViews: true
    });
  }
 
  track(event: string, properties?: Record<string, any>) {
    this.alytica.track(event, properties);
  }
}

3. Use in Components

import { Component } from '@angular/core';
import { AlyticaService } from './alytica.service';
 
@Component({
  selector: 'app-tracking',
  template: `
    <button (click)="trackEvent()">Track Event</button>
  `
})
export class TrackingComponent {
  constructor(private alytica: AlyticaService) {}
 
  trackEvent() {
    this.alytica.track('button_click', { component: 'angular' });
  }
}

Best Practices

  • Replace 'your-client-id' and 'your-client-secret' with your actual Alytica credentials
  • Configure tracking options based on your specific requirements
  • Ensure compliance with privacy regulations when tracking user data

On this page