Skip to content

Commit f063da6

Browse files
Added tracking of project selection. Resolves #1223. (#1227)
1 parent 6bde019 commit f063da6

File tree

18 files changed

+83
-33
lines changed

18 files changed

+83
-33
lines changed

spa/src/app/files/_ngrx/release/release.selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const selectReleaseByProjectId =
3535
createSelector(selectReleases, (state, props) => {
3636

3737
const release = state.releasesByName.get(props.name);
38-
38+
3939
// Filter down the set of projects in this release to just the project we are looking for
4040
const project = release.projects.find(project => project.entryId === props.projectId);
4141
return Object.assign({}, release, {

spa/src/app/files/_ngrx/search/select-project-id.action.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
import { Action } from "@ngrx/store";
1212

1313
// App dependencies
14+
import { TrackingAction } from "../analytics/tracking.action";
1415
import { FileFacetName } from "../../facet/file-facet/file-facet-name.model";
1516
import { SearchTerm } from "../../search/search-term.model";
1617
import { SearchEntity } from "../../search/search-entity.model";
1718
import { SelectSearchTermAction } from "./select-search-term.action";
19+
import { GAEvent } from "../../../shared/analytics/ga-event.model";
20+
import { GADimension } from "../../../shared/analytics/ga-dimension.model";
21+
import { GAAction } from "../../../shared/analytics/ga-action.model";
22+
import { GAEntityType } from "../../../shared/analytics/ga-entity-type.model";
23+
import { GACategory } from "../../../shared/analytics/ga-category.model";
24+
import { GASource } from "../../../shared/analytics/ga-source.model";
1825

19-
export class SelectProjectIdAction implements Action, SelectSearchTermAction {
26+
export class SelectProjectIdAction implements Action, SelectSearchTermAction, TrackingAction {
2027

2128
public static ACTION_TYPE = "FILE.SEARCH.SELECT_PROJECT_ID";
2229
public readonly type = SelectProjectIdAction.ACTION_TYPE;
@@ -27,11 +34,36 @@ export class SelectProjectIdAction implements Action, SelectSearchTermAction {
2734
* @param {string} projectId
2835
* @param {string} projectShortname
2936
* @param {boolean} selected
37+
* @param {GASource} source
3038
*/
3139
constructor(
3240
public readonly projectId: string,
3341
public readonly projectShortname: string,
34-
public readonly selected = true) {}
42+
public readonly selected = true,
43+
public readonly source: GASource) {}
44+
45+
/**
46+
* Return the cleared age range action as a GA event.
47+
*
48+
* @param {string} currentQuery
49+
* @returns {GAEvent}
50+
*/
51+
public asEvent(currentQuery: string): GAEvent {
52+
53+
return {
54+
category: GACategory.SEARCH,
55+
action: this.selected ? GAAction.SELECT : GAAction.DESELECT,
56+
label: this.projectShortname,
57+
dimensions: {
58+
[GADimension.CURRENT_QUERY]: currentQuery,
59+
[GADimension.ENTITY_ID]: this.projectId,
60+
[GADimension.ENTITY_TYPE]: GAEntityType.FACET,
61+
[GADimension.FACET]: this.facetName,
62+
[GADimension.SOURCE]: this.source,
63+
[GADimension.TERM]: this.projectShortname
64+
}
65+
};
66+
}
3567

3668
/**
3769
* Returns selected project in search term format.

spa/src/app/files/_ngrx/table/table.effects.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("Table Effects", () => {
8080
it(`selectProject$ - projects tab - should set "update table data" flag to false`, () => {
8181

8282
actions = hot("--a-", {
83-
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true)
83+
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true, GASource.SEARCH)
8484
});
8585

8686
const expected = cold("--(bc)", {
@@ -100,7 +100,7 @@ describe("Table Effects", () => {
100100
store.setState(DEFAULT_SAMPLES_STATE);
101101

102102
actions = hot("--a-", {
103-
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true)
103+
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true, GASource.SEARCH)
104104
});
105105

106106
const expected = cold("--(bc)", {
@@ -120,7 +120,7 @@ describe("Table Effects", () => {
120120
store.setState(DEFAULT_FILES_STATE);
121121

122122
actions = hot("--a-", {
123-
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true)
123+
a: new SelectProjectIdAction(PROJECT_1M_NEURONS.id, PROJECT_1M_NEURONS.name, true, GASource.SEARCH)
124124
});
125125

126126
const expected = cold("--(bc)", {

spa/src/app/files/_ngrx/table/table.effects.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,17 @@ export class TableEffects {
222222
selectProject$: Observable<Action> = this.actions$
223223
.pipe(
224224
ofType(SelectProjectIdAction.ACTION_TYPE),
225-
switchMap(() =>
226-
this.store.pipe(
227-
select(selectTableQueryParams),
228-
take(1)
225+
concatMap(action => of(action).pipe(
226+
withLatestFrom(
227+
this.store.pipe(select(selectTableQueryParams)),
228+
this.store.pipe(select(selectPreviousQuery), take(1))
229229
)
230-
),
231-
switchMap((tableQueryParams) => {
230+
)),
231+
switchMap(([action, tableQueryParams, queryWhenActionTriggered]) => {
232+
233+
// Send tracking event.
234+
const event = (action as SelectProjectIdAction).asEvent(queryWhenActionTriggered);
235+
this.gtmService.trackEvent(event);
232236

233237
// Return an array of actions that need to be dispatched - request for file summary and file facets.
234238
return of(

spa/src/app/files/_ngrx/table/view-project-tab.action.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export class ViewProjectTabAction implements Action, TrackingAction {
2222

2323
/**
2424
* @param {GAAction} tabName
25-
* @param {string} projectName
25+
* @param {string} projectId
26+
* @param {string} projectShortname
2627
* @param {string} projectUrl
2728
*/
2829
constructor(public tabName: GAAction,
29-
public projectName: string,
30+
public projectId: string,
31+
public projectShortname: string,
3032
public projectUrl: string) {}
3133

3234
/**
@@ -40,9 +42,10 @@ export class ViewProjectTabAction implements Action, TrackingAction {
4042
return {
4143
category: GACategory.PROJECT,
4244
action: this.tabName,
43-
label: this.projectName,
45+
label: this.projectShortname,
4446
dimensions: {
4547
[GADimension.CURRENT_QUERY]: currentQuery,
48+
[GADimension.ENTITY_ID]: this.projectId,
4649
[GADimension.ENTITY_URL]: this.projectUrl
4750
}
4851
};

spa/src/app/files/hca-search/hca-search.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class HCASearchComponent implements OnInit, OnChanges {
9898
const searchValue = selectedSearchTermOption.option.searchValue;
9999

100100
const action = (searchKey === FileFacetName.PROJECT_ID) ?
101-
new SelectProjectIdAction(searchValue, displayValue) :
101+
new SelectProjectIdAction(searchValue, displayValue, true, GASource.SEARCH) :
102102
new SelectFileFacetTermAction(searchKey, searchValue, true, GASource.SEARCH);
103103
this.store.dispatch(action);
104104

spa/src/app/files/hca-table-projects/hca-table-projects.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { CopyToClipboardComponent } from "../../shared/copy-to-clipboard/copy-to
4747
import { DownloadButtonComponent } from "../../shared/download-button/download-button.component";
4848
import { FileDownloadComponent } from "../../shared/file-download/file-download.component";
4949
import { DEFAULT_FILE_SUMMARY } from "../shared/file-summary.mock";
50+
import { GASource } from "../../shared/analytics/ga-source.model";
5051
import { HCATooltipComponent } from "../../shared/hca-tooltip/hca-tooltip.component";
5152
import { ResponsiveService } from "../../shared/responsive/responsive.service";
5253
import { TableScroll } from "../table-scroll/table-scroll.component";
@@ -320,7 +321,7 @@ describe("HCATableProjectsComponent", () => {
320321

321322
const projectId = PROJECTS_TABLE_MODEL.data[0].entryId;
322323
const projectName = PROJECTS_TABLE_MODEL.data[0].projects[0].projectTitle;
323-
const selectProjectIdAction = new SelectProjectIdAction(projectId, projectName, true);
324+
const selectProjectIdAction = new SelectProjectIdAction(projectId, projectName, true, GASource.SEARCH_RESULTS);
324325

325326
// Confirm store dispatch is called
326327
component.onProjectSelected(projectId, projectName, false);

spa/src/app/files/hca-table-projects/hca-table-projects.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class HCATableProjectsComponent implements OnInit {
182182
*/
183183
public onProjectSelected(projectId: string, projectName: string, selected: boolean) {
184184

185-
this.store.dispatch(new SelectProjectIdAction(projectId, projectName, !selected));
185+
this.store.dispatch(new SelectProjectIdAction(projectId, projectName, !selected, GASource.SEARCH_RESULTS));
186186
}
187187

188188
/**

spa/src/app/files/project-detail/project-detail.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { EntityName } from "../shared/entity-name.model";
3232
import EntitySpec from "../shared/entity-spec";
3333
import { ProjectDetailComponentState } from "./project-detail.component.state";
3434
import { ReleaseService } from "../shared/release.service";
35+
import { GASource } from "../../shared/analytics/ga-source.model";
3536

3637
@Component({
3738
selector: "project-detail",
@@ -104,7 +105,7 @@ export class ProjectDetailComponent {
104105
*/
105106
public onProjectSelected(projectSelected: boolean, projectId: string, projectShortname: string) {
106107

107-
this.store.dispatch(new SelectProjectIdAction(projectId, projectShortname, !projectSelected));
108+
this.store.dispatch(new SelectProjectIdAction(projectId, projectShortname, !projectSelected, GASource.PROJECT));
108109
this.router.navigate(["/projects"]);
109110
}
110111

spa/src/app/files/project-expression-matrices/project-expression-matrices.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class ProjectExpressionMatricesComponent {
4949
this.state$.pipe(
5050
take(1)
5151
).subscribe((state) => {
52-
this.projectAnalyticsService.trackTabView(GAAction.VIEW_MATRICES, state.project.projectShortname);
52+
const project = state.project;
53+
this.projectAnalyticsService.trackTabView(GAAction.VIEW_MATRICES, project.entryId, project.projectShortname);
5354
});
5455
}
5556

0 commit comments

Comments
 (0)