diff --git a/src/components/analytics-siteimprove/utils.ts b/src/components/analytics-siteimprove/utils.ts new file mode 100644 index 000000000..5a2f576f4 --- /dev/null +++ b/src/components/analytics-siteimprove/utils.ts @@ -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]); + } + }; diff --git a/src/components/details-page/components/details-page/index.tsx b/src/components/details-page/components/details-page/index.tsx index 2bde6acb8..61ec1610b 100755 --- a/src/components/details-page/components/details-page/index.tsx +++ b/src/components/details-page/components/details-page/index.tsx @@ -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; @@ -322,7 +327,17 @@ const DetailsPage: FC> = ({ target='_blank' rel='noreferrer' > - + )} diff --git a/src/types/global.d.ts b/src/types/global.d.ts index a9bb7490d..2ea5d4561 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1 +1,9 @@ -export declare global {} +export {}; + +declare global { + interface Window { + _sz: { + push: (event: [string, string, string, string?]) => void; + }; + } +}