Ghost/apps/admin-x-settings/test/unit/utils/analytics.test.ts
Chris Raible b8ad03b0f3
Added PostHog to admin-x-settings trackEvent function (#20013)
ref https://linear.app/tryghost/issue/PA-53/add-posthog-tracking-to-trackevent-in-admin-x-settings-and-lexical

- There was a pre-existing `trackEvent` function in `admin-x-settings`
that was using Plausible for tracking events.
- This PR adds PostHog to the same function, any calls to `trackEvent`
will send the event name and properties to PostHog as well.
2024-04-11 19:35:30 -07:00

39 lines
1.1 KiB
TypeScript

import * as assert from 'assert/strict';
import trackEvent from '../../../src/utils/analytics';
describe('trackEvent', function () {
it('calls posthog.capture with the correct event name and properties', function () {
const testEventName = 'Recommendation Added';
const testProps = {
oneClickSubscribe: true
};
window.posthog = {
capture: (eventName, props) => {
assert.equal(eventName, 'Recommendation Added');
assert.deepEqual(props, {
oneClickSubscribe: true
});
}
};
trackEvent(testEventName, testProps);
});
it('calls plausible with the correct event name and properties', function () {
const testEventName = 'Recommendation Added';
const testProps = {
oneClickSubscribe: true
};
window.plausible = (eventName, {props}) => {
assert.equal(eventName, 'Recommendation Added');
assert.deepEqual(props, {
oneClickSubscribe: true
});
};
trackEvent(testEventName, testProps);
});
});