mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
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:
parent
2574546f2e
commit
b868dd263d
@ -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,
|
||||
|
16
apps/admin-x-settings/src/utils/plausible.ts
Normal file
16
apps/admin-x-settings/src/utils/plausible.ts
Normal 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});
|
||||
}
|
Loading…
Reference in New Issue
Block a user