@usermaven/sdk-js 1.0.3 → 1.0.6

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.
@@ -24,7 +24,7 @@ export type UsermavenClient = {
24
24
  // * additional detection (user-agent, url and so on will be done). No payload structure is enforced
25
25
  // * @param payload
26
26
  // */
27
- rawTrack: (payload: any) => void
27
+ rawTrack: (payload: any) => Promise<void>
28
28
 
29
29
  /**
30
30
  * Sets a user data including organization/company data
@@ -87,10 +87,23 @@ export type Policy = 'strict' | 'keep' | 'comply'
87
87
  */
88
88
  export type UsermavenOptions = {
89
89
 
90
+ /**
91
+ * A custom fetch implementation. Here's how Jitsu decides what functions to use to execute HTTP requests
92
+ *
93
+ * - If Jitsu runs in browser, this parameter will be ignored. The best available API (most likely, XMLHttpRequest)
94
+ * will be used for sending reqs
95
+ * - For node Jitsu will use this param. If it's not set, Jitsu will try to search for fetch in global environment
96
+ * and will fail if it's absent
97
+ *
98
+ *
99
+ *
100
+ */
101
+ fetch?: any,
102
+
90
103
  /**
91
- * If auto-capturing is enabled on all sort of events | for future work
104
+ * Forces Jitsu SDK to use the fetch implementation (custom or default) even in browser
92
105
  */
93
- autocapture?: boolean,
106
+ force_use_fetch?: any,
94
107
 
95
108
  /**
96
109
  * If Usermaven should work in compatibility mode. If set to true:
@@ -185,24 +198,79 @@ export type UsermavenOptions = {
185
198
  * Log level. 'WARN' if not set
186
199
  */
187
200
  log_level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
201
+
202
+ /**
203
+ * Headers that should be added to each request. Could be either static dict or function that returns the dict
204
+ */
205
+ custom_headers?: Record<string, string> | (() => Record<string, string>)
188
206
 
189
207
  /**
190
208
  * Type of persistence required
191
209
  * Possible values: cookie | localStorage | localStorage+cookie | memory
192
- * Default value: cookie
210
+ *
211
+ * @default cookie
193
212
  */
194
- persistence?: PersistenceType;
213
+ persistence?: PersistenceType;
195
214
 
196
215
  /**
197
216
  * Persistent connection name
198
217
  */
199
- persistence_name?: string;
218
+ persistence_name?: string;
219
+
220
+ /**
221
+ * Session tracking time in seconds (x)
222
+ * After x seconds of inactivity, new session will be created. Default time is 30 minutes i.e 1800 seconds
223
+ *
224
+ * @default 1800
225
+ */
226
+ persistence_time?: number;
227
+
228
+ /**
229
+ * Disable session tracking here
230
+ *
231
+ * @default false
232
+ */
233
+ disable_persistence?: boolean;
234
+
235
+ /**
236
+ * Auto-capturing is disabled by default
237
+ *
238
+ * @default false
239
+ */
240
+ autocapture?: boolean,
241
+
242
+ /**
243
+ * Should a page_view event be triggered on page load
244
+ *
245
+ * @default true
246
+ */
247
+ capture_pageview?: boolean,
248
+
249
+ /**
250
+ * To control the payload properties character limit. Defaults to null that means there is no limit. i.e 65535
251
+ *
252
+ * @default null
253
+ */
254
+ properties_string_max_length?: number | null,
255
+
256
+ /**
257
+ * Property names that must be exempted from the payload of capture call
258
+ *
259
+ * @default []
260
+ */
261
+ property_blacklist?: string[],
200
262
 
201
263
  /**
202
264
  * Persistent connection version
203
265
  */
204
266
  project_id?: string;
205
267
 
268
+ /**
269
+ * Enable cookie across subdomain
270
+ * Default value: true
271
+ */
272
+ cross_subdomain_cookie?: boolean;
273
+
206
274
  //NOTE: If any property is added here, please make sure it's added to browser.ts usermavenProps as well
207
275
 
208
276
  };
@@ -213,6 +281,7 @@ export type UsermavenOptions = {
213
281
  export interface CompanyProps {
214
282
  id: string; // Company ID
215
283
  name: string; // Company Name
284
+ created_at: string; // Company creation date
216
285
  custom: any; // Optional attributes such as industry, website, employee count etc.
217
286
  }
218
287
 
@@ -255,31 +324,109 @@ export type EventCtx = {
255
324
  user: UserProps //user properties
256
325
  company?: CompanyProps //company properties
257
326
  ids?: ThirdpartyIds //user ids from external systems
258
- user_agent: string //user
259
327
  utc_time: string //current UTC time in ISO 8601
260
328
  local_tz_offset: number //local timezone offset (in minutes)
329
+
330
+ utm: Record<string, string> //utm tags (without utm prefix, e.g key will be "source", not utm_source. See
331
+ click_id: Record<string, string> //all external click ids (passed through URL). See CLICK_IDS for supported all supported click ids
332
+ [propName: string]: any //context is extendable, any extra properties can be added here
333
+
334
+ }
335
+
336
+
337
+ /**
338
+ * Tracking environment. Encapsulates environment such as Node browser or
339
+ */
340
+ export type TrackingEnvironment = {
341
+ /**
342
+ * Describes "client": page title, url, etc. See type definition
343
+ */
344
+ describeClient(): Partial<ClientProperties>;
345
+ /**
346
+ * Returns source ip. If IP should be resolved by Jitsu server, this method should return undefined
347
+ */
348
+ getSourceIp(): string | undefined;
349
+
350
+ /**
351
+ * Gets (and persists) anonymous id. Example implementation: id can be persisted in cookies or in other way.
352
+ *
353
+ */
354
+ getAnonymousId(cookieOpts: { name: string, domain?: string }): string;
355
+ };
356
+ /**
357
+ * List of environments where Jitsu tracker can work. See TrackingEnvironment above
358
+ * to learn what is the environment
359
+ */
360
+ export type Envs = {
361
+ // /**
362
+ // * Environment where requests and responses are based on fetch API Request & Response object.
363
+ // * Example: NextJS Middleware (https://nextjs.org/docs/middleware) is based on this API
364
+ // */
365
+ // fetchApi(req, res);
366
+ // /**
367
+ // * Alias of fetchApi
368
+ // */
369
+ // nextjsMiddleware(req, res);
370
+
371
+ /**
372
+ * Environment where requests and responses are based on core Node.js http APIs (IncomingMessage and Server Response)
373
+ * Example: NextJS APIs (except Middleware) is based on this one, or Express
374
+ */
375
+ httpApi(req, res);
376
+ /**
377
+ * Alias of httpApi
378
+ */
379
+ nextjsApi(req, res);
380
+ /**
381
+ * Alias of httpApi. For requests handled by Express
382
+ */
383
+ express(req, res);
384
+ /**
385
+ * Browser environment (based on window, document and etc globals)
386
+ */
387
+ browser();
388
+ /**
389
+ * Empty environment
390
+ */
391
+ empty();
392
+ }
393
+
394
+ declare const envs: Envs;
395
+
396
+
397
+ /**
398
+ * Environment where the event have happened.
399
+ */
400
+ export type ClientProperties = {
401
+ screen_resolution: string //screen resolution
402
+ user_agent: string //user
261
403
  referer: string //document referer
262
404
  url: string //current url
263
405
  page_title: string //page title
264
- //see UTM_TYPES for all supported utm tags
406
+ //see UTM_TYPES for all supported utm tags
265
407
  doc_path: string //document path
266
408
  doc_host: string //document host
267
409
  doc_search: string //document search string
268
- screen_resolution: string //screen resolution
410
+
269
411
  vp_size: string //viewport size
270
412
  user_language: string //user language
271
-
272
413
  doc_encoding: string
273
-
274
- utm: Record<string, string> //utm tags (without utm prefix, e.g key will be "source", not utm_source. See
275
- click_id: Record<string, string> //all external click ids (passed through URL). See CLICK_IDS for supported all supported click ids
276
- [propName: string]: any //context is extendable, any extra properties can be added here
277
414
  }
278
415
 
279
416
  /**
280
417
  * Optional data that can be added to each event. Consist from optional fields,
281
418
  */
282
- export type EventPayload = {
419
+ export type EventPayload = Partial<ClientProperties> & {
420
+ /**
421
+ * If track() is called in node env, it's possible to provide
422
+ * request/response. In this case Jitsu will try to use it for
423
+ * getting request data (url, referer and etc). Also, it will be used for
424
+ * setting and getting cookies
425
+ */
426
+ req?: Request
427
+ res?: Response
428
+ env?: TrackingEnvironment
429
+
283
430
  conversion?: Conversion //Conversion data if events indicates a conversion
284
431
  src_payload?: any, //Third-party payload if event is intercepted from third-party source
285
432
  [propName: string]: any //payload is extendable, any extra properties can be added here