Added plausible events to the recommendation modal (#18526)

fixes https://github.com/TryGhost/Product/issues/3841

- Wired up the trackEvent method in admin-X
- Send an event when a recommendation is added
This commit is contained in:
Simon Backx 2023-10-06 15:41:33 +02:00 committed by GitHub
parent 2574546f2e
commit b868dd263d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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<AddRecommendationModalProps> = ({r
message: 'Successfully added a recommendation',
type: 'success'
});
trackEvent('Recommendation Added', {
oneClickSubscribe: state.one_click_subscribe
});
updateRoute('recommendations');
},
onSaveError: handleError,

View File

@ -0,0 +1,16 @@
// Wrapper function for Plausible event
type PlausiblePropertyValue = string|number|boolean
declare global {
interface Window {
plausible?: ((eventName: string, options: {props: Record<string, PlausiblePropertyValue>}) => void)
}
}
export default function trackEvent(eventName: string, props: Record<string, PlausiblePropertyValue> = {}) {
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});
}