analytics service refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-29 15:31:08 +03:00
parent ae4595874b
commit 30fb0eb7ed
6 changed files with 36 additions and 23 deletions

View File

@ -4,20 +4,20 @@ import { catchError, takeUntil } from 'rxjs/operators';
import { FileTransformerHttpService } from './file-transformer.http.service';
import { Guid } from '@common/types/guid';
import * as FileSaver from 'file-saver';
import { MatomoService } from '../matomo/matomo-service';
import { FileUtils } from '../utilities/file-utils.service';
import { AuthService } from '../auth/auth.service';
import { RepositoryFileFormat } from '@app/core/model/file/file-format.model';
import { FileTransformerEntityType } from '@app/core/common/enum/file-transformer-entity-type';
import { DmpService } from '../dmp/dmp.service';
import { DescriptionService } from '../description/description.service';
import { AnalyticsService } from '../matomo/analytics-service';
@Injectable()
export class FileTransformerService extends BaseService {
constructor(
private fileTransformerHttpService: FileTransformerHttpService,
private matomoService: MatomoService,
private analyticsService: AnalyticsService,
private fileUtils: FileUtils,
private dmpService: DmpService,
private descriptionService: DescriptionService,
@ -87,7 +87,7 @@ export class FileTransformerService extends BaseService {
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(result.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', format, id.toString());
this.analyticsService.trackDownload('dmps', format, id.toString());
}
});
@ -114,7 +114,7 @@ export class FileTransformerService extends BaseService {
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(result.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('descriptions', format, id.toString());
this.analyticsService.trackDownload('descriptions', format, id.toString());
}
});
}

View File

@ -6,6 +6,7 @@ import { AnalyticsProviderType, AnalyticsProviders } from "@app/core/model/confi
@Injectable()
export class AnalyticsService {
//#region track page view
public static Dashboard: string = 'Home Dashboard';
public static About: string = 'About';
public static DescriptionTemplateEditor: string = 'Admin: DMP Blueprints';
@ -44,6 +45,13 @@ export class AnalyticsService {
public static UserGuideContent: string = 'User Guide Content';
public static UserProfile: string = 'User Profile';
public static NotificationTempplateEditor: string = 'Admin: Notification Tempplates';
//#endregion
//#region trackDownload
public static trackDmp: string = "dmps"
public static trackDatasets: string = "datasets"
public static trackDescriptions: string = "descriptions"
//#endregion
constructor(
private configurationService: ConfigurationService,
@ -55,14 +63,33 @@ export class AnalyticsService {
for (let provider of analytics.providers) {
switch(provider.type) {
case(AnalyticsProviderType.Matomo):
this.matomoService.trackPageViewCopy(provider, customTitle);
this.matomoService.trackPageView(provider, customTitle);
break;
}
}
}
trackSiteSearch(keyword: string, category?: string, resultsCount?: number): void {
const analytics: AnalyticsProviders = this.configurationService.analyticsProviders;
for (let provider of analytics.providers) {
switch(provider.type) {
case(AnalyticsProviderType.Matomo):
this.matomoService.trackSiteSearch(keyword, category, resultsCount);
break;
}
}
}
trackDownload(category: "dmps" | "datasets" | "descriptions", type: string, id: string): void {
const analytics: AnalyticsProviders = this.configurationService.analyticsProviders;
for (let provider of analytics.providers) {
switch(provider.type) {
case(AnalyticsProviderType.Matomo):
this.matomoService.trackDownload(category, type, id);
break;
}
}
}
}

View File

@ -22,15 +22,7 @@ export class MatomoService {
}
}
trackPageView(customTitle?: string): void {
if (this.configurationService.matomoEnabled) {
var principalid = this.authService.userId();
if (principalid != null) { this.matomoTracker.setUserId(principalid.toString()); }
this.matomoTracker.trackPageView(customTitle);
}
}
trackPageViewCopy(provider: AnalyticsProvider, customTitle?: string): void {
trackPageView(provider: AnalyticsProvider, customTitle?: string): void {
if (provider.enabled) {
var principalid = this.authService.userId();
if (principalid != null) { this.matomoTracker.setUserId(principalid.toString()); }

View File

@ -11,7 +11,6 @@ import { DescriptionService } from '@app/core/services/description/description.s
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.service';
import { LockService } from '@app/core/services/lock/lock.service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
import { ReferenceService } from '@app/core/services/reference/reference.service';
@ -63,7 +62,6 @@ export class DescriptionListingItemComponent extends BaseComponent implements On
private uiNotificationService: UiNotificationService,
private lockService: LockService,
private location: Location,
private matomoService: MatomoService,
private fileUtils: FileUtils,
public dmpService: DmpService,
public referenceService: ReferenceService,
@ -146,7 +144,7 @@ export class DescriptionListingItemComponent extends BaseComponent implements On
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('descriptions', format, description.id.toString());
this.analyticsService.trackDownload('descriptions', format, description.id.toString());
});
}

View File

@ -19,7 +19,6 @@ import { ConfigurationService } from '@app/core/services/configuration/configura
import { DescriptionService } from '@app/core/services/description/description.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
import { ReferenceService } from '@app/core/services/reference/reference.service';
@ -87,7 +86,6 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
public referenceService: ReferenceService,
private location: Location,
public enumUtils: EnumUtils,
private matomoService: MatomoService,
private fileUtils: FileUtils,
private authService: AuthService,
public fileTransformerService: FileTransformerService,
@ -355,7 +353,7 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('descriptions', format, id);
this.analyticsService.trackDownload('descriptions', format, id);
});
}

View File

@ -25,7 +25,6 @@ import { DepositService } from '@app/core/services/deposit/deposit.service';
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.service';
import { LockService } from '@app/core/services/lock/lock.service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { ReferenceService } from '@app/core/services/reference/reference.service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
@ -100,7 +99,6 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
private configurationService: ConfigurationService,
private location: Location,
private lockService: LockService,
private matomoService: MatomoService,
private fileUtils: FileUtils,
public referenceService: ReferenceService,
public enumUtils: EnumUtils,
@ -462,7 +460,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', format, id);
this.analyticsService.trackDownload('dmps', format, id);
});
}