Skip to content

Commit de6c47f

Browse files
Added GA/GTM for Terra functionality. Resolves #1137. (#1141)
1 parent 3f9c464 commit de6c47f

File tree

8 files changed

+92
-6
lines changed

8 files changed

+92
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<a class="fontsize-s link"
22
href="{{link}}"
3+
(click)="onClick($event)"
34
[attr.target]="targetBlank ? '_blank' : null">{{link}}</a>

spa/src/app/files/hca-get-data/display-data-link/display-data-link.component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
// Core dependencies
9-
import { Component, Input } from "@angular/core";
9+
import { Component, EventEmitter, Input, Output } from "@angular/core";
1010

1111
@Component({
1212
selector: "display-data-link",
@@ -18,4 +18,17 @@ export class DisplayDataLinkComponent {
1818
// Inputs
1919
@Input() link: string;
2020
@Input() targetBlank: boolean;
21+
22+
// Outputs
23+
@Output() dataLinkClicked = new EventEmitter<MouseEvent>();
24+
25+
/**
26+
* Emit click event on click of anchor tag.
27+
*
28+
* @param {MouseEvent} event
29+
*/
30+
public onClick(event: MouseEvent) {
31+
32+
this.dataLinkClicked.emit(event);
33+
}
2134
}

spa/src/app/files/hca-get-data/hca-export-to-terra/hca-export-to-terra.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h4 class="fontsize-m semi-bold">Select Export File Types</h4>
77
<ng-container *ngIf="getFileTypeSummaries(state.manifestDownloadFileSummary).length > 0">
88
<file-type-summary-list [selectedSearchTermNames]="state.selectedSearchTermNames"
99
[fileTypeSummaries]="getFileTypeSummaries(state.manifestDownloadFileSummary)"></file-type-summary-list>
10-
<button class="button primary" type="button" (click)="onExportToTerra()" [disabled]="!isAnyFileFormatSelected(state.selectedSearchTerms)">Request Export</button>
10+
<button class="button primary" type="button" (click)="onExportToTerra(state.selectedSearchTerms)" [disabled]="!isAnyFileFormatSelected(state.selectedSearchTerms)">Request Export</button>
1111
</ng-container>
1212
</ng-container>
1313
<ng-container *ngIf="isRequestInProgress(state.exportToTerraStatus)">
@@ -24,8 +24,10 @@ <h4 class="fontsize-m semi-bold">Your Export is Ready</h4>
2424
</hca-get-data-panel>
2525
<div class="download">
2626
<display-data-link [link]="getTerraServiceUrl(state.exportToTerraUrl)"
27-
[targetBlank]="true"></display-data-link>
28-
<copy-to-clipboard [copyToClipboardLink]="getTerraServiceUrl(state.exportToTerraUrl)"></copy-to-clipboard>
27+
[targetBlank]="true"
28+
(dataLinkClicked)="onDataLinkClicked(getTerraServiceUrl(state.exportToTerraUrl))"></display-data-link>
29+
<copy-to-clipboard [copyToClipboardLink]="getTerraServiceUrl(state.exportToTerraUrl)"
30+
(copyClicked)="onDataLinkCopied(getTerraServiceUrl(state.exportToTerraUrl))"></copy-to-clipboard>
2931
</div>
3032
</ng-container>
3133
<ng-container *ngIf="isRequestFailed(state.exportToTerraStatus)">

spa/src/app/files/hca-get-data/hca-export-to-terra/hca-export-to-terra.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { CopyToClipboardComponent } from "../../../shared/copy-to-clipboard/copy
3030
import { DisplayDataLinkComponent } from "../display-data-link/display-data-link.component";
3131
import { HCAGetDataPanelComponent } from "../hca-get-data-panel/hca-get-data-panel.component";
3232
import { HCAExportToTerraComponent } from "./hca-export-to-terra.component";
33+
import { GTMService } from "../../../shared/gtm/gtm.service";
3334

3435
describe("HCAExportToTerraComponent", () => {
3536

@@ -88,6 +89,12 @@ describe("HCAExportToTerraComponent", () => {
8889
"requestFileManifestUrl"
8990
])
9091
},
92+
{
93+
provide: GTMService,
94+
useValue: jasmine.createSpyObj("GTMService", [
95+
"trackEvent"
96+
])
97+
},
9198
{
9299
provide: HttpClient,
93100
useValue: jasmine.createSpyObj("HttpClient", [

spa/src/app/files/hca-get-data/hca-export-to-terra/hca-export-to-terra.component.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import { SearchTerm } from "../../search/search-term.model";
2626
import { ExportToTerraStatus } from "../../shared/export-to-terra-status.model";
2727
import { TerraService } from "../../shared/terra.service";
2828
import { HCAExportToTerraState } from "./hca-export-to-terra.state";
29+
import { SearchTermService } from "../../shared/search-term.service";
30+
import { GTMService } from "../../../shared/gtm/gtm.service";
31+
import { GACategory } from "../../../shared/gtm/ga-category.model";
32+
import { GAAction } from "../../../shared/gtm/ga-action.model";
33+
import { GADimension } from "../../../shared/gtm/ga-dimension.model";
34+
import { ReleaseName } from "../../releases/release-name.model";
35+
import { ToolName } from "../../shared/tool-name.model";
2936

3037
@Component({
3138
selector: "hca-export-to-terra",
@@ -44,11 +51,15 @@ export class HCAExportToTerraComponent implements OnDestroy, OnInit {
4451
/**
4552
*
4653
* @param {ConfigService} configService
54+
* @param {GTMService} gtmService
55+
* @param {SearchTermService} searchTermService
4756
* @param {TerraService} terraService
4857
* @param {Store<AppState>} store
4958
* @param {Window} window
5059
*/
5160
constructor(private configService: ConfigService,
61+
private gtmService: GTMService,
62+
private searchTermService: SearchTermService,
5263
private terraService: TerraService,
5364
private store: Store<AppState>,
5465
@Inject("Window") window: Window) {
@@ -135,10 +146,41 @@ export class HCAExportToTerraComponent implements OnDestroy, OnInit {
135146
return this.terraService.isExportToTerraRequestNotStarted(status);
136147
}
137148

149+
/**
150+
* Track click on Terra data link.
151+
*
152+
* @param {string} exportToTerraUrl
153+
*/
154+
public onDataLinkClicked(exportToTerraUrl: string) {
155+
156+
this.gtmService.trackEvent(GACategory.RESULT_SET, GAAction.DATA_LINK, exportToTerraUrl, {
157+
[GADimension.TOOL_NAME]: ToolName.TERRA
158+
});
159+
}
160+
161+
/**
162+
* Track click on copy of Terra data link.
163+
*
164+
* @param {string} exportToTerraUrl
165+
*/
166+
public onDataLinkCopied(exportToTerraUrl: string) {
167+
168+
this.gtmService.trackEvent(GACategory.RESULT_SET, GAAction.COPY_TO_CLIPBOARD, exportToTerraUrl, {
169+
[GADimension.TOOL_NAME]: ToolName.TERRA
170+
});
171+
}
172+
138173
/**
139174
* Dispatch action to export to Terra.
175+
*
176+
* @param {SearchTerm[]} selectedSearchTerms
140177
*/
141-
public onExportToTerra() {
178+
public onExportToTerra(selectedSearchTerms: SearchTerm[]) {
179+
180+
const query = this.searchTermService.marshallSearchTerms(selectedSearchTerms);
181+
this.gtmService.trackEvent(GACategory.RESULT_SET, GAAction.EXPORT, query, {
182+
[GADimension.TOOL_NAME]: ToolName.TERRA
183+
});
142184
this.store.dispatch(new ExportToTerraRequestAction());
143185
}
144186

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+
* Set of tools.
6+
*/
7+
8+
export enum ToolName {
9+
"TERRA" = "Terra",
10+
"MANIFEST" = "Manifest",
11+
"MATRIX" = "Matrix"
12+
}

spa/src/app/shared/copy-to-clipboard/copy-to-clipboard.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
// Core dependencies
9-
import { Component, Input } from "@angular/core";
9+
import { Component, EventEmitter, Input, Output } from "@angular/core";
1010
import { BehaviorSubject, interval } from "rxjs";
1111
import { take } from "rxjs/internal/operators";
1212

@@ -22,6 +22,9 @@ export class CopyToClipboardComponent {
2222

2323
// Inputs
2424
@Input() copyToClipboardLink: string;
25+
26+
// Outputs
27+
@Output() copyClicked = new EventEmitter<any>();
2528

2629
/**
2730
* Returns true, when copy to clipboard is successful.
@@ -41,6 +44,10 @@ export class CopyToClipboardComponent {
4144
*/
4245
public onCopy(event: MouseEvent) {
4346

47+
// Let parent components know link has been copied
48+
this.copyClicked.emit(event);
49+
50+
// Update UI to indicate link has been copied
4451
this.copied.next(true);
4552
this.resetCopied();
4653
event.stopPropagation();

spa/src/app/shared/gtm/ga-action.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
export enum GAAction {
9+
"DATA_LINK" = "Data Link",
910
"DOWNLOAD" = "Download",
1011
"EXPORT" = "Export",
12+
"COPY_TO_CLIPBOARD" = "Copy to Clipboard",
1113
"VISUALIZE" = "Visualize"
1214
}

0 commit comments

Comments
 (0)