diff --git a/apps/admin-x-settings/src/components/settings/site/recommendations/AddRecommendationModalConfirm.tsx b/apps/admin-x-settings/src/components/settings/site/recommendations/AddRecommendationModalConfirm.tsx index 3508983eb5..864e2c3cb7 100644 --- a/apps/admin-x-settings/src/components/settings/site/recommendations/AddRecommendationModalConfirm.tsx +++ b/apps/admin-x-settings/src/components/settings/site/recommendations/AddRecommendationModalConfirm.tsx @@ -3,6 +3,7 @@ import Modal from '../../../../admin-x-ds/global/modal/Modal'; import NiceModal, {useModal} from '@ebay/nice-modal-react'; import React from 'react'; import RecommendationReasonForm, {validateReasonForm} from './RecommendationReasonForm'; +import trackEvent from '../../../../utils/plausible'; import useForm from '../../../../hooks/useForm'; import useHandleError from '../../../../utils/api/handleError'; import useRouting from '../../../../hooks/useRouting'; @@ -31,6 +32,9 @@ const AddRecommendationModalConfirm: React.FC = ({r message: 'Successfully added a recommendation', type: 'success' }); + trackEvent('Recommendation Added', { + oneClickSubscribe: state.one_click_subscribe + }); updateRoute('recommendations'); }, onSaveError: handleError, diff --git a/apps/admin-x-settings/src/utils/plausible.ts b/apps/admin-x-settings/src/utils/plausible.ts new file mode 100644 index 0000000000..cd6d882838 --- /dev/null +++ b/apps/admin-x-settings/src/utils/plausible.ts @@ -0,0 +1,16 @@ +// Wrapper function for Plausible event +type PlausiblePropertyValue = string|number|boolean + +declare global { + interface Window { + plausible?: ((eventName: string, options: {props: Record}) => void) + } +} + +export default function trackEvent(eventName: string, props: Record = {}) { + window.plausible = window.plausible || function () { + // eslint-disable-next-line @typescript-eslint/no-explicit-any, prefer-rest-params + ((window.plausible as any).q = (window.plausible as any).q || []).push(arguments as unknown); + }; + window.plausible!(eventName, {props: props}); +}