Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Track analytics for task file link clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Oct 18, 2023
1 parent b430b32 commit 6172ae4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/analytics/task/useTaskAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ type Action =
| { name: "Click See History Button" }
| { name: "Click Trace Link" }
| { name: "Click Trace Metrics Link" }
| { name: "Submit Previous Commit Selector"; type: CommitType };
| { name: "Submit Previous Commit Selector"; type: CommitType }
| {
name: "Click Task File Link";
parsleyAvailable: boolean;
fileName: string;
};

export const useTaskAnalytics = () => {
const { id } = useParams<{ id: string }>();
Expand Down
22 changes: 19 additions & 3 deletions src/pages/task/taskTabs/FileTable/GroupedFileTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useRef } from "react";
import { useMemo, useRef } from "react";
import styled from "@emotion/styled";
import { useLeafyGreenTable, LGColumnDef } from "@leafygreen-ui/table/new";
import { Subtitle } from "@leafygreen-ui/typography";
import { useTaskAnalytics } from "analytics";
import { StyledLink } from "components/styles";
import { BaseTable } from "components/Table/BaseTable";
import { size } from "constants/tokens";
Expand All @@ -10,7 +11,10 @@ import { GroupedFiles } from "../types";

type GroupedFilesFile = Unpacked<GroupedFiles["files"]>;

const columns: LGColumnDef<GroupedFilesFile>[] = [
// taskAnalytics is the return value of useTaskAnalytics
const columns = (
taskAnalytics: ReturnType<typeof useTaskAnalytics>
): LGColumnDef<GroupedFilesFile>[] => [
{
accessorKey: "name",
header: "Name",
Expand All @@ -21,6 +25,13 @@ const columns: LGColumnDef<GroupedFilesFile>[] = [
href={value.row.original.link}
data-cy="file-link"
target="_blank"
onClick={() => {
taskAnalytics.sendEvent({
name: "Click Task File Link",
parsleyAvailable: false,
fileName: value.getValue(),
});
}}
>
{value.getValue()}
</StyledLink>
Expand All @@ -37,11 +48,16 @@ const GroupedFileTable: React.FC<GroupedFileTableProps> = ({
taskName,
}) => {
const tableContainerRef = useRef<HTMLDivElement>(null);
const taskAnalytics = useTaskAnalytics();

const memoizedColumns = useMemo(
() => columns(taskAnalytics),
[taskAnalytics]
);
const table = useLeafyGreenTable<GroupedFilesFile>({
containerRef: tableContainerRef,
data: files,
columns,
columns: memoizedColumns,
});

return (
Expand Down

0 comments on commit 6172ae4

Please sign in to comment.