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

chore: replace monsido with siteimprove #2141

Merged
merged 2 commits into from
Sep 27, 2024
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
57 changes: 0 additions & 57 deletions src/components/analytics-monsido/index.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/analytics-monsido/utils/errors.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/components/analytics-monsido/utils/events.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/components/analytics-monsido/utils/helpers.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/components/analytics-monsido/utils/index.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/components/analytics-siteimprove/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FC, useEffect } from 'react';

const AnalyticsSiteImprove: FC = () => {
useEffect(() => {
const script = document.createElement('script');
script.src = 'https://siteimproveanalytics.com/js/siteanalyze_6255470.js';
script.async = true;

document.body.appendChild(script);
return () => {
document.body.removeChild(script);
};
}, []);

return null;
};

export default AnalyticsSiteImprove;
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]);
}
};
15 changes: 9 additions & 6 deletions src/components/details-page/components/details-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ import withCommunity, {
import Aside from '../aside';
import { accessRequestWhiteList } from '../../../../white-list';
import {
MonsidoTrackEventParams,
monsidoTrackButtonClickEvent
} from '../../../analytics-monsido/utils/events';
EventAction,
EventCategory,
trackSiteImproveEvent
} from '../../../analytics-siteimprove/utils';

interface ExternalProps {
entity: Entity;
Expand Down Expand Up @@ -328,9 +329,11 @@ const DetailsPage: FC<PropsWithChildren<Props>> = ({
>
<Button
onClick={() =>
monsidoTrackButtonClickEvent(
MonsidoTrackEventParams.Action.Click.Button.AccessRequest
)
trackSiteImproveEvent({
category: EventCategory.DETAILS_PAGE,
action: EventAction.REQUEST_ACCESS,
label: entityId
})
}
>
{translations.detailsPage.requestDataButton}
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints/main/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getConfig } from '../../config';
import { themeFDK, themeNAP } from '../../app/theme';
import GlobalStyles from '../../app/styles';

import AnalyticsMonsido from '../../components/analytics-monsido';
import AnalyticsSiteImprove from '../../components/analytics-siteimprove';
import { store } from '../../redux/store';

const client = new ApolloClient({
Expand All @@ -31,7 +31,7 @@ render(
<GlobalStyles />
<AuthProvider>
<LoggingProvider>
<AnalyticsMonsido />
<AnalyticsSiteImprove />
<ApolloProvider client={client}>
<Provider store={store}>
<BrowserRouter>
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints/publishing/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import store from '../redux/store';
import GlobalStyles from '../styles';
import Router from '../router';

import AnalyticsMonsido from '../../../components/analytics-monsido';
import AnalyticsSiteImprove from '../../../components/analytics-siteimprove';

const App: FC = () => (
<ThemeProvider>
<GlobalStyles />
<AnalyticsMonsido />
<AnalyticsSiteImprove />
<TranslationsProvider>
<ReduxProvider store={store}>
<Router />
Expand Down
13 changes: 5 additions & 8 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
export declare global {
export {};

declare global {
interface Window {
monsido_functions: {
trackEvent: (
category: string,
action: string,
event: string,
increaseBy: number
) => string;
_sz: {
push: (event: [string, string, string, string?]) => void;
};
}
}