mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Merge pull request #2068 from cadesalaberry/chore/update-tracker-typing
chore(tracker): 🏷️ could not use `string` in `EventData`
This commit is contained in:
commit
79b728cc23
151
tracker/index.d.ts
vendored
151
tracker/index.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
type TrackedProperties = {
|
export type TrackedProperties = {
|
||||||
/**
|
/**
|
||||||
* Hostname of server
|
* Hostname of server
|
||||||
*
|
*
|
||||||
@ -55,7 +55,7 @@ type TrackedProperties = {
|
|||||||
website: string;
|
website: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
|
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -65,74 +65,89 @@ type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
|
|||||||
* - Arrays are converted to a String, with the same max length of 500.
|
* - Arrays are converted to a String, with the same max length of 500.
|
||||||
* - Objects have a max of 50 properties. Arrays are considered 1 property.
|
* - Objects have a max of 50 properties. Arrays are considered 1 property.
|
||||||
*/
|
*/
|
||||||
type EventData = Record<string, object>;
|
export interface EventData {
|
||||||
type EventProperties = {
|
[key: string]: number | string | EventData | number[] | string[] | EventData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EventProperties = {
|
||||||
|
/**
|
||||||
|
* NOTE: event names will be truncated past 50 characters
|
||||||
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
data?: EventData;
|
data?: EventData;
|
||||||
} & WithRequired<TrackedProperties, 'website'>
|
} & WithRequired<TrackedProperties, 'website'>;
|
||||||
| WithRequired<TrackedProperties, 'website'>;
|
export type PageViewProperties = WithRequired<TrackedProperties, 'website'>;
|
||||||
|
export type CustomEventFunction = (
|
||||||
|
props: PageViewProperties,
|
||||||
|
) => EventProperties | PageViewProperties;
|
||||||
|
|
||||||
|
export type UmamiTracker = {
|
||||||
|
track: {
|
||||||
|
/**
|
||||||
|
* Track a page view
|
||||||
|
*
|
||||||
|
* @example ```
|
||||||
|
* umami.track();
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
(): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Track an event with a given name
|
||||||
|
*
|
||||||
|
* NOTE: event names will be truncated past 50 characters
|
||||||
|
*
|
||||||
|
* @example ```
|
||||||
|
* umami.track('signup-button');
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
(eventName: string): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks an event with dynamic data.
|
||||||
|
*
|
||||||
|
* NOTE: event names will be truncated past 50 characters
|
||||||
|
*
|
||||||
|
* When tracking events, the default properties are included in the payload. This is equivalent to running:
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* umami.track(props => ({
|
||||||
|
* ...props,
|
||||||
|
* name: 'signup-button',
|
||||||
|
* data: {
|
||||||
|
* name: 'newsletter',
|
||||||
|
* id: 123
|
||||||
|
* }
|
||||||
|
* }));
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @example ```
|
||||||
|
* umami.track('signup-button', { name: 'newsletter', id: 123 });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
(eventName: string, obj: EventData): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks a page view with custom properties
|
||||||
|
*
|
||||||
|
* @example ```
|
||||||
|
* umami.track({ website: 'e676c9b4-11e4-4ef1-a4d7-87001773e9f2', url: '/home', title: 'Home page' });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
(properties: PageViewProperties): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks an event with fully customizable dynamic data
|
||||||
|
* Ilf you don't specify any `name` and/or `data`, it will be treated as a page view
|
||||||
|
*
|
||||||
|
* @example ```
|
||||||
|
* umami.track((props) => ({ ...props, url: path }));
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
(eventFunction: CustomEventFunction): Promise<string>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
umami: {
|
umami: UmamiTracker;
|
||||||
track: {
|
|
||||||
/**
|
|
||||||
* Track a page view
|
|
||||||
*
|
|
||||||
* @example ```
|
|
||||||
* umami.track();
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
(): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Track an event with a given name
|
|
||||||
*
|
|
||||||
* @example ```
|
|
||||||
* umami.track('signup-button');
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
(eventName: string): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tracks an event with dynamic data.
|
|
||||||
*
|
|
||||||
* When tracking events, the default properties are included in the payload. This is equivalent to running:
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* umami.track(props => ({
|
|
||||||
* ...props,
|
|
||||||
* name: 'signup-button',
|
|
||||||
* data: {
|
|
||||||
* name: 'newsletter',
|
|
||||||
* id: 123
|
|
||||||
* }
|
|
||||||
* }));
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @example ```
|
|
||||||
* umami.track('signup-button', { name: 'newsletter', id: 123 });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
(eventName: string, obj: EventData): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tracks a page view with custom properties
|
|
||||||
*
|
|
||||||
* @example ```
|
|
||||||
* umami.track({ website: 'e676c9b4-11e4-4ef1-a4d7-87001773e9f2', url: '/home', title: 'Home page' });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
(properties: WithRequired<Partial<TrackedProperties>, 'website'>): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tracks an event with fully customizable dynamic data
|
|
||||||
* Ilf you don't specify any `name` and/or `data`, it will be treated as a page view
|
|
||||||
*
|
|
||||||
* @example ```
|
|
||||||
* umami.track((props) => ({ ...props, url: path }));
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
(eventFunction: (prop: TrackedProperties) => EventProperties): Promise<string>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user