Document IEvent.properties, fix IWelcomeScreenLoad

IEvent.properties is a placeholder that needs to be overriden by extenders for type validation to take place.

IWelcomeScreenLoad should have had properties declared for it. Because it didn't, a faulty call using it was possible.
This commit is contained in:
James Salter 2021-07-28 16:43:13 +01:00
parent 13ef819ba6
commit b1bd5f57a4
2 changed files with 7 additions and 6 deletions

View file

@ -32,15 +32,15 @@ import SettingsStore from './settings/SettingsStore';
* - Otherwise, if the existing `analyticsOptIn` flag is `true`, or not present (i.e. prior to * - Otherwise, if the existing `analyticsOptIn` flag is `true`, or not present (i.e. prior to
* logging in), track anonymously, i.e. redact all matrix identifiers in tracking events. * logging in), track anonymously, i.e. redact all matrix identifiers in tracking events.
* - If both flags are false, events are not sent. * - If both flags are false, events are not sent.
*/ */
interface IEvent { interface IEvent {
// The event name that will be used by PostHog. // The event name that will be used by PostHog. Event names should use snake_case.
// TODO: standard format (camel case? snake? UpperCase?)
eventName: string; eventName: string;
// The properties of the event that will be stored in PostHog. // The properties of the event that will be stored in PostHog. This is just a placeholder,
properties: {}; // extending interfaces must override this with a concrete definition to do type validation.
properties: {}
} }
export enum Anonymity { export enum Anonymity {
@ -73,6 +73,7 @@ interface IPageView extends IAnonymousEvent {
export interface IWelcomeScreenLoad extends IAnonymousEvent { export interface IWelcomeScreenLoad extends IAnonymousEvent {
eventName: "welcome_screen_load"; eventName: "welcome_screen_load";
properties: Record<any, never>;
} }
const hashHex = async (input: string): Promise<string> => { const hashHex = async (input: string): Promise<string> => {

View file

@ -76,6 +76,6 @@ export default class Welcome extends React.PureComponent<IProps> {
} }
componentDidMount() { componentDidMount() {
getAnalytics().trackAnonymousEvent<IWelcomeScreenLoad>("welcome_screen_load", { foo: "bar" }); getAnalytics().trackAnonymousEvent<IWelcomeScreenLoad>("welcome_screen_load", {});
} }
} }