-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
interface TrackedProperties { | ||
/** | ||
* Hostname of server | ||
* | ||
* @description extracted from `window.location.hostname` | ||
* @example 'analytics.umami.is' | ||
*/ | ||
hostname: string; | ||
|
||
/** | ||
* Browser language | ||
* | ||
* @description extracted from `window.navigator.language` | ||
* @example 'en-US', 'fr-FR' | ||
*/ | ||
language: string; | ||
|
||
/** | ||
* Page referrer | ||
* | ||
* @description extracted from `window.navigator.language` | ||
* @example 'https://analytics.umami.is/docs/getting-started' | ||
*/ | ||
referrer: string; | ||
|
||
/** | ||
* Screen dimensions | ||
* | ||
* @description extracted from `window.screen.width` and `window.screen.height` | ||
* @example '1920x1080', '2560x1440' | ||
*/ | ||
screen: string; | ||
|
||
/** | ||
* Page title | ||
* | ||
* @description extracted from `document.querySelector('head > title')` | ||
* @example 'umami' | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* Page url | ||
* | ||
* @description built from `${window.location.pathname}${window.location.search}` | ||
* @example 'docs/getting-started' | ||
*/ | ||
url: string; | ||
|
||
/** | ||
* Website ID (required) | ||
* | ||
* @example 'b59e9c65-ae32-47f1-8400-119fcf4861c4' | ||
*/ | ||
website: string; | ||
} | ||
|
||
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }; | ||
|
||
/** | ||
* | ||
* Event Data can work with any JSON data. There are a few rules in place to maintain performance. | ||
* - Numbers have a max precision of 4. | ||
* - Strings have a 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. | ||
*/ | ||
interface EventData { | ||
[key: string]: | ||
| EventData | ||
| EventData[] | ||
| number[] | ||
| string[] | ||
| number | ||
| string; | ||
} | ||
|
||
type EventProperties = WithRequired<TrackedProperties, "website"> & { | ||
/** | ||
* NOTE: event names will be truncated past 50 characters | ||
*/ | ||
name: string; | ||
data?: EventData; | ||
}; | ||
type PageViewProperties = WithRequired<TrackedProperties, "website">; | ||
type CustomEventFunction = ( | ||
props: PageViewProperties, | ||
) => EventProperties | PageViewProperties; | ||
|
||
export interface 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'); | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/unified-signatures | ||
(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 }); | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/unified-signatures | ||
(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' }); | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/unified-signatures | ||
(properties: PageViewProperties): Promise<string>; | ||
|
||
/** | ||
* Tracks an event with fully customizable dynamic data | ||
* If you don't specify any `name` and/or `data`, it will be treated as a page view | ||
* | ||
* @example ``` | ||
* umami.track((props) => ({ ...props, url: path })); | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/unified-signatures | ||
(eventFunction: CustomEventFunction): Promise<string>; | ||
}; | ||
} |