Skip to content

Commit

Permalink
chore: handle siteimprove event
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Sep 27, 2024
1 parent 22c65a7 commit b87ba61
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/components/analytics-siteimprove/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export enum EventCategory {
DETAILS_PAGE = 'Details page'
}

export enum EventAction {
REQUEST_ACCESS = 'Request access'
}

type SiteImproveEventProps = {
category: EventCategory;
action: EventAction;
label?: string | undefined;
};

export const trackSiteImproveEvent =
({ category, action, label }: SiteImproveEventProps) =>
() => {
if (window._sz === undefined) {
// eslint-disable-next-line no-console
console.error('Unable to find Site Improve event library.');
}

if (label) {
window._sz.push(['event', category, action, label]);
} else {
window._sz.push(['event', category, action]);
}
};
17 changes: 16 additions & 1 deletion src/components/details-page/components/details-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ import withCommunity, {
} from '../../../with-community';
import Aside from '../aside';
import { accessRequestWhiteList } from '../../../../white-list';
import {
EventAction,
EventCategory,
trackSiteImproveEvent
} from '../../../analytics-siteimprove/utils';

interface ExternalProps {
entity: Entity;
Expand Down Expand Up @@ -322,7 +327,17 @@ const DetailsPage: FC<PropsWithChildren<Props>> = ({
target='_blank'
rel='noreferrer'
>
<Button>{translations.detailsPage.requestDataButton}</Button>
<Button
onClick={() =>
trackSiteImproveEvent({
category: EventCategory.DETAILS_PAGE,
action: EventAction.REQUEST_ACCESS,
label: entityId
})
}
>
{translations.detailsPage.requestDataButton}
</Button>
</a>
</SC.AccessRequest>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export declare global {}
export {};

declare global {
interface Window {
_sz: {
push: (event: [string, string, string, string?]) => void;
};
}
}

0 comments on commit b87ba61

Please sign in to comment.