import { Injectable } from '@angular/core';
import { OpenPanel } from '@openpanel/web';

@Injectable({
  providedIn: 'root'
})
export class AnalyticsService {
  private openpanel: OpenPanel;

  constructor() {
    this.openpanel = new OpenPanel({
      clientId: 'DEINE_CLIENT_ID',
      trackScreenViews: true,
      trackOutgoingLinks: true,
    });
  }

  trackEvent(name: string, properties?: Record<string, any>) {
    this.openpanel.track(name, properties);
  }

  identifyUser(userId: string, traits?: Record<string, any>) {
    this.openpanel.identify(userId);
    
    if (traits) {
      this.openpanel.setProfile(traits);
    }
  }
}