Skip to content

Commit 3ed9e66

Browse files
MillenniumFalconMechanicNoopDog
authored andcommitted
Added GA dimensions to download/visualize events. Resolves #1067. (#1120)
1 parent d6357d4 commit 3ed9e66

File tree

8 files changed

+85
-38
lines changed

8 files changed

+85
-38
lines changed

spa/src/app/files/releases/release-files-modal/release-files-modal.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h4 class="fontsize-l" [ngClass]="{'singleDataset': state.singleDataset}">
2121
<mat-table [dataSource]="state.releaseDataset.files">
2222
<ng-container matColumnDef="download">
2323
<mat-cell *matCellDef="let element" class="download fontsize-xxs">
24-
<a [href]="getReleaseFileUrl(element.url)" (click)="trackDownload(state.releaseDataset.projectShortname, element)"></a>
24+
<a [href]="getReleaseFileUrl(element.url)" (click)="trackDownload(state.releaseDataset, element)"></a>
2525
</mat-cell>
2626
</ng-container>
2727
<ng-container matColumnDef="description">

spa/src/app/files/releases/release-files-modal/release-files-modal.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ import { ReleaseFilesModalState } from "./release-files-modal.state";
3636
import { Release } from "../release.model";
3737
import { ReleaseName } from "../release-name.model";
3838
import { ReleaseFileView } from "../release-file-view.model";
39-
import { ReleaseService } from "../../shared/release.service";
4039
import { GTMService } from "../../../shared/gtm/gtm.service";
40+
import { GACategory } from "../../../shared/gtm/ga-category.model";
41+
import { GADimension } from "../../../shared/gtm/ga-dimension.model";
42+
import { GAAction } from "../../../shared/gtm/ga-action.model";
43+
import { ReleaseService } from "../../shared/release.service";
4144

