|
| 1 | +export namespace SegmentAnalytics { |
| 2 | + export interface SegmentOpts { |
| 3 | + integrations?: any; |
| 4 | + anonymousId?: string; |
| 5 | + context?: object; |
| 6 | + } |
| 7 | + |
| 8 | + export interface IntegrationsSettings { |
| 9 | + // TODO remove `any` |
| 10 | + [key: string]: any; |
| 11 | + } |
| 12 | + |
| 13 | + export interface CookieOptions { |
| 14 | + maxage?: number; |
| 15 | + domain?: string; |
| 16 | + path?: string; |
| 17 | + secure?: boolean; |
| 18 | + } |
| 19 | + |
| 20 | + export interface MetricsOptions { |
| 21 | + host?: string; |
| 22 | + sampleRate?: number; |
| 23 | + flushTimer?: number; |
| 24 | + maxQueueSize?: number; |
| 25 | + } |
| 26 | + |
| 27 | + export interface StoreOptions { |
| 28 | + enabled?: boolean; |
| 29 | + } |
| 30 | + |
| 31 | + export interface UserOptions { |
| 32 | + cookie?: { |
| 33 | + key: string; |
| 34 | + oldKey: string; |
| 35 | + }; |
| 36 | + localStorage?: { |
| 37 | + key: string; |
| 38 | + }; |
| 39 | + persist?: boolean; |
| 40 | + } |
| 41 | + |
| 42 | + export interface GroupOptions { |
| 43 | + cookie?: { |
| 44 | + key: string; |
| 45 | + }; |
| 46 | + localStorage?: { |
| 47 | + key: string; |
| 48 | + }; |
| 49 | + persist?: boolean; |
| 50 | + } |
| 51 | + |
| 52 | + export interface SegmentIntegration { |
| 53 | + All?: boolean; |
| 54 | + [integration: string]: boolean | undefined; |
| 55 | + } |
| 56 | + |
| 57 | + export interface InitOptions { |
| 58 | + initialPageview?: boolean; |
| 59 | + cookie?: CookieOptions; |
| 60 | + metrics?: MetricsOptions; |
| 61 | + localStorage?: StoreOptions; |
| 62 | + user?: UserOptions; |
| 63 | + group?: GroupOptions; |
| 64 | + integrations?: SegmentIntegration; |
| 65 | + } |
| 66 | + |
| 67 | + export interface AnalyticsJS { |
| 68 | + Integrations: { [name: string]: unknown }; |
| 69 | + require: any; |
| 70 | + VERSION: any; |
| 71 | + |
| 72 | + /** |
| 73 | + * Use a `plugin`. |
| 74 | + */ |
| 75 | + use(plugin: (analytics: AnalyticsJS) => void): AnalyticsJS; |
| 76 | + |
| 77 | + /** |
| 78 | + * Define a new `Integration`. |
| 79 | + */ |
| 80 | + addIntegration(Integration: (options: SegmentOpts) => void): AnalyticsJS; |
| 81 | + |
| 82 | + /** |
| 83 | + * Define a new `SourceMiddleware` |
| 84 | + */ |
| 85 | + addSourceMiddleware(middleware: Function): AnalyticsJS; |
| 86 | + |
| 87 | + /** |
| 88 | + * Define a new `IntegrationMiddleware` |
| 89 | + * @deprecated Use addDestinationMiddleware instead |
| 90 | + */ |
| 91 | + addIntegrationMiddleware(middleware: Function): AnalyticsJS; |
| 92 | + |
| 93 | + /** |
| 94 | + * Define a new `DestinationMiddleware` |
| 95 | + * Destination Middleware is chained after integration middleware |
| 96 | + */ |
| 97 | + addDestinationMiddleware( |
| 98 | + integrationName: string, |
| 99 | + middlewares: Array<unknown> |
| 100 | + ): AnalyticsJS; |
| 101 | + |
| 102 | + /** |
| 103 | + * Initialize with the given integration `settings` and `options`. |
| 104 | + * |
| 105 | + * Aliased to `init` for convenience. |
| 106 | + */ |
| 107 | + initialize( |
| 108 | + settings: IntegrationsSettings, |
| 109 | + options: InitOptions |
| 110 | + ): AnalyticsJS; |
| 111 | + |
| 112 | + /** |
| 113 | + * Initialize with the given integration `settings` and `options`. |
| 114 | + * |
| 115 | + * Aliased to `init` for convenience. |
| 116 | + */ |
| 117 | + init(settings: IntegrationsSettings, options: InitOptions): AnalyticsJS; |
| 118 | + |
| 119 | + /** |
| 120 | + * Set the user's `id`. |
| 121 | + */ |
| 122 | + setAnonymousId(id: string): AnalyticsJS; |
| 123 | + |
| 124 | + /** |
| 125 | + * Add an integration. |
| 126 | + */ |
| 127 | + add(integration: { name: string | number }): AnalyticsJS; |
| 128 | + |
| 129 | + /** |
| 130 | + * Identify a user by optional `id` and `traits`. |
| 131 | + */ |
| 132 | + identify( |
| 133 | + id: string, |
| 134 | + traits: unknown, |
| 135 | + options: SegmentOpts, |
| 136 | + fn: Function | SegmentOpts |
| 137 | + ): AnalyticsJS; |
| 138 | + |
| 139 | + /** |
| 140 | + * Return the current user. |
| 141 | + */ |
| 142 | + user(): object; |
| 143 | + |
| 144 | + /** |
| 145 | + * Identify a group by optional `id` and `traits`. Or, if no arguments are |
| 146 | + * supplied, return the current group. |
| 147 | + */ |
| 148 | + group( |
| 149 | + id: string, |
| 150 | + traits: unknown, |
| 151 | + options: unknown, |
| 152 | + fn: unknown |
| 153 | + ): AnalyticsJS; |
| 154 | + |
| 155 | + /** |
| 156 | + * Track an `event` that a user has triggered with optional `properties`. |
| 157 | + */ |
| 158 | + track( |
| 159 | + event: string, |
| 160 | + properties: unknown, |
| 161 | + options: unknown, |
| 162 | + fn: unknown |
| 163 | + ): AnalyticsJS; |
| 164 | + |
| 165 | + /** |
| 166 | + * Helper method to track an outbound link that would normally navigate away |
| 167 | + * from the page before the analytics calls were sent. |
| 168 | + * |
| 169 | + * BACKWARDS COMPATIBILITY: aliased to `trackClick`. |
| 170 | + */ |
| 171 | + trackClick( |
| 172 | + links: Element | Array<unknown>, |
| 173 | + event: any, |
| 174 | + properties?: any |
| 175 | + ): AnalyticsJS; |
| 176 | + |
| 177 | + /** |
| 178 | + * Helper method to track an outbound link that would normally navigate away |
| 179 | + * from the page before the analytics calls were sent. |
| 180 | + * |
| 181 | + * BACKWARDS COMPATIBILITY: aliased to `trackClick`. |
| 182 | + */ |
| 183 | + trackLink( |
| 184 | + links: Element | Array<unknown>, |
| 185 | + event: any, |
| 186 | + properties?: any |
| 187 | + ): AnalyticsJS; |
| 188 | + |
| 189 | + /** |
| 190 | + * Set the user's `id`. |
| 191 | + */ |
| 192 | + setAnonymousId(id: string): AnalyticsJS; |
| 193 | + |
| 194 | + /** |
| 195 | + * Helper method to track an outbound form that would normally navigate away |
| 196 | + * from the page before the analytics calls were sent. |
| 197 | + * |
| 198 | + * BACKWARDS COMPATIBILITY: aliased to `trackSubmit`. |
| 199 | + */ |
| 200 | + trackSubmit( |
| 201 | + forms: Element | Array<unknown>, |
| 202 | + event: any, |
| 203 | + properties?: any |
| 204 | + ): AnalyticsJS; |
| 205 | + |
| 206 | + /** |
| 207 | + * Helper method to track an outbound form that would normally navigate away |
| 208 | + * from the page before the analytics calls were sent. |
| 209 | + * |
| 210 | + * BACKWARDS COMPATIBILITY: aliased to `trackSubmit`. |
| 211 | + */ |
| 212 | + trackForm( |
| 213 | + forms: Element | Array<unknown>, |
| 214 | + event: any, |
| 215 | + properties?: any |
| 216 | + ): AnalyticsJS; |
| 217 | + |
| 218 | + /** |
| 219 | + * Trigger a pageview, labeling the current page with an optional `category`, |
| 220 | + * `name` and `properties`. |
| 221 | + */ |
| 222 | + page( |
| 223 | + category: string, |
| 224 | + name: string, |
| 225 | + properties: any, |
| 226 | + options: any, |
| 227 | + fn: unknown |
| 228 | + ): AnalyticsJS; |
| 229 | + |
| 230 | + /** |
| 231 | + * Merge two previously unassociated user identities. |
| 232 | + */ |
| 233 | + alias( |
| 234 | + to: string, |
| 235 | + from?: string, |
| 236 | + options?: unknown, |
| 237 | + fn?: unknown |
| 238 | + ): AnalyticsJS; |
| 239 | + |
| 240 | + /** |
| 241 | + * Register a `fn` to be fired when all the analytics services are ready. |
| 242 | + */ |
| 243 | + ready(fn: Function): AnalyticsJS; |
| 244 | + |
| 245 | + /** |
| 246 | + * Set the `timeout` (in milliseconds) used for callbacks. |
| 247 | + */ |
| 248 | + timeout(timeout: number): void; |
| 249 | + |
| 250 | + /** |
| 251 | + * Enable or disable debug. |
| 252 | + */ |
| 253 | + debug(str: string | boolean): void; |
| 254 | + |
| 255 | + /** |
| 256 | + * Reset group and user traits and id's. |
| 257 | + */ |
| 258 | + reset(): void; |
| 259 | + |
| 260 | + /** |
| 261 | + * Normalize the given `msg`. |
| 262 | + */ |
| 263 | + normalize(msg: { context: { page }; anonymousId: string }): object; |
| 264 | + |
| 265 | + /** |
| 266 | + * No conflict support. |
| 267 | + */ |
| 268 | + noConflict(): AnalyticsJS; |
| 269 | + } |
| 270 | +} |
| 271 | + |
| 272 | +declare var analytics: SegmentAnalytics.AnalyticsJS; |
| 273 | + |
| 274 | +declare module '@segment/analytics.js-core' { |
| 275 | + var analytics: SegmentAnalytics.AnalyticsJS; |
| 276 | + export default analytics; |
| 277 | +} |
0 commit comments