40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { MatomoInjector, MatomoTracker } from 'ngx-matomo';
|
|
import { AuthService } from '../auth/auth.service';
|
|
import { ConfigurationService } from '../configuration/configuration.service';
|
|
|
|
@Injectable()
|
|
export class MatomoService {
|
|
|
|
constructor(
|
|
private configurationService: ConfigurationService,
|
|
private matomoInjector: MatomoInjector,
|
|
private matomoTracker: MatomoTracker,
|
|
private authService: AuthService
|
|
) {
|
|
|
|
}
|
|
|
|
init() {
|
|
if (this.configurationService.matomoEnabled) {
|
|
this.matomoInjector.init(this.configurationService.matomoSiteUrl, this.configurationService.matomoSiteId);
|
|
}
|
|
}
|
|
|
|
trackPageView(customTitle?: string): void {
|
|
if (this.configurationService.matomoEnabled) {
|
|
var principal = this.authService.current();
|
|
this.matomoTracker.setUserId(principal ? principal.id : null);
|
|
this.matomoTracker.trackPageView(customTitle);
|
|
}
|
|
}
|
|
|
|
trackSiteSearch(keyword: string, category?: string, resultsCount?: number): void {
|
|
if (this.configurationService.matomoEnabled) {
|
|
var principal = this.authService.current();
|
|
this.matomoTracker.setUserId(principal ? principal.id : null);
|
|
this.matomoTracker.trackSiteSearch(keyword, category, resultsCount);
|
|
}
|
|
}
|
|
}
|