Skip to content

Commit e67e054

Browse files
committed
add docstrings
1 parent d1eb93c commit e67e054

File tree

1 file changed

+146
-1
lines changed

1 file changed

+146
-1
lines changed

packages/browser/src/core/analytics/interfaces.ts

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,169 @@ export interface AnalyticsClassic extends AnalyticsClassicStubs {
7777
* Interface implemented by concrete Analytics class (commonly accessible if you use "await" on AnalyticsBrowser.load())
7878
*/
7979
export interface AnalyticsCore extends CoreAnalytics {
80+
/**
81+
* Tracks an event.
82+
* @param args - Event parameters.
83+
* @example
84+
* ```ts
85+
* analytics.track('Event Name', {
86+
* property1: 'value1',
87+
* property2: 'value2'
88+
* });
89+
* ```
90+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#track
91+
* @returns A promise that resolves to a dispatched event.
92+
*/
8093
track(...args: EventParams): Promise<DispatchedEvent>
94+
95+
/**
96+
* Tracks a page view.
97+
* @param args - `[category], [name], [properties], [options], [callback]`
98+
* @example
99+
* ```ts
100+
* analytics.page('My Category', 'Pricing', {
101+
* title: 'My Overridden Title',
102+
* myExtraProp: 'foo'
103+
* })
104+
*
105+
* analytics.page('Pricing', {
106+
* title: 'My Overridden Title',
107+
* myExtraProp: 'foo'
108+
* });
109+
* ```
110+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#page
111+
* @returns A promise that resolves to a dispatched event.
112+
*/
81113
page(...args: PageParams): Promise<DispatchedEvent>
114+
115+
/**
116+
* Identifies a user.
117+
* @param args - Identify parameters.
118+
* @example
119+
* ```ts
120+
* analytics.identify('userId123', {
121+
* email: 'user@example.com',
122+
* name: 'John Doe'
123+
* });
124+
* ```
125+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#identify
126+
* @returns A promise that resolves to a dispatched event.
127+
*/
82128
identify(...args: IdentifyParams): Promise<DispatchedEvent>
129+
130+
/**
131+
* Gets the group.
132+
* @returns The group.
133+
*/
83134
group(): Group
135+
136+
/**
137+
* Sets the group.
138+
* @param args - Group parameters.
139+
* @example
140+
* ```ts
141+
* analytics.group('groupId123', {
142+
* name: 'Company Inc.',
143+
* industry: 'Software'
144+
* });
145+
* ```
146+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#group
147+
* @returns A promise that resolves to a dispatched event.
148+
*/
84149
group(...args: GroupParams): Promise<DispatchedEvent>
150+
151+
/**
152+
* Creates an alias for a user.
153+
* @param args - Alias parameters.
154+
* @example
155+
* ```ts
156+
* analytics.alias('newUserId123', 'oldUserId456');
157+
* ```
158+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#alias
159+
* @returns A promise that resolves to a dispatched event.
160+
*/
85161
alias(...args: AliasParams): Promise<DispatchedEvent>
162+
163+
/**
164+
* Tracks a screen view.
165+
* @param args - Page parameters.
166+
* @example
167+
* ```ts
168+
* analytics.screen('Home Screen', {
169+
* title: 'Home',
170+
* section: 'Main'
171+
* });
172+
* ```
173+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#screen
174+
* @returns A promise that resolves to a dispatched event.
175+
*/
86176
screen(...args: PageParams): Promise<DispatchedEvent>
177+
178+
/**
179+
* Registers plugins.
180+
* @param plugins - Plugins to register.
181+
* @example
182+
* ```ts
183+
* analytics.register(plugin1, plugin2);
184+
* ```
185+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#register
186+
* @returns A promise that resolves to the context.
187+
*/
87188
register(...plugins: Plugin[]): Promise<Context>
189+
190+
/**
191+
* Deregisters plugins.
192+
* @param plugins - Plugin names to deregister.
193+
* @example
194+
* ```ts
195+
* analytics.deregister('plugin1', 'plugin2');
196+
* ```
197+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#deregister
198+
* @returns A promise that resolves to the context.
199+
*/
88200
deregister(...plugins: string[]): Promise<Context>
201+
202+
/**
203+
* Gets the user.
204+
* @returns The user.
205+
*/
89206
user(): User
207+
208+
/**
209+
* The version of the analytics library.
210+
*/
90211
readonly VERSION: string
91212
}
92213

93214
/**
94215
* Interface implemented by AnalyticsBrowser (buffered version of analytics) (commonly accessible through AnalyticsBrowser.load())
95216
*/
96-
export type AnalyticsBrowserCore = Omit<AnalyticsCore, 'group' | 'user'> & {
217+
export interface AnalyticsBrowserCore
218+
extends Omit<AnalyticsCore, 'group' | 'user'> {
219+
/**
220+
* Gets the group.
221+
* @returns A promise that resolves to the group.
222+
*/
97223
group(): Promise<Group>
224+
225+
/**
226+
* Sets the group.
227+
* @param args - Group parameters.
228+
* @example
229+
* ```ts
230+
* analytics.group('groupId123', {
231+
* name: 'Company Inc.',
232+
* industry: 'Software'
233+
* });
234+
* ```
235+
* @link https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#group
236+
* @returns A promise that resolves to a dispatched event.
237+
*/
98238
group(...args: GroupParams): Promise<DispatchedEvent>
239+
240+
/**
241+
* Gets the user.
242+
* @returns A promise that resolves to the user.
243+
*/
99244
user(): Promise<User>
100245
}

0 commit comments

Comments
 (0)