#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.
This commit is contained in:
Konstantina Galouni 2023-01-20 19:02:12 +02:00
parent a1dbd72bce
commit 1d45bddeca
11 changed files with 58 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -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);
});

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});