diff --git a/src/common/analytics/entities.ts b/src/common/analytics/entities.ts index 2b95deeb..0f711227 100644 --- a/src/common/analytics/entities.ts +++ b/src/common/analytics/entities.ts @@ -9,6 +9,7 @@ export enum EVENT_NAME { ENTITY_SELECTED = "entity_selected", ENTITY_TABLE_PAGINATED = "entity_table_paginated", ENTITY_TABLE_SORTED = "entity_table_sorted", + FILE_DOWNLOADED = "file_downloaded", FILTER_SELECTED = "filter_selected", INDEX_ANALYZE_IN_TERRA_REQUESTED = "index_analyze_in_terra_requested", INDEX_FILE_MANIFEST_REQUESTED = "index_file_manifest_requested", @@ -23,6 +24,8 @@ export enum EVENT_PARAM { FILTER_NAME = "filter_name", FILTER_VALUE = "filter_value", PAGINATION_DIRECTION = "pagination_direction", + RELATED_ENTITY_ID = "related_entity_id", + RELATED_ENTITY_NAME = "related_entity_name", SORT_DIRECTION = "sort_direction", TOOL_NAME = "tool_name", } @@ -61,6 +64,11 @@ export type EventParams = { [EVENT_PARAM.COLUMN_NAME]: string; [EVENT_PARAM.SORT_DIRECTION]: SORT_DIRECTION; }; + [EVENT_NAME.FILE_DOWNLOADED]: { + [EVENT_PARAM.ENTITY_NAME]: string; + [EVENT_PARAM.RELATED_ENTITY_ID]: string; + [EVENT_PARAM.RELATED_ENTITY_NAME]: string; + }; [EVENT_NAME.FILTER_SELECTED]: { [EVENT_PARAM.FILTER_NAME]: string; [EVENT_PARAM.FILTER_VALUE]: string; diff --git a/src/components/Export/common/tracking.ts b/src/components/Export/common/tracking.ts index 1522ebc9..4d32a6d7 100644 --- a/src/components/Export/common/tracking.ts +++ b/src/components/Export/common/tracking.ts @@ -38,3 +38,22 @@ export function exportToTerraTracking(entity_name: string): void { [EVENT_PARAM.ENTITY_NAME]: entity_name, }); } + +/** + * Executes event tracking for individual file downloads + * @param entity_name - The name of the file downloaded. + * @param related_entity_id - The ID of the file's dataset / project + * @param related_entity_name -The name of the file's dataset / project + */ +export function trackFileDownload( + entity_name: string, + related_entity_id: string, + related_entity_name: string +): void { + // Track the file downloaded event. + track(EVENT_NAME.FILE_DOWNLOADED, { + [EVENT_PARAM.ENTITY_NAME]: entity_name, + [EVENT_PARAM.RELATED_ENTITY_ID]: related_entity_id, + [EVENT_PARAM.RELATED_ENTITY_NAME]: related_entity_name, + }); +} diff --git a/src/components/Index/components/AzulFileDownload/azulFileDownload.tsx b/src/components/Index/components/AzulFileDownload/azulFileDownload.tsx index 4e27cdc0..76837a2d 100644 --- a/src/components/Index/components/AzulFileDownload/azulFileDownload.tsx +++ b/src/components/Index/components/AzulFileDownload/azulFileDownload.tsx @@ -1,9 +1,11 @@ import { Box } from "@mui/material"; import React, { Fragment, useEffect, useRef, useState } from "react"; +import { stringifyValues } from "../../../../common/utils"; import { useFileLocation } from "../../../../hooks/useFileLocation"; import { DownloadIcon } from "../../../common/CustomIcon/components/DownloadIcon/downloadIcon"; import { LoadingIcon } from "../../../common/CustomIcon/components/LoadingIcon/loadingIcon"; import { IconButton } from "../../../common/IconButton/iconButton"; +import { trackFileDownload } from "../../../Export/common/tracking"; import { StyledIconButton } from "./azulFileDownload.styles"; import { AZUL_FILE_DOWNLOAD_TEST_ID, @@ -12,10 +14,16 @@ import { } from "./common/constants"; export interface AzulFileDownloadProps { + entityName?: string; // The name of the file downloaded. + relatedEntityId?: string[]; // An array of IDs of the file's datasets / projects + relatedEntityName?: string[]; // An array of names of the file's datasets / projects url?: string; // Original "file fetch URL" as returned from Azul endpoint. } export const AzulFileDownload = ({ + entityName, + relatedEntityId, + relatedEntityName, url, }: AzulFileDownloadProps): JSX.Element => { const { fileUrl, isLoading, run } = useFileLocation(url); @@ -49,6 +57,11 @@ export const AzulFileDownload = ({ Icon={isLoading ? LoadingIcon : DownloadIcon} onClick={(): void => { setIsRequestPending(true); + trackFileDownload( + entityName ?? "", + stringifyValues(relatedEntityId ?? [""]), + stringifyValues(relatedEntityName ?? [""]) + ); run(); }} size="medium"