4245
@Component({
4346
selector: "release-files-modal",
@@ -122,9 +125,14 @@ export class ReleaseFilesModalComponent implements OnDestroy, OnInit {
122125
* @param {string} projectShortname
123126
* @param {ReleaseFileView} releaseFile
124127
*/
125-
public trackDownload(projectShortname: string, releaseFile: ReleaseFileView): void {
128+
public trackDownload(releaseDatasetView: ReleaseDatasetView, releaseFile: ReleaseFileView): void {
126129

127-
this.gtmService.trackDownload(projectShortname, releaseFile.url);
130+
this.gtmService.trackEvent(GACategory.DATASET, GAAction.DOWNLOAD, this.getReleaseFileUrl(releaseFile.url), {
131+
[GADimension.DATASET_NAME]: releaseDatasetView.datasetId,
132+
[GADimension.FILE_TYPE]: releaseFile.type,
133+
[GADimension.FILE_EXTENSION]: releaseFile.extension,
134+
[GADimension.FILE_NAME]: releaseFile.url
135+
});
128136
}
129137

130138
/**

spa/src/app/files/releases/release-table/release-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h2 class="fontsize-xl">{{organView.organ}}</h2>
6969
[tooltipDisabled]="false"
7070
[tooltipPosition]="'above'">
7171
<a href={{visualization.url}} target="_blank"
72-
rel="noopener noreferrer" (click)="trackExternalLink(element.projectShortname, visualization.url)">{{visualization.title}}</a>
72+
rel="noopener noreferrer" (click)="trackExternalLink(element, visualization)">{{visualization.title}}</a>
7373
</hca-tooltip>
7474
</ng-container>
7575
</mat-cell>

spa/src/app/files/releases/release-table/release-table.component.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { SetReleaseReferrerAction } from "../../_ngrx/release/set-release-referr
1515
import { ReleaseOrganView } from "../release-organ-view.model";
1616
import { SetReleaseFilesReferrerAction } from "../../_ngrx/release/set-release-files-referrer.action";
1717
import { GTMService } from "../../../shared/gtm/gtm.service";
18+
import { ReleaseVisualization } from "../release-visualization.model";
19+
import { ReleaseDatasetView } from "../release-dataset-view.model";
20+
import { GACategory } from "../../../shared/gtm/ga-category.model";
21+
import { GAAction } from "../../../shared/gtm/ga-action.model";
22+
import { GADimension } from "../../../shared/gtm/ga-dimension.model";
1823

1924
@Component({
2025
selector: "release-table",
@@ -61,7 +66,8 @@ export class ReleaseTableComponent {
6166

6267
/**
6368
* Update state to indicate that the release files modal should return to the release page and not a project-specific
64-
* release tab.
69+
* release tab.release-files-modal.component.html
70+
6571
*/
6672
public setReleaseFilesReferrer() {
6773

@@ -85,11 +91,14 @@ export class ReleaseTableComponent {
8591
/**
8692
* Track click on link to external visualization tool.
8793
*
88-
* @param {string} projectShortname
89-
* @param {string} url
94+
* @param {ReleaseDatasetView} releaseDatasetView
95+
* @param {ReleaseVisualization} visualization
9096
*/
91-
public trackExternalLink(projectShortname: string, url: string): void {
97+
public trackExternalLink(releaseDatasetView: ReleaseDatasetView, visualization: ReleaseVisualization): void {
9298

93-
this.gtmService.trackExternalLink(projectShortname, url);
99+
this.gtmService.trackEvent(GACategory.DATASET, GAAction.VISUALIZE, visualization.url, {
100+
[GADimension.DATASET_NAME]: releaseDatasetView.datasetId,
101+
[GADimension.TOOL_NAME]: visualization.title
102+
});
94103
}
95104
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Human Cell Atlas
3+
* https://www.humancellatlas.org/
4+
*
5+
* Possible values of Google Analytic actions.
6+
*/
7+
8+
export enum GAAction {
9+
"DOWNLOAD" = "Download",
10+
"EXPORT" = "Export",
11+
"VISUALIZE" = "Visualize"
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Human Cell Atlas
3+
* https://www.humancellatlas.org/
4+
*
5+
* Possible values of Google Analytic categories.
6+
*/
7+
8+
export enum GACategory {
9+
"DATASET" = "Dataset",
10+
"RESULT_SET" = "Result Set"
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Human Cell Atlas
3+
* https://www.humancellatlas.org/
4+
*
5+
* Possible values of Google Analytic dimensions.
6+
*/
7+
8+
export enum GADimension {
9+
"DATASET_NAME" = "datasetName",
10+
"FILE_EXTENSION" = "fileExtension",
11+
"FILE_NAME" = "fileName",
12+
"FILE_TYPE" = "fileType",
13+
"QUERY" = "query",
14+
"TOOL_NAME" = "toolName"
15+
}

spa/src/app/shared/gtm/gtm.service.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// Core dependencies
99
import { Inject, Injectable } from "@angular/core";
1010

11+
// App dependencies
12+
import { GACategory } from "./ga-category.model";
13+
import { GAAction } from "./ga-action.model";
14+
1115
@Injectable()
1216
export class GTMService {
1317

14-
private EVENT_NAME_DOWNLOAD = "Download";
15-
private EVENT_NAME_VISUALIZE = "Visualize";
16-
1718
/**
1819
* @param {Window} window
1920
*/
@@ -23,29 +24,17 @@ export class GTMService {
2324
/**
2425
* Send custom "download" GTM event.
2526
*
26-
* @param {string} action
27-
* @param {string} label
28-
*/
29-
public trackDownload(action: string, label: string): void {
30-
31-
if ( !this.isTracking() ) {
32-
return;
33-
}
34-
this.trackEvent(this.EVENT_NAME_DOWNLOAD, action, label);
35-
}
36-
37-
/**
38-
* Send custom "download" GTM event.
39-
*
40-
* @param {string} action
27+
* @param {GACategory} category
28+
* @param {GAAction} action
4129
* @param {string} label
30+
* @param {{}} dimensions
4231
*/
43-
public trackExternalLink(action: string, label: string): void {
32+
public trackEvent(category: GACategory, action: GAAction, label: string, dimensions: {} = {}): void {
4433

4534
if ( !this.isTracking() ) {
4635
return;
4736
}
48-
this.trackEvent(this.EVENT_NAME_VISUALIZE, action, label);
37+
this.sendToGA(category, action, label, dimensions);
4938
}
5039

5140
/**
@@ -63,22 +52,25 @@ export class GTMService {
6352
*/
6453
private isTracking(): boolean {
6554

66-
return !!this.getDataLayer();
55+
// return !!this.getDataLayer();
56+
return true;
6757
}
6858

6959
/**
70-
* Track the specified event.
60+
* Add event to data layer, triggering the configured GTM tag (and in turn sending tracking event to GA).
7161
*
72-
* @param {string} eventName
73-
* @param {string} label
62+
* @param {GACategory} category - GTM "event" variable, used as "Category" value for GA
63+
* @param {GAAction} action - used as "Action" value for GA
64+
* @param {string} label - used as "Label" value for GA
65+
* @param {{}} dimensions - additional variables that correspond to GTM variables and in turn, GA dimensions
7466
*/
75-
private trackEvent(eventName: string, action: string, label: string): void {
67+
private sendToGA(category: GACategory, action: GAAction, label: string, dimensions: {} = {}): void {
7668

77-
const eventConfig = {
78-
event: eventName,
69+
const eventConfig = Object.assign({
70+
event: category,
7971
eventAction: action,
8072
eventLabel: label
81-
};
73+
}, dimensions);
8274
this.getDataLayer().push(eventConfig);
8375
}
8476
}

0 commit comments

Comments
 (0)