Skip to content

Commit c9cbea7

Browse files
apataa7madgamal
andauthored
Add JSDoc types (#5842)
* Enhance TypeScript definitions for Plausible tracking library Updated the plausible.d.ts file to improve documentation by adding JSDoc comments for all functions and properties. This enhances clarity and usability for developers integrating the tracking library. * Update CHANGELOG.md to reflect changes in TypeScript definition comments for improved IDE integration * Format * Remove subtitle from changelog --------- Co-authored-by: Ahmed Hassanein <[email protected]>
1 parent 546f0c3 commit c9cbea7

File tree

2 files changed

+66
-44
lines changed

2 files changed

+66
-44
lines changed

tracker/npm_package/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Convert all TypeScript definition comments from `//` style to JSDoc `/** */` style for better IDE integration and TypeScript tooling support
11+
1012
## [0.4.3] - 2025-09-15
1113

1214
- Fix formatting issues.

tracker/npm_package/plausible.d.ts

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,130 @@
1-
// Sets up the tracking library. Can be called once.
1+
/** Sets up the tracking library. Can be called once. */
22
export function init(config: PlausibleConfig): void
33

4-
// Tracks an event, requires `init` to be called first.
4+
/** Tracks an event, requires `init` to be called first. */
55
export function track(eventName: string, options: PlausibleEventOptions): void
66

77
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. */
99
domain: string
1010

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+
*/
1315
endpoint?: string
1416

15-
// Whether to automatically capture pageviews. Defaults to true.
17+
/** Whether to automatically capture pageviews. Defaults to true. */
1618
autoCapturePageviews?: boolean
1719

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+
*/
2024
hashBasedRouting?: boolean
2125

22-
// Whether to track outbound link clicks. Defaults to false.
26+
/** Whether to track outbound link clicks. Defaults to false. */
2327
outboundLinks?: boolean
2428

25-
// Whether to track file downloads. Defaults to false.
29+
/** Whether to track file downloads. Defaults to false. */
2630
fileDownloads?: boolean | { fileExtensions: string[] }
2731

28-
// Whether to track form submissions. Defaults to false.
32+
/** Whether to track form submissions. Defaults to false. */
2933
formSubmissions?: boolean
3034

31-
// Whether to capture events on localhost. Defaults to false.
35+
/** Whether to capture events on localhost. Defaults to false. */
3236
captureOnLocalhost?: boolean
3337

34-
// Whether to log on ignored events. Defaults to true.
38+
/** Whether to log on ignored events. Defaults to true. */
3539
logging?: boolean
3640

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+
*/
3945
customProperties?:
4046
| CustomProperties
4147
| ((eventName: string) => CustomProperties)
4248

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+
*/
4856
transformRequest?: (
4957
payload: PlausibleRequestPayload
5058
) => PlausibleRequestPayload | null
5159

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+
*/
5464
bindToWindow?: boolean
5565
}
5666

5767
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+
*/
6072
props?: CustomProperties
6173

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+
*/
6478
interactive?: boolean
6579

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+
*/
6884
revenue?: PlausibleEventRevenue
6985

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+
*/
7492
callback?: (
7593
result?: { status: number } | { error: unknown } | undefined
7694
) => void
7795

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+
*/
80100
url?: string
81101
}
82102

83103
export type CustomProperties = Record<string, string>
84104

85105
export type PlausibleEventRevenue = {
86-
// Revenue amount in `currency`
106+
/** Revenue amount in `currency` */
87107
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" */
89109
currency: string
90110
}
91111

92112
export type PlausibleRequestPayload = {
93-
// Event name
113+
/** Event name */
94114
n: string
95-
// URL of the event
115+
/** URL of the event */
96116
u: string
97-
// Domain of the event
117+
/** Domain of the event */
98118
d: string
99-
// Referrer
119+
/** Referrer */
100120
r?: string | null
101-
// Custom properties
121+
/** Custom properties */
102122
p?: CustomProperties
103-
// Revenue information
123+
/** Revenue information */
104124
$?: PlausibleEventRevenue
105-
// Whether the event is interactive
125+
/** Whether the event is interactive */
106126
i?: boolean
107127
} & Record<string, unknown>
108128

109-
// Default file types that are tracked when `fileDownloads` is enabled.
129+
/** Default file types that are tracked when `fileDownloads` is enabled. */
110130
export const DEFAULT_FILE_TYPES: string[]

0 commit comments

Comments
 (0)