mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Angulartics2 } from 'angulartics2';
|
|
import { StatisticsService } from '../statistics.service';
|
|
|
|
/**
|
|
* Angulartics2DSpace is a angulartics2 plugin that provides DSpace with the events.
|
|
*/
|
|
@Injectable({providedIn: 'root'})
|
|
export class Angulartics2DSpace {
|
|
|
|
constructor(
|
|
private angulartics2: Angulartics2,
|
|
private statisticsService: StatisticsService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Activates this plugin
|
|
*/
|
|
startTracking(): void {
|
|
this.angulartics2.eventTrack
|
|
.pipe(this.angulartics2.filterDeveloperMode())
|
|
.subscribe((event) => this.eventTrack(event));
|
|
}
|
|
|
|
private eventTrack(event) {
|
|
if (event.action === 'pageView') {
|
|
this.statisticsService.trackViewEvent(event.properties.object, event.properties.referrer);
|
|
} else if (event.action === 'search') {
|
|
this.statisticsService.trackSearchEvent(
|
|
event.properties.searchOptions,
|
|
event.properties.page,
|
|
event.properties.sort,
|
|
event.properties.filters
|
|
);
|
|
}
|
|
}
|
|
}
|