Skip to content

Commit

Permalink
feat: added and updated index export tracking (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Oct 17, 2024
1 parent 539e30d commit 046dca3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
15 changes: 9 additions & 6 deletions src/common/analytics/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ export enum EVENT_NAME {
ENTITY_TABLE_PAGINATED = "entity_table_paginated",
ENTITY_TABLE_SORTED = "entity_table_sorted",
FILTER_SELECTED = "filter_selected",
INDEX_ANALYZE_IN_TERRA_REQUESTED = "index_analyze_in_terra_requested",
INDEX_FILE_MANIFEST_REQUESTED = "index_file_manifest_requested",
}

/**
* Set of analytics event parameters.
*/
export enum EVENT_PARAM {
CATALOG = "catalog",
COLUMN_NAME = "column_name",
CURRENT_QUERY = "current_query",
ENTITY_NAME = "entity_name",
FILTER_NAME = "filter_name",
FILTER_VALUE = "filter_value",
INDEX = "index",
PAGINATION_DIRECTION = "pagination_direction",
SORT_DIRECTION = "sort_direction",
TOOL_NAME = "tool_name",
Expand All @@ -49,9 +48,7 @@ export enum SORT_DIRECTION {
*/
export type EventParams = {
[EVENT_NAME.BULK_DOWNLOAD_REQUESTED]: {
[EVENT_PARAM.CATALOG]: string;
[EVENT_PARAM.CURRENT_QUERY]: string;
[EVENT_PARAM.INDEX]: string;
[EVENT_PARAM.ENTITY_NAME]: string;
[EVENT_PARAM.TOOL_NAME]: string;
};
[EVENT_NAME.ENTITY_SELECTED]: { [EVENT_PARAM.ENTITY_NAME]: string };
Expand All @@ -68,4 +65,10 @@ export type EventParams = {
[EVENT_PARAM.FILTER_NAME]: string;
[EVENT_PARAM.FILTER_VALUE]: string;
};
[EVENT_NAME.INDEX_ANALYZE_IN_TERRA_REQUESTED]: {
[EVENT_PARAM.ENTITY_NAME]: string;
};
[EVENT_NAME.INDEX_FILE_MANIFEST_REQUESTED]: {
[EVENT_PARAM.ENTITY_NAME]: string;
};
};
16 changes: 9 additions & 7 deletions src/common/analytics/readme-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ See below a list of the currently available events.

### GA4 Event Inventory

| Event | Parameters | Description |
| ------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- |
| `bulk_download_requested` | `catalog`, `current_query`, `entity_type`, `index`, `tool_name` | Runs when the HCA-DCP "Request curl command" button is selected |
| `entity_selected` | `entity_name` | Runs when an entity (tab) is selected |
| `entity_table_paginated` | `entity_name`, `pagination_directed` | Runs when the page forward/backwards buttons are clicked |
| `entity_table_sorted` | `entity_name`, `column_name`, `sort_direction` | Runs each time a column in the entity table is sorted |
| `filter_selected` | `filter_name`, `filter_value` | Runs each time a filter is selected |
| Event | Parameters | Description |
| ---------------------------------- | ---------------------------------------------- | -------------------------------------------------------------- |
| `bulk_download_requested` | `entity_name`, `tool_name` | Runs when the index "Request curl command" button is selected |
| `index_analyze_in_terra_requested` | `entity_name` | Runs when the index "Analyze in Terra" button is selected |
| `index_file_manifest_requested` | `entity_name` | Runs when the index "Request File Manifest" button is selected |
| `entity_selected` | `entity_name` | Runs when an entity (tab) is selected |
| `entity_table_paginated` | `entity_name`, `pagination_direction` | Runs when the page forward/backwards buttons are clicked |
| `entity_table_sorted` | `entity_name`, `column_name`, `sort_direction` | Runs each time a column in the entity table is sorted |
| `filter_selected` | `filter_name`, `filter_value` | Runs each time a filter is selected |
35 changes: 20 additions & 15 deletions src/components/Export/common/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@ import { EVENT_NAME, EVENT_PARAM } from "../../../common/analytics/entities";

/**
* Executes event tracking for bulk download.
* @param index - Index.
* @param entity_name - Entity (tab) name.
* @param toolName - Tool name.
* @param requestParams - Request params.
*/
export function bulkDownloadTracking(
index: string,
toolName: string,
requestParams?: URLSearchParams
entity_name: string,
toolName: string
): void {
if (!requestParams) {
return;
}
// Grab catalog and current query from the request params.
const catalog = requestParams.get("catalog") as string; // Catalog will be defined.
const currentQuery = requestParams.get("filters") as string; // Filters will be defined.

// Track the bulk download requested event.
track(EVENT_NAME.BULK_DOWNLOAD_REQUESTED, {
[EVENT_PARAM.CATALOG]: catalog,
[EVENT_PARAM.CURRENT_QUERY]: currentQuery,
[EVENT_PARAM.INDEX]: index,
[EVENT_PARAM.ENTITY_NAME]: entity_name,
[EVENT_PARAM.TOOL_NAME]: toolName,
});
}

export function fileManifestTracking(entity_name: string): void {
// Track the file manifest requested event.
console.log("tracking file manifest requested event");
console.log(entity_name);
track(EVENT_NAME.INDEX_FILE_MANIFEST_REQUESTED, {
[EVENT_PARAM.ENTITY_NAME]: entity_name,
});
}

export function exportToTerraTracking(entity_name: string): void {
// Track the export to terra event.
track(EVENT_NAME.INDEX_ANALYZE_IN_TERRA_REQUESTED, {
[EVENT_PARAM.ENTITY_NAME]: entity_name,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import React, { ElementType, useState } from "react";
import { MANIFEST_DOWNLOAD_FORMAT } from "../../../../apis/azul/common/entities";
import { Filters } from "../../../../common/entities";
import { useExploreState } from "../../../../hooks/useExploreState";
import {
FILE_MANIFEST_TYPE,
FileManifestType,
} from "../../../../hooks/useFileManifest/common/entities";
import { FileManifestType } from "../../../../hooks/useFileManifest/common/entities";
import { useFileManifest } from "../../../../hooks/useFileManifest/useFileManifest";
import { useRequestFileManifest } from "../../../../hooks/useFileManifest/useRequestFileManifest";
import { FileLocation } from "../../../../hooks/useRequestFileLocation";
Expand Down Expand Up @@ -35,7 +32,6 @@ export const DownloadCurlCommand = ({
DownloadCurlStart,
DownloadCurlSuccess,
fileManifestState,
fileManifestType,
fileSummaryFacetName,
filters,
formFacet,
Expand All @@ -50,7 +46,6 @@ export const DownloadCurlCommand = ({
const {
exploreState: { tabValue: entityList },
} = useExploreState();
const { requestParams } = fileManifestState;
const { data, isLoading, run } = useFileManifest();
const curlCommand = getBulkDownloadCurlCommand(data, executionEnvironment);
return curlCommand ? (
Expand All @@ -68,12 +63,7 @@ export const DownloadCurlCommand = ({
isLoading={isLoading}
onRequestManifest={(): void => {
// Execute GTM tracking.
track(
fileManifestType,
entityList,
executionEnvironment,
requestParams
);
bulkDownloadTracking(entityList, executionEnvironment);
// Request manifest.
run();
}}
Expand All @@ -98,21 +88,3 @@ function getBulkDownloadCurlCommand(
}
return commandLine[executionEnvironment];
}

/**
* Executes GTM tracking.
* @param fileManifestType - File manifest type.
* @param index - Index.
* @param toolName - Execution environment.
* @param requestParams - Request params.
*/
function track(
fileManifestType: FileManifestType,
index: string,
toolName: string,
requestParams?: URLSearchParams
): void {
if (fileManifestType === FILE_MANIFEST_TYPE.BULK_DOWNLOAD) {
bulkDownloadTracking(index, toolName, requestParams);
}
}
12 changes: 11 additions & 1 deletion src/components/Export/components/ExportToTerra/exportToTerra.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { ElementType } from "react";
import { Filters } from "../../../../common/entities";
import { useExploreState } from "../../../../hooks/useExploreState";
import { useExportToTerraResponseURL } from "../../../../hooks/useExportToTerraResponseURL";
import { FileManifestType } from "../../../../hooks/useFileManifest/common/entities";
import { useFileManifest } from "../../../../hooks/useFileManifest/useFileManifest";
import { useRequestFileManifest } from "../../../../hooks/useFileManifest/useRequestFileManifest";
import { FileManifestState } from "../../../../providers/fileManifestState";
import { FormFacet, ManifestDownloadFormat } from "../../common/entities";
import { exportToTerraTracking } from "../../common/tracking";
import { ExportToTerraNotStarted } from "./components/ExportToTerraNotStarted/exportToTerraNotStarted";
import { ExportToTerraReady } from "./components/ExportToTerraReady/exportToTerraReady";

Expand Down Expand Up @@ -33,6 +35,9 @@ export const ExportToTerra = ({
manifestDownloadFormat,
manifestDownloadFormats,
}: ExportToTerraProps): JSX.Element => {
const {
exploreState: { tabValue: entityList },
} = useExploreState();
useRequestFileManifest(manifestDownloadFormat, filters, fileSummaryFacetName);
const { requestParams } = fileManifestState;
const { data, isLoading, run } = useFileManifest();
Expand All @@ -50,7 +55,12 @@ export const ExportToTerra = ({
formFacet={formFacet}
isLoading={isLoading}
manifestDownloadFormats={manifestDownloadFormats}
onRequestManifest={run}
onRequestManifest={(): void => {
// Execute GA tracking
exportToTerraTracking(entityList);
// Request manifest
run();
}}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { ElementType } from "react";
import { MANIFEST_DOWNLOAD_FORMAT } from "../../../../apis/azul/common/entities";
import { Filters } from "../../../../common/entities";
import { useExploreState } from "../../../../hooks/useExploreState";
import { FileManifestType } from "../../../../hooks/useFileManifest/common/entities";
import { useFileManifest } from "../../../../hooks/useFileManifest/useFileManifest";
import { useRequestFileManifest } from "../../../../hooks/useFileManifest/useRequestFileManifest";
import { FileLocation } from "../../../../hooks/useRequestFileLocation";
import { FileManifestState } from "../../../../providers/fileManifestState";
import { FormFacet } from "../../common/entities";
import { fileManifestTracking } from "../../common/tracking";
import { ManifestDownloadNotStarted } from "./components/ManifestDownloadNotStarted/manifestDownloadNotStarted";
import { ManifestDownloadReady } from "./components/ManifestDownloadReady/manifestDownloadReady";

Expand Down Expand Up @@ -35,6 +37,9 @@ export const ManifestDownload = ({
filters,
fileSummaryFacetName
);
const {
exploreState: { tabValue: entityList },
} = useExploreState();
const { data, isLoading, run } = useFileManifest();
const manifestURL = getManifestDownloadURL(data);
return manifestURL ? (
Expand All @@ -49,7 +54,10 @@ export const ManifestDownload = ({
fileManifestState={fileManifestState}
formFacet={formFacet}
isLoading={isLoading}
onRequestManifest={run}
onRequestManifest={(): void => {
fileManifestTracking(entityList);
run();
}}
/>
);
};
Expand Down

0 comments on commit 046dca3

Please sign in to comment.