@usermaven/sdk-js 1.4.3 → 1.5.0-rc.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,546 +0,0 @@
1
- export declare function usermavenClient(opts: UsermavenOptions): UsermavenClient
2
-
3
- export type UsermavenClient = {
4
- /**
5
- * Sends a third-party event (event intercepted from third-party system, such as analytics.js or GA). Should
6
- * not be called directly
7
- * @param typeName event name of event
8
- * @param _3pData third-party payload. The structure depend on
9
- * @param type event-type
10
- * @return promise that is resolved after executed.
11
- * However, if beacon API is used (see TrackerOption.use_beacon) promise will be resolved immediately
12
- */
13
- _send3p: (typeName: EventSrc, _3pPayload: any, type?: string) => Promise<void>
14
- /**
15
- * Sends a track event to server
16
- * @param name event name
17
- * @param payload event payload
18
- * @return Promise, see _send3p documentation
19
- */
20
- track: (typeName: string, payload?: EventPayload) => Promise<void>
21
-
22
- // /**
23
- // * Similar to track(), but send unstructured payload to EventNative processing pipeline. No
24
- // * additional detection (user-agent, url and so on will be done). No payload structure is enforced
25
- // * @param payload
26
- // */
27
- rawTrack: (payload: any) => Promise<void>
28
-
29
- /**
30
- * Sets a user data including organization/company data
31
- * @param userData user data (as map id_type --> value, such as "email": "a@bcd.com"
32
- * @param doNotSendEvent if true (false by default), separate "id" event won't be sent to server
33
- * @return Promise, see _send3p documentation
34
- */
35
- id: (userData: UserProps, doNotSendEvent?: boolean) => Promise<void>
36
- /**
37
- * Initializes tracker. Must be called
38
- * @param initialization options
39
- */
40
- init: (opts: UsermavenOptions) => void
41
-
42
- /**
43
- * Explicit call for intercepting Segment's analytics.
44
- * @param analytics window.analytics object
45
- */
46
- interceptAnalytics: (analytics: any) => void
47
-
48
- /**
49
- * Sets a permanent properties that will be persisted across sessions. On every track() call those properties
50
- * will be merged with `payload` parameter
51
- * @param properties properties
52
- * @param opts options.
53
- * eventType - apply permanent properties to only certain event type (applied to all types by default)
54
- * persist - persist properties across sessions (in cookies). True by default
55
- */
56
- set(properties: Record<string, any>, opts?: { eventType?: string, persist?: boolean });
57
-
58
- /**
59
- * User
60
- */
61
- unset(propertyName: string, opts: { eventType?: string, persist?: boolean });
62
-
63
- /**
64
- * Trigger for auto-captured event.
65
- * @param name event name
66
- * @param payload event payload
67
- * @return Promise, see _send3p documentation
68
- */
69
- capture?: (name: string, properties?: EventPayload, opts?: UsermavenOptions) => void
70
-
71
-
72
- }
73
-
74
- /**
75
- * Type of usermaven function which is exported to window.usermaven when tracker is embedded from server
76
- */
77
- export type UsermavenFunction = (action: 'track' | 'id' | 'set', eventType: string, payload?: EventPayload) => void;
78
-
79
- /**
80
- * User identification method:
81
- * - cookie (based on cookie)
82
- * - ls (localstorage)
83
- * Currently only 'cookie' is supported
84
- */
85
- export type IdMethod = 'cookie' | 'ls'
86
-
87
- /**
88
- * Policy configuration affects cookies storage and IP handling.
89
- * - strict: Usermaven doesn't store cookies and replaces last octet in IP address (10.10.10.10 -> 10.10.10.1)
90
- * - keep: Usermaven uses cookies for user identification and saves full IP
91
- * - comply: Usermaven checks customer country and tries to comply with Regulation laws (such as GDPR, UK's GDPR (PECR) and California's GDPR (CCPA)
92
- */
93
- export type Policy = 'strict' | 'keep' | 'comply'
94
-
95
- /**
96
- * Configuration options of Usermaven
97
- */
98
- export type UsermavenOptions = {
99
-
100
- /**
101
- * A custom fetch implementation. Here's how Jitsu decides what functions to use to execute HTTP requests
102
- *
103
- * - If Jitsu runs in browser, this parameter will be ignored. The best available API (most likely, XMLHttpRequest)
104
- * will be used for sending reqs
105
- * - For node Jitsu will use this param. If it's not set, Jitsu will try to search for fetch in global environment
106
- * and will fail if it's absent
107
- *
108
- *
109
- *
110
- */
111
- fetch?: any,
112
-
113
- /**
114
- * Forces Jitsu SDK to use the fetch implementation (custom or default) even in browser
115
- */
116
- force_use_fetch?: any,
117
-
118
- /**
119
- * If Usermaven should work in compatibility mode. If set to true:
120
- * - event_type will be set to 'eventn' instead of 'usermaven'
121
- * - EventCtx should be written in eventn_ctx node as opposed to to event root
122
- */
123
- compat_mode?: boolean
124
-
125
- /**
126
- * If beacon API (https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API) should be used instead of
127
- * XMLHttpRequest.
128
- *
129
- * Warning: beacon API might be unstable (https://volument.com/blog/sendbeacon-is-broken). Please,
130
- * do not use it unless absolutely necessary
131
- */
132
- use_beacon_api?: boolean
133
-
134
- /**
135
- * Cookie domain that will be used to identify
136
- * users. If not set, location.hostname will be used
137
- */
138
- cookie_domain?: string
139
- /**
140
- * Tracking host (where API calls will be sent). If not set,
141
- * we'd try to do the best to "guess" it. Last resort is t.usermaven.com.
142
- *
143
- * Though this parameter is not required, it's highly recommended to set is explicitly
144
- */
145
- tracking_host?: string
146
-
147
- /**
148
- * Name of id cookie. __eventn_id_{data-key} by default
149
- */
150
- cookie_name?: string
151
- /**
152
- * API key. It's highly recommended to explicitely set it. Otherwise, the code will work
153
- * in some cases (where server is configured with exactly one client key)
154
- */
155
- key: string
156
- /**
157
- * If google analytics events should be intercepted. Read more about event interception
158
- * at https://docs.eventnative.org/sending-data/javascript-reference/events-interception
159
- *
160
- * @default false
161
- */
162
- ga_hook?: boolean
163
- /**
164
- * If google analytics events should be intercepted. Read more about event interception
165
- * at https://docs.eventnative.org/sending-data/javascript-reference/events-interception
166
- *
167
- * @default false
168
- */
169
- segment_hook?: boolean
170
- /**
171
- * If URL of API server call should be randomize to by-pass adblockers
172
- *
173
- * @default false
174
- */
175
- randomize_url?: boolean
176
-
177
- /**
178
- * If Usermaven should capture third-party cookies: either array
179
- * of cookies name or false if the features should be disabled
180
- *
181
- * @default GA/Segment/Fb cookies: ['_ga': '_fbp', '_ym_uid', 'ajs_user_id', 'ajs_anonymous_id']
182
- */
183
- capture_3rd_party_cookies?: string[] | false;
184
-
185
- /**
186
- * See comment on IdMethod. Currently only 'cookie' and 'cookie-less' are supported
187
- */
188
- id_method?: IdMethod
189
-
190
- /**
191
- * Privacy policy configuration makes all policies strict to comply with the cookies law. If set to 'strict'
192
- * ip_policy = 'strict' and cookie_policy = 'strict' will be set.
193
- * Currently only 'strict' is supported
194
- */
195
- privacy_policy?: 'strict'
196
-
197
- /**
198
- * IP policy see Policy
199
- */
200
- ip_policy?: Policy
201
-
202
- /**
203
- * Cookie policy see Policy
204
- */
205
- cookie_policy?: Policy
206
-
207
- /**
208
- * Log level. 'WARN' if not set
209
- */
210
- log_level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
211
-
212
- /**
213
- * Headers that should be added to each request. Could be either static dict or function that returns the dict
214
- */
215
- custom_headers?: Record<string, string> | (() => Record<string, string>)
216
-
217
- /**
218
- * Minimum timeout before re-attempting to send events.
219
- * Defaults to 0.
220
- */
221
- min_send_timeout?: number
222
-
223
- /**
224
- * Maximum timeout before re-attempting to send events.
225
- * Defaults to 2 seconds.
226
- */
227
- max_send_timeout?: number
228
-
229
- /**
230
- * Maximum number of send event attempts.
231
- * Defaults to 4.
232
- */
233
- max_send_attempts?: number
234
-
235
- /**
236
- * Whether failed events should NOT be persisted when applicable.
237
- */
238
- disable_event_persistence?: boolean
239
-
240
- /**
241
- * Auto-capturing is disabled by default
242
- *
243
- * @default false
244
- */
245
- autocapture?: boolean,
246
-
247
- /**
248
- * Auto pageview is disabled by default
249
- *
250
- * @default false
251
- */
252
- auto_pageview?: boolean,
253
-
254
- /**
255
- * To control the payload properties character limit. Defaults to null that means there is no limit. i.e 65535
256
- *
257
- * @default null
258
- */
259
- properties_string_max_length?: number | null,
260
-
261
- /**
262
- * Property names that must be exempted from the payload of capture call
263
- *
264
- * @default []
265
- */
266
- property_blacklist?: string[],
267
-
268
- /**
269
- * Persistent connection version
270
- */
271
- project_id?: string;
272
-
273
-
274
- //NOTE: If any property is added here, please make sure it's added to browser.ts usermavenProps as well
275
-
276
- /**
277
- * Mask all element attributes
278
- */
279
- mask_all_element_attributes?: boolean
280
-
281
- /**
282
- * Mask all text
283
- */
284
- mask_all_text?: boolean
285
-
286
- /**
287
- * Exclude pages
288
- */
289
- exclude?: string
290
-
291
-
292
- /**
293
- * Namespace
294
- */
295
- namespace?: string
296
-
297
- /**
298
- * Cross domain linking (if true, Usermaven will try to extract query params or hash from URL)
299
- */
300
- cross_domain_linking?: boolean
301
-
302
- /**
303
- * Domains that should be used for cross domain linking
304
- * @example "*.mydomain.com,*mydomain2.com"
305
- */
306
- domains?: string
307
-
308
- /**
309
- * Form tracking
310
- */
311
- form_tracking?: 'all' | 'tagged' | 'none' | boolean
312
- };
313
-
314
- /**
315
- * Company Attributes
316
- */
317
- export interface CompanyProps {
318
- id: string; // Company ID
319
- name: string; // Company Name
320
- created_at: string; // Company creation date
321
- custom: any; // Optional attributes such as industry, website, employee count etc.
322
- }
323
-
324
- /**
325
- * User properties (ids).
326
- */
327
- export interface UserProps {
328
- anonymous_id?: string //anonymous is (cookie or ls based),
329
- id?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
330
- email?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
331
- [propName: string]: any //any other forms of ids
332
- company?: CompanyProps
333
- }
334
-
335
-
336
- /**
337
- * Ids for third-party tracking systems
338
- */
339
- export type ThirdpartyIds = {
340
- [id: string]: string
341
- }
342
-
343
- export type Conversion = {
344
- //The purpose of this set is mainly to minic GA's set of parameters
345
- //(see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters)
346
-
347
- transaction_id?: string | number //id of transaction
348
- affiliation?: string | number //affiliation id
349
- revenue?: number //revenue
350
- currency?: string //currency
351
- shipping_cost?: number //shipping cost
352
- tax?: number //tax cost
353
-
354
- }
355
-
356
- /**
357
- * Event context. Data that is present in any event type. EventContext is assembled automatically
358
- */
359
- export type EventCtx = {
360
- event_id: string //unique event id or empty string for generating id on the backend side
361
- user: UserProps //user properties
362
- company?: CompanyProps //company properties
363
- ids?: ThirdpartyIds //user ids from external systems
364
- utc_time: string //current UTC time in ISO 8601
365
- local_tz_offset: number //local timezone offset (in minutes)
366
-
367
- utm: Record<string, string> //utm tags (without utm prefix, e.g key will be "source", not utm_source. See
368
- click_id: Record<string, string> //all external click ids (passed through URL). See CLICK_IDS for supported all supported click ids
369
- [propName: string]: any //context is extendable, any extra properties can be added here
370
-
371
- }
372
-
373
-
374
- /**
375
- * Tracking environment. Encapsulates environment such as Node browser or
376
- */
377
- export type TrackingEnvironment = {
378
- /**
379
- * Describes "client": page title, url, etc. See type definition
380
- */
381
- describeClient(): Partial<ClientProperties>;
382
- /**
383
- * Returns source ip. If IP should be resolved by Jitsu server, this method should return undefined
384
- */
385
- getSourceIp(): string | undefined;
386
-
387
- /**
388
- * Gets (and persists) anonymous id. Example implementation: id can be persisted in cookies or in other way.
389
- *
390
- */
391
- getAnonymousId(cookieOpts: { name: string, domain?: string, crossDomainLinking?: boolean, cookiePolicy?: Policy }): string;
392
- };
393
- /**
394
- * List of environments where Jitsu tracker can work. See TrackingEnvironment above
395
- * to learn what is the environment
396
- */
397
- export type Envs = {
398
- // /**
399
- // * Environment where requests and responses are based on fetch API Request & Response object.
400
- // * Example: NextJS Middleware (https://nextjs.org/docs/middleware) is based on this API
401
- // */
402
- // fetchApi(req, res);
403
- // /**
404
- // * Alias of fetchApi
405
- // */
406
- // nextjsMiddleware(req, res);
407
-
408
- /**
409
- * Environment where requests and responses are based on core Node.js http APIs (IncomingMessage and Server Response)
410
- * Example: NextJS APIs (except Middleware) is based on this one, or Express
411
- */
412
- httpApi(req, res);
413
- /**
414
- * Alias of httpApi
415
- */
416
- nextjsApi(req, res);
417
- /**
418
- * Alias of httpApi. For requests handled by Express
419
- */
420
- express(req, res);
421
- /**
422
- * Browser environment (based on window, document and etc globals)
423
- */
424
- browser();
425
- /**
426
- * Empty environment
427
- */
428
- empty();
429
- }
430
-
431
- declare const envs: Envs;
432
-
433
-
434
- /**
435
- * Environment where the event have happened.
436
- */
437
- export type ClientProperties = {
438
- screen_resolution: string //screen resolution
439
- user_agent: string //user
440
- referer: string //document referer
441
- url: string //current url
442
- page_title: string //page title
443
- //see UTM_TYPES for all supported utm tags
444
- doc_path: string //document path
445
- doc_host: string //document host
446
- doc_search: string //document search string
447
-
448
- vp_size: string //viewport size
449
- user_language: string //user language
450
- doc_encoding: string
451
- }
452
-
453
- /**
454
- * Optional data that can be added to each event. Consist from optional fields,
455
- */
456
- export type EventPayload = Partial<ClientProperties> & {
457
- /**
458
- * If track() is called in node env, it's possible to provide
459
- * request/response. In this case Jitsu will try to use it for
460
- * getting request data (url, referer and etc). Also, it will be used for
461
- * setting and getting cookies
462
- */
463
- req?: Request
464
- res?: Response
465
- env?: TrackingEnvironment
466
-
467
- conversion?: Conversion //Conversion data if events indicates a conversion
468
- src_payload?: any, //Third-party payload if event is intercepted from third-party source
469
- [propName: string]: any //payload is extendable, any extra properties can be added here
470
- }
471
-
472
- export type Transport = (url: string, jsonPayload: string) => Promise<void>
473
-
474
- /**
475
- * Type of event source
476
- */
477
- export type EventSrc =
478
- 'usermaven' | //event came directly from Usermaven
479
- 'eventn' | //same as usermaven but for 'compat' mode, see
480
- 'ga' | //event is intercepted from GA
481
- '3rdparty' | //event is intercepted from 3rdparty source
482
- 'ajs'; //event is intercepted from analytics.js
483
-
484
- /**
485
- * Basic information about the event
486
- */
487
- export type EventBasics = {
488
- source_ip?: string //IP address. Do not set this field on a client side, it will be rewritten on the server
489
- anon_ip?: string //First 3 octets of an IP address. Same as IP - will be set on a server
490
- api_key: string //JS api key
491
- src: EventSrc //Event source
492
- event_type: string //event type
493
- }
494
-
495
- /**
496
- * Event object. A final object which is send to server
497
- */
498
- export type Event = EventBasics & EventPayload & EventCtx;
499
-
500
- /**
501
- * Event object, if tracker works in compatibility mode
502
- */
503
- export type EventCompat = EventBasics & {
504
- eventn_ctx: EventCtx
505
- } & EventPayload;
506
-
507
- export type PersistenceType = 'cookie' | 'localStorage' | 'localStorage+cookie' | 'memory';
508
-
509
- // Autocapture
510
- export type Property = any
511
- export type Properties = Record<string, Property>
512
-
513
- export enum Compression {
514
- GZipJS = 'gzip-js',
515
- LZ64 = 'lz64',
516
- Base64 = 'base64',
517
- }
518
-
519
- export interface EditorParams {
520
- jsURL?: string
521
- apiURL?: string
522
- toolbarVersion?: 'toolbar'
523
- }
524
-
525
-
526
- export interface DecideResponse {
527
- status: number
528
- supportedCompression: Compression[]
529
- config: {
530
- enable_collect_everything: boolean
531
- }
532
- custom_properties: AutoCaptureCustomProperty[] // TODO: delete, not sent
533
- featureFlags: Record<string, string | boolean>
534
- sessionRecording?: {
535
- endpoint?: string
536
- }
537
- editorParams: EditorParams
538
- toolbarVersion: 'toolbar' /** deprecated, moved to editorParams */
539
- isAuthenticated: boolean
540
- }
541
-
542
- export interface AutoCaptureCustomProperty {
543
- name: string
544
- css_selector: string
545
- event_selectors: string[]
546
- }