|
1 | | -// Sets up the tracking library. Can be called once. |
| 1 | +/** Sets up the tracking library. Can be called once. */ |
2 | 2 | export function init(config: PlausibleConfig): void |
3 | 3 |
|
4 | | -// Tracks an event, requires `init` to be called first. |
| 4 | +/** Tracks an event, requires `init` to be called first. */ |
5 | 5 | export function track(eventName: string, options: PlausibleEventOptions): void |
6 | 6 |
|
7 | 7 | export interface PlausibleConfig { |
8 | | - // Your site's domain, as declared by you in Plausible's settings. |
| 8 | + /** Your site's domain, as declared by you in Plausible's settings. */ |
9 | 9 | domain: string |
10 | 10 |
|
11 | | - // The URL of the Plausible API endpoint. Defaults to https://plausible.io/api/event |
12 | | - // See proxying guide at https://plausible.io/docs/proxy/introduction |
| 11 | + /** |
| 12 | + * The URL of the Plausible API endpoint. Defaults to https://plausible.io/api/event |
| 13 | + * See proxying guide at https://plausible.io/docs/proxy/introduction |
| 14 | + */ |
13 | 15 | endpoint?: string |
14 | 16 |
|
15 | | - // Whether to automatically capture pageviews. Defaults to true. |
| 17 | + /** Whether to automatically capture pageviews. Defaults to true. */ |
16 | 18 | autoCapturePageviews?: boolean |
17 | 19 |
|
18 | | - // Whether the page uses hash based routing. Defaults to false. |
19 | | - // Read more at https://plausible.io/docs/hash-based-routing |
| 20 | + /** |
| 21 | + * Whether the page uses hash based routing. Defaults to false. |
| 22 | + * Read more at https://plausible.io/docs/hash-based-routing |
| 23 | + */ |
20 | 24 | hashBasedRouting?: boolean |
21 | 25 |
|
22 | | - // Whether to track outbound link clicks. Defaults to false. |
| 26 | + /** Whether to track outbound link clicks. Defaults to false. */ |
23 | 27 | outboundLinks?: boolean |
24 | 28 |
|
25 | | - // Whether to track file downloads. Defaults to false. |
| 29 | + /** Whether to track file downloads. Defaults to false. */ |
26 | 30 | fileDownloads?: boolean | { fileExtensions: string[] } |
27 | 31 |
|
28 | | - // Whether to track form submissions. Defaults to false. |
| 32 | + /** Whether to track form submissions. Defaults to false. */ |
29 | 33 | formSubmissions?: boolean |
30 | 34 |
|
31 | | - // Whether to capture events on localhost. Defaults to false. |
| 35 | + /** Whether to capture events on localhost. Defaults to false. */ |
32 | 36 | captureOnLocalhost?: boolean |
33 | 37 |
|
34 | | - // Whether to log on ignored events. Defaults to true. |
| 38 | + /** Whether to log on ignored events. Defaults to true. */ |
35 | 39 | logging?: boolean |
36 | 40 |
|
37 | | - // Custom properties to add to all events tracked. |
38 | | - // If passed as a function, it will be called when `track` is called. |
| 41 | + /** |
| 42 | + * Custom properties to add to all events tracked. |
| 43 | + * If passed as a function, it will be called when `track` is called. |
| 44 | + */ |
39 | 45 | customProperties?: |
40 | 46 | | CustomProperties |
41 | 47 | | ((eventName: string) => CustomProperties) |
42 | 48 |
|
43 | | - // A function that can be used to transform the payload before it is sent to the API. |
44 | | - // If the function returns null or any other falsy value, the event will be ignored. |
45 | | - // |
46 | | - // This can be used to avoid sending certain types of events, or modifying any event |
47 | | - // parameters, e.g. to clean URLs of values that should not be recorded. |
| 49 | + /** |
| 50 | + * A function that can be used to transform the payload before it is sent to the API. |
| 51 | + * If the function returns null or any other falsy value, the event will be ignored. |
| 52 | + * |
| 53 | + * This can be used to avoid sending certain types of events, or modifying any event |
| 54 | + * parameters, e.g. to clean URLs of values that should not be recorded. |
| 55 | + */ |
48 | 56 | transformRequest?: ( |
49 | 57 | payload: PlausibleRequestPayload |
50 | 58 | ) => PlausibleRequestPayload | null |
51 | 59 |
|
52 | | - // If enabled (the default), the script will set `window.plausible` after `init` is called. |
53 | | - // This is used by the verifier to detect if the script is loaded from npm package. |
| 60 | + /** |
| 61 | + * If enabled (the default), the script will set `window.plausible` after `init` is called. |
| 62 | + * This is used by the verifier to detect if the script is loaded from npm package. |
| 63 | + */ |
54 | 64 | bindToWindow?: boolean |
55 | 65 | } |
56 | 66 |
|
57 | 67 | export interface PlausibleEventOptions { |
58 | | - // Custom properties to add to the event. |
59 | | - // Read more at https://plausible.io/docs/custom-props/introduction |
| 68 | + /** |
| 69 | + * Custom properties to add to the event. |
| 70 | + * Read more at https://plausible.io/docs/custom-props/introduction |
| 71 | + */ |
60 | 72 | props?: CustomProperties |
61 | 73 |
|
62 | | - // Whether the tracked event is interactive. Defaults to true. |
63 | | - // By marking a custom event as non-interactive, it will not be counted towards bounce rate calculations. |
| 74 | + /** |
| 75 | + * Whether the tracked event is interactive. Defaults to true. |
| 76 | + * By marking a custom event as non-interactive, it will not be counted towards bounce rate calculations. |
| 77 | + */ |
64 | 78 | interactive?: boolean |
65 | 79 |
|
66 | | - // Revenue data to add to the event. |
67 | | - // Read more at https://plausible.io/docs/ecommerce-revenue-tracking |
| 80 | + /** |
| 81 | + * Revenue data to add to the event. |
| 82 | + * Read more at https://plausible.io/docs/ecommerce-revenue-tracking |
| 83 | + */ |
68 | 84 | revenue?: PlausibleEventRevenue |
69 | 85 |
|
70 | | - // Called when request to `endpoint` completes or is ignored. |
71 | | - // When request is ignored, the result will be undefined. |
72 | | - // When request was delivered, the result will be an object with the response status code of the request. |
73 | | - // When there was a network error, the result will be an object with the error object. |
| 86 | + /** |
| 87 | + * Called when request to `endpoint` completes or is ignored. |
| 88 | + * When request is ignored, the result will be undefined. |
| 89 | + * When request was delivered, the result will be an object with the response status code of the request. |
| 90 | + * When there was a network error, the result will be an object with the error object. |
| 91 | + */ |
74 | 92 | callback?: ( |
75 | 93 | result?: { status: number } | { error: unknown } | undefined |
76 | 94 | ) => void |
77 | 95 |
|
78 | | - // Overrides the URL of the page that the event is being tracked on. |
79 | | - // If not provided, `location.href` will be used. |
| 96 | + /** |
| 97 | + * Overrides the URL of the page that the event is being tracked on. |
| 98 | + * If not provided, `location.href` will be used. |
| 99 | + */ |
80 | 100 | url?: string |
81 | 101 | } |
82 | 102 |
|
83 | 103 | export type CustomProperties = Record<string, string> |
84 | 104 |
|
85 | 105 | export type PlausibleEventRevenue = { |
86 | | - // Revenue amount in `currency` |
| 106 | + /** Revenue amount in `currency` */ |
87 | 107 | amount: number | string |
88 | | - // Currency is an ISO 4217 string representing the currency code, e.g. "USD" or "EUR" |
| 108 | + /** Currency is an ISO 4217 string representing the currency code, e.g. "USD" or "EUR" */ |
89 | 109 | currency: string |
90 | 110 | } |
91 | 111 |
|
92 | 112 | export type PlausibleRequestPayload = { |
93 | | - // Event name |
| 113 | + /** Event name */ |
94 | 114 | n: string |
95 | | - // URL of the event |
| 115 | + /** URL of the event */ |
96 | 116 | u: string |
97 | | - // Domain of the event |
| 117 | + /** Domain of the event */ |
98 | 118 | d: string |
99 | | - // Referrer |
| 119 | + /** Referrer */ |
100 | 120 | r?: string | null |
101 | | - // Custom properties |
| 121 | + /** Custom properties */ |
102 | 122 | p?: CustomProperties |
103 | | - // Revenue information |
| 123 | + /** Revenue information */ |
104 | 124 | $?: PlausibleEventRevenue |
105 | | - // Whether the event is interactive |
| 125 | + /** Whether the event is interactive */ |
106 | 126 | i?: boolean |
107 | 127 | } & Record<string, unknown> |
108 | 128 |
|
109 | | -// Default file types that are tracked when `fileDownloads` is enabled. |
| 129 | +/** Default file types that are tracked when `fileDownloads` is enabled. */ |
110 | 130 | export const DEFAULT_FILE_TYPES: string[] |
0 commit comments