Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WNMGDS-3205] Adds analytics tracking to theme & version dialogs #3424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/docs/src/components/layout/SideNav/ThemeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ import { Button, Dropdown } from '@cmsgov/design-system';
import { FilterDialog } from '../FilterDialog/index';
import { getThemeOptions } from './themeVersionData';
import { setQueryParam } from '../../../helpers/urlUtils';
import { sendFilterAppliedEvent } from '../../../helpers/analytics';
import { getVersionEquivalent } from './themeVersionData';

export interface ThemeVersionDialogProps {
theme: string;
isOpen?: boolean;
version: string;
onExit(...args: any[]): void;
}

export const ThemeVersionDialog = (props: ThemeVersionDialogProps) => {
const [theme, setTheme] = useState(props.theme);

function handleUpdate() {
const currentVersion = getVersionEquivalent(theme, props.theme, props.version);
const filterCategoriesUsed = { theme: theme, version: currentVersion };
const filterCategoriesUsedString = JSON.stringify(filterCategoriesUsed);

sendFilterAppliedEvent({ filterCategoriesUsedString });

if (theme !== props.theme) {
setQueryParam('theme', theme, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const ThemeVersionSection = () => {
</button>
<ThemeDialog
theme={theme}
version={version}
isOpen={themeDialogProps.isOpen}
onExit={() => {
themeDialogProps.closeClick();
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/src/components/layout/SideNav/VersionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from 'react';
import { Button, Dropdown } from '@cmsgov/design-system';
import { FilterDialog } from '../FilterDialog';
import { getVersionOptions, getVersionEquivalent } from './themeVersionData';
import { sendFilterAppliedEvent } from '../../../helpers/analytics';

export interface ThemeVersionDialogProps {
theme: string;
Expand All @@ -14,6 +15,11 @@ export const ThemeVersionDialog = (props: ThemeVersionDialogProps) => {
const [version, setVersion] = useState(props.version);

function handleUpdate() {
const filterCategoriesUsed = { theme: props.theme, version: version };
const filterCategoriesUsedString = JSON.stringify(filterCategoriesUsed);

sendFilterAppliedEvent({ filterCategoriesUsedString });

if (version !== props.version) {
// Since the version changed, we need to navigate to that version of the
// doc site, which is archived under design.cms.gov/v/
Expand Down
11 changes: 11 additions & 0 deletions packages/docs/src/helpers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ export function sendSearchInitiatedEvent(searchTerm: string) {
search_term_type: 'user_initiated',
} as any);
}

export function sendFilterAppliedEvent({
filterCategoriesUsedString,
}: {
filterCategoriesUsedString: string;
}) {
sendLinkEvent({
event_name: 'filters_applied',
filter_categories_used: filterCategoriesUsedString,
} as any);
}