From 1d45bddecaa96417985fce39f0ed50e90747bb2d Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 20 Jan 2023 19:02:12 +0200 Subject: [PATCH] #8350 - Added tracking of download Dataset & DMP exports in Matomo. 1. matomo-service.ts: Added method "trackDownload()". 2. drafts.component.ts & recent-edited-activity.component.ts & recent-edited-dataset-activity.component.ts & recent-edited-dmp-activity.component.ts & dataset-wizard.component.ts & dataset-listing-item.component.ts & dataset-overview.component.ts & dmp-editor.component.ts & dmp-listing-item.component.ts & dmp-overview.component.ts: Added calls to this.matomoService.trackDownload() for "datasets/" or "dmps/" with the file type (/docx, /xml, /pdf, /json) and the id. --- .../app/core/services/matomo/matomo-service.ts | 11 +++++++++++ .../app/ui/dashboard/drafts/drafts.component.ts | 3 +++ .../recent-edited-activity.component.ts | 7 +++++++ .../recent-edited-dataset-activity.component.ts | 7 ++++++- .../recent-edited-dmp-activity.component.ts | 4 ++++ .../dataset-wizard/dataset-wizard.component.ts | 15 +++++++++------ .../dataset-listing-item.component.ts | 3 +++ .../overview/dataset-overview.component.ts | 3 +++ .../src/app/ui/dmp/editor/dmp-editor.component.ts | 4 ++++ .../listing-item/dmp-listing-item.component.ts | 4 ++++ .../app/ui/dmp/overview/dmp-overview.component.ts | 4 ++++ 11 files changed, 58 insertions(+), 7 deletions(-) diff --git a/dmp-frontend/src/app/core/services/matomo/matomo-service.ts b/dmp-frontend/src/app/core/services/matomo/matomo-service.ts index f4711f996..700535510 100644 --- a/dmp-frontend/src/app/core/services/matomo/matomo-service.ts +++ b/dmp-frontend/src/app/core/services/matomo/matomo-service.ts @@ -36,4 +36,15 @@ export class MatomoService { this.matomoTracker.trackSiteSearch(keyword, category, resultsCount); } } + + trackDownload(category: "dmps"|"datasets", type: "docx"|"pdf"|"xml"|"json", id: string): void { + if (this.configurationService.matomoEnabled) { + var principal = this.authService.current(); + if (principal != null) { this.matomoTracker.setUserId(principal.id); } + this.matomoTracker.trackLink(this.configurationService.server + category + "/" + type + "/" + id, "download"); + + // this.matomoTracker.trackLink(url, "download"); + // this.matomoTracker.trackEvent(category, "Downloaded", type); + } + } } diff --git a/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts b/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts index 424072c2b..b5e80c54f 100644 --- a/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts @@ -263,6 +263,7 @@ export class DraftsComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", dataset.id); }); } @@ -274,6 +275,7 @@ export class DraftsComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", dataset.id); }); } @@ -286,6 +288,7 @@ export class DraftsComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", dataset.id); }); } diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts index 0110adf19..ffcf3740b 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts @@ -425,6 +425,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "xml", id); }); } @@ -436,6 +437,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "docx", id); }); } @@ -447,6 +449,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "pdf", id); }); } @@ -457,6 +460,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const blob = new Blob([response.body], { type: 'application/json' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "json", id); }, async error => { this.onExportCallbackError(error); }); @@ -476,6 +480,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", dataset.id); }); } @@ -487,6 +492,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", dataset.id); }); } @@ -499,6 +505,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", dataset.id); }); } diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-dataset-activity/recent-edited-dataset-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-dataset-activity/recent-edited-dataset-activity.component.ts index 1eb17a363..6f51f4a54 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-dataset-activity/recent-edited-dataset-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-dataset-activity/recent-edited-dataset-activity.component.ts @@ -27,6 +27,7 @@ import { Location } from '@angular/common'; import { LockService } from '@app/core/services/lock/lock.service'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { HttpClient } from '@angular/common/http'; +import {ConfigurationService} from "@app/core/services/configuration/configuration.service"; @Component({ selector: 'app-recent-edited-dataset-activity', @@ -61,7 +62,8 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen private location: Location, private lockService: LockService, private httpClient: HttpClient, - private matomoService: MatomoService + private matomoService: MatomoService, + private configurationService: ConfigurationService ) { super(); } @@ -304,6 +306,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", dataset.id); }); } @@ -315,6 +318,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", dataset.id); }); } @@ -327,6 +331,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", dataset.id); }); } diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts index ae9bfc46d..4ad783614 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts @@ -369,6 +369,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "xml", id); }); } @@ -380,6 +381,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "docx", id); }); } @@ -391,6 +393,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "pdf", id); }); } @@ -401,6 +404,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O const blob = new Blob([response.body], { type: 'application/json' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "json", id); }, async error => { this.onExportCallbackError(error); }); diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index df98a21bd..33951bea3 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -957,37 +957,40 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme }); } - downloadPDF(): void { - this.datasetWizardService.downloadPDF(this.downloadDocumentId) + downloadPDF(id: string): void { + this.datasetWizardService.downloadPDF(id) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], {type: 'application/pdf'}); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", id); }); } - downloadDOCX(): void { - this.datasetWizardService.downloadDOCX(this.downloadDocumentId) + downloadDOCX(id: string): void { + this.datasetWizardService.downloadDOCX(id) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], {type: 'application/msword'}); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", id); }); } - downloadXML(): void { - this.datasetWizardService.downloadXML(this.downloadDocumentId) + downloadXML(id: string): void { + this.datasetWizardService.downloadXML(id) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], {type: 'application/xml'}); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", id); }); } diff --git a/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts b/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts index 284dd1a3d..04d6db3d1 100644 --- a/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts @@ -99,6 +99,7 @@ export class DatasetListingItemComponent extends BaseComponent implements OnInit const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", dataset.id); }); } @@ -110,6 +111,7 @@ export class DatasetListingItemComponent extends BaseComponent implements OnInit const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", dataset.id); }); } @@ -122,6 +124,7 @@ export class DatasetListingItemComponent extends BaseComponent implements OnInit const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", dataset.id); }); } diff --git a/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts b/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts index c665817f2..750f98a47 100644 --- a/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts +++ b/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts @@ -340,6 +340,7 @@ export class DatasetOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "pdf", id); }); } @@ -351,6 +352,7 @@ export class DatasetOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "docx", id); }); } @@ -362,6 +364,7 @@ export class DatasetOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('datasets', "xml", id); }); } diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index 4c6a8bc76..f5ca821cb 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -699,6 +699,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements const blob = new Blob([response.body], { type: 'application/xml' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "xml", id); }); } @@ -709,6 +710,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements const blob = new Blob([response.body], { type: 'application/msword' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "docx", id); }); } @@ -719,6 +721,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements const blob = new Blob([response.body], { type: 'application/pdf' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "pdf", id); }); } @@ -729,6 +732,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements const blob = new Blob([response.body], { type: 'application/json' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "json", id); }, async error => { this.onExportCallbackError(error); }); diff --git a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts index c6e72d002..aa1830664 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts @@ -226,6 +226,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "xml", id); }); } @@ -237,6 +238,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "docx", id); }); } @@ -248,6 +250,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "pdf", id); }); } @@ -258,6 +261,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { const blob = new Blob([response.body], { type: 'application/json' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "json", id); }, async error => { this.onExportCallbackError(error); }); diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index 0778658bf..91b68dbcb 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -343,6 +343,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "xml", id); }); } @@ -354,6 +355,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "docx", id); }); } @@ -365,6 +367,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "pdf", id); }); } @@ -375,6 +378,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { const blob = new Blob([complete.body], { type: 'application/json' }); const filename = this.getFilenameFromContentDispositionHeader(complete.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); + this.matomoService.trackDownload('dmps', "json", id); }, async error => { this.onExportCallbackError(error); });