@usermaven/sdk-js 1.3.3 → 1.4.1-rc.58

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,541 +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
- /**
310
- * Company Attributes
311
- */
312
- export interface CompanyProps {
313
- id: string; // Company ID
314
- name: string; // Company Name
315
- created_at: string; // Company creation date
316
- custom: any; // Optional attributes such as industry, website, employee count etc.
317
- }
318
-
319
- /**
320
- * User properties (ids).
321
- */
322
- export interface UserProps {
323
- anonymous_id?: string //anonymous is (cookie or ls based),
324
- id?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
325
- email?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
326
- [propName: string]: any //any other forms of ids
327
- company?: CompanyProps
328
- }
329
-
330
-
331
- /**
332
- * Ids for third-party tracking systems
333
- */
334
- export type ThirdpartyIds = {
335
- [id: string]: string
336
- }
337
-
338
- export type Conversion = {
339
- //The purpose of this set is mainly to minic GA's set of parameters
340
- //(see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters)
341
-
342
- transaction_id?: string | number //id of transaction
343
- affiliation?: string | number //affiliation id
344
- revenue?: number //revenue
345
- currency?: string //currency
346
- shipping_cost?: number //shipping cost
347
- tax?: number //tax cost
348
-
349
- }
350
-
351
- /**
352
- * Event context. Data that is present in any event type. EventContext is assembled automatically
353
- */
354
- export type EventCtx = {
355
- event_id: string //unique event id or empty string for generating id on the backend side
356
- user: UserProps //user properties
357
- company?: CompanyProps //company properties
358
- ids?: ThirdpartyIds //user ids from external systems
359
- utc_time: string //current UTC time in ISO 8601
360
- local_tz_offset: number //local timezone offset (in minutes)
361
-
362
- utm: Record<string, string> //utm tags (without utm prefix, e.g key will be "source", not utm_source. See
363
- click_id: Record<string, string> //all external click ids (passed through URL). See CLICK_IDS for supported all supported click ids
364
- [propName: string]: any //context is extendable, any extra properties can be added here
365
-
366
- }
367
-
368
-
369
- /**
370
- * Tracking environment. Encapsulates environment such as Node browser or
371
- */
372
- export type TrackingEnvironment = {
373
- /**
374
- * Describes "client": page title, url, etc. See type definition
375
- */
376
- describeClient(): Partial<ClientProperties>;
377
- /**
378
- * Returns source ip. If IP should be resolved by Jitsu server, this method should return undefined
379
- */
380
- getSourceIp(): string | undefined;
381
-
382
- /**
383
- * Gets (and persists) anonymous id. Example implementation: id can be persisted in cookies or in other way.
384
- *
385
- */
386
- getAnonymousId(cookieOpts: { name: string, domain?: string, crossDomainLinking?: boolean }): string;
387
- };
388
- /**
389
- * List of environments where Jitsu tracker can work. See TrackingEnvironment above
390
- * to learn what is the environment
391
- */
392
- export type Envs = {
393
- // /**
394
- // * Environment where requests and responses are based on fetch API Request & Response object.
395
- // * Example: NextJS Middleware (https://nextjs.org/docs/middleware) is based on this API
396
- // */
397
- // fetchApi(req, res);
398
- // /**
399
- // * Alias of fetchApi
400
- // */
401
- // nextjsMiddleware(req, res);
402
-
403
- /**
404
- * Environment where requests and responses are based on core Node.js http APIs (IncomingMessage and Server Response)
405
- * Example: NextJS APIs (except Middleware) is based on this one, or Express
406
- */
407
- httpApi(req, res);
408
- /**
409
- * Alias of httpApi
410
- */
411
- nextjsApi(req, res);
412
- /**
413
- * Alias of httpApi. For requests handled by Express
414
- */
415
- express(req, res);
416
- /**
417
- * Browser environment (based on window, document and etc globals)
418
- */
419
- browser();
420
- /**
421
- * Empty environment
422
- */
423
- empty();
424
- }
425
-
426
- declare const envs: Envs;
427
-
428
-
429
- /**
430
- * Environment where the event have happened.
431
- */
432
- export type ClientProperties = {
433
- screen_resolution: string //screen resolution
434
- user_agent: string //user
435
- referer: string //document referer
436
- url: string //current url
437
- page_title: string //page title
438
- //see UTM_TYPES for all supported utm tags
439
- doc_path: string //document path
440
- doc_host: string //document host
441
- doc_search: string //document search string
442
-
443
- vp_size: string //viewport size
444
- user_language: string //user language
445
- doc_encoding: string
446
- }
447
-
448
- /**
449
- * Optional data that can be added to each event. Consist from optional fields,
450
- */
451
- export type EventPayload = Partial<ClientProperties> & {
452
- /**
453
- * If track() is called in node env, it's possible to provide
454
- * request/response. In this case Jitsu will try to use it for
455
- * getting request data (url, referer and etc). Also, it will be used for
456
- * setting and getting cookies
457
- */
458
- req?: Request
459
- res?: Response
460
- env?: TrackingEnvironment
461
-
462
- conversion?: Conversion //Conversion data if events indicates a conversion
463
- src_payload?: any, //Third-party payload if event is intercepted from third-party source
464
- [propName: string]: any //payload is extendable, any extra properties can be added here
465
- }
466
-
467
- export type Transport = (url: string, jsonPayload: string) => Promise<void>
468
-
469
- /**
470
- * Type of event source
471
- */
472
- export type EventSrc =
473
- 'usermaven' | //event came directly from Usermaven
474
- 'eventn' | //same as usermaven but for 'compat' mode, see
475
- 'ga' | //event is intercepted from GA
476
- '3rdparty' | //event is intercepted from 3rdparty source
477
- 'ajs'; //event is intercepted from analytics.js
478
-
479
- /**
480
- * Basic information about the event
481
- */
482
- export type EventBasics = {
483
- source_ip?: string //IP address. Do not set this field on a client side, it will be rewritten on the server
484
- anon_ip?: string //First 3 octets of an IP address. Same as IP - will be set on a server
485
- api_key: string //JS api key
486
- src: EventSrc //Event source
487
- event_type: string //event type
488
- }
489
-
490
- /**
491
- * Event object. A final object which is send to server
492
- */
493
- export type Event = EventBasics & EventPayload & EventCtx;
494
-
495
- /**
496
- * Event object, if tracker works in compatibility mode
497
- */
498
- export type EventCompat = EventBasics & {
499
- eventn_ctx: EventCtx
500
- } & EventPayload;
501
-
502
- export type PersistenceType = 'cookie' | 'localStorage' | 'localStorage+cookie' | 'memory';
503
-
504
- // Autocapture
505
- export type Property = any
506
- export type Properties = Record<string, Property>
507
-
508
- export enum Compression {
509
- GZipJS = 'gzip-js',
510
- LZ64 = 'lz64',
511
- Base64 = 'base64',
512
- }
513
-
514
- export interface EditorParams {
515
- jsURL?: string
516
- apiURL?: string
517
- toolbarVersion?: 'toolbar'
518
- }
519
-
520
-
521
- export interface DecideResponse {
522
- status: number
523
- supportedCompression: Compression[]
524
- config: {
525
- enable_collect_everything: boolean
526
- }
527
- custom_properties: AutoCaptureCustomProperty[] // TODO: delete, not sent
528
- featureFlags: Record<string, string | boolean>
529
- sessionRecording?: {
530
- endpoint?: string
531
- }
532
- editorParams: EditorParams
533
- toolbarVersion: 'toolbar' /** deprecated, moved to editorParams */
534
- isAuthenticated: boolean
535
- }
536
-
537
- export interface AutoCaptureCustomProperty {
538
- name: string
539
- css_selector: string
540
- event_selectors: string[]
541
- }