@usermaven/sdk-js 1.0.0
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.
- package/README.md +26 -0
- package/dist/npm/usermaven.cjs.js +588 -0
- package/dist/npm/usermaven.d.ts +289 -0
- package/dist/npm/usermaven.es.js +584 -0
- package/package.json +56 -0
|
@@ -0,0 +1,289 @@
|
|
|
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) => void
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Sets a user 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
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Type of usermaven function which is exported to window.usermaven when tracker is embedded from server
|
|
67
|
+
*/
|
|
68
|
+
export type UsermavenFunction = (action: 'track' | 'id' | 'set', eventType: string, payload?: EventPayload) => void;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* User identification method:
|
|
72
|
+
* - cookie (based on cookie)
|
|
73
|
+
* - ls (localstorage)
|
|
74
|
+
* Currently only 'cookie' is supported
|
|
75
|
+
*/
|
|
76
|
+
export type IdMethod = 'cookie' | 'ls'
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Policy configuration affects cookies storage and IP handling.
|
|
80
|
+
* - strict: Usermaven doesn't store cookies and replaces last octet in IP address (10.10.10.10 -> 10.10.10.1)
|
|
81
|
+
* - keep: Usermaven uses cookies for user identification and saves full IP
|
|
82
|
+
* - comply: Usermaven checks customer country and tries to comply with Regulation laws (such as GDPR, UK's GDPR (PECR) and California's GDPR (CCPA)
|
|
83
|
+
*/
|
|
84
|
+
export type Policy = 'strict' | 'keep' | 'comply'
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Configuration options of Usermaven
|
|
88
|
+
*/
|
|
89
|
+
export type UsermavenOptions = {
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* If Usermaven should work in compatibility mode. If set to true:
|
|
93
|
+
* - event_type will be set to 'eventn' instead of 'usermaven'
|
|
94
|
+
* - EventCtx should be written in eventn_ctx node as opposed to to event root
|
|
95
|
+
*/
|
|
96
|
+
compat_mode?: boolean
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* If beacon API (https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API) should be used instead of
|
|
100
|
+
* XMLHttpRequest.
|
|
101
|
+
*
|
|
102
|
+
* Warning: beacon API might be unstable (https://volument.com/blog/sendbeacon-is-broken). Please,
|
|
103
|
+
* do not use it unless absolutely necessary
|
|
104
|
+
*/
|
|
105
|
+
use_beacon_api?: boolean
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Cookie domain that will be used to identify
|
|
109
|
+
* users. If not set, location.hostname will be used
|
|
110
|
+
*/
|
|
111
|
+
cookie_domain?: string
|
|
112
|
+
/**
|
|
113
|
+
* Tracking host (where API calls will be sent). If not set,
|
|
114
|
+
* we'd try to do the best to "guess" it. Last resort is t.usermaven.com.
|
|
115
|
+
*
|
|
116
|
+
* Though this parameter is not required, it's highly recommended to set is explicitly
|
|
117
|
+
*/
|
|
118
|
+
tracking_host?: string
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Name of id cookie. __eventn_id by default
|
|
122
|
+
*/
|
|
123
|
+
cookie_name?: string
|
|
124
|
+
/**
|
|
125
|
+
* API key. It's highly recommended to explicitely set it. Otherwise, the code will work
|
|
126
|
+
* in some cases (where server is configured with exactly one client key)
|
|
127
|
+
*/
|
|
128
|
+
key: string
|
|
129
|
+
/**
|
|
130
|
+
* If google analytics events should be intercepted. Read more about event interception
|
|
131
|
+
* at https://docs.eventnative.org/sending-data/javascript-reference/events-interception
|
|
132
|
+
*
|
|
133
|
+
* @default false
|
|
134
|
+
*/
|
|
135
|
+
ga_hook?: boolean
|
|
136
|
+
/**
|
|
137
|
+
* If google analytics events should be intercepted. Read more about event interception
|
|
138
|
+
* at https://docs.eventnative.org/sending-data/javascript-reference/events-interception
|
|
139
|
+
*
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
segment_hook?: boolean
|
|
143
|
+
/**
|
|
144
|
+
* If URL of API server call should be randomize to by-pass adblockers
|
|
145
|
+
*
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
randomize_url?: boolean
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* If Usermaven should capture third-party cookies: either array
|
|
152
|
+
* of cookies name or false if the features should be disabled
|
|
153
|
+
*
|
|
154
|
+
* @default GA/Segment/Fb cookies: ['_ga': '_fbp', '_ym_uid', 'ajs_user_id', 'ajs_anonymous_id']
|
|
155
|
+
*/
|
|
156
|
+
capture_3rd_party_cookies?: string[] | false;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* See comment on IdMethod. Currently only 'cookie' and 'cookie-less' are supported
|
|
160
|
+
*/
|
|
161
|
+
id_method?: IdMethod
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Privacy policy configuration makes all policies strict to comply with the cookies law. If set to 'strict'
|
|
165
|
+
* ip_policy = 'strict' and cookie_policy = 'strict' will be set.
|
|
166
|
+
* Currently only 'strict' is supported
|
|
167
|
+
*/
|
|
168
|
+
privacy_policy?: 'strict'
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* IP policy see Policy
|
|
172
|
+
*/
|
|
173
|
+
ip_policy?: Policy
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Cookie policy see Policy
|
|
177
|
+
*/
|
|
178
|
+
cookie_policy?: Policy
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Log level. 'WARN' if not set
|
|
182
|
+
*/
|
|
183
|
+
log_level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
|
|
184
|
+
|
|
185
|
+
//NOTE: If any property is added here, please make sure it's added to browser.ts usermavenProps as well
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* User properties (ids).
|
|
190
|
+
*/
|
|
191
|
+
export interface UserProps {
|
|
192
|
+
anonymous_id?: string //anonymous is (cookie or ls based),
|
|
193
|
+
id?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
|
|
194
|
+
email?: string //user id (non anonymous). If not set, first known id (from propName below) will be used
|
|
195
|
+
[propName: string]: any //any other forms of ids
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Ids for third-party tracking systems
|
|
200
|
+
*/
|
|
201
|
+
export type ThirdpartyIds = {
|
|
202
|
+
[id: string]: string
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type Conversion = {
|
|
206
|
+
//The purpose of this set is mainly to minic GA's set of parameters
|
|
207
|
+
//(see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters)
|
|
208
|
+
|
|
209
|
+
transaction_id?: string | number //id of transaction
|
|
210
|
+
affiliation?: string | number //affiliation id
|
|
211
|
+
revenue?: number //revenue
|
|
212
|
+
currency?: string //currency
|
|
213
|
+
shipping_cost?: number //shipping cost
|
|
214
|
+
tax?: number //tax cost
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Event context. Data that is present in any event type. EventContext is assembled automatically
|
|
220
|
+
*/
|
|
221
|
+
export type EventCtx = {
|
|
222
|
+
event_id: string //unique event id or empty string for generating id on the backend side
|
|
223
|
+
user: UserProps //user properties
|
|
224
|
+
ids?: ThirdpartyIds //user ids from external systems
|
|
225
|
+
user_agent: string //user
|
|
226
|
+
utc_time: string //current UTC time in ISO 8601
|
|
227
|
+
local_tz_offset: number //local timezone offset (in minutes)
|
|
228
|
+
referer: string //document referer
|
|
229
|
+
url: string //current url
|
|
230
|
+
page_title: string //page title
|
|
231
|
+
//see UTM_TYPES for all supported utm tags
|
|
232
|
+
doc_path: string //document path
|
|
233
|
+
doc_host: string //document host
|
|
234
|
+
doc_search: string //document search string
|
|
235
|
+
screen_resolution: string //screen resolution
|
|
236
|
+
vp_size: string //viewport size
|
|
237
|
+
user_language: string //user language
|
|
238
|
+
|
|
239
|
+
doc_encoding: string
|
|
240
|
+
|
|
241
|
+
utm: Record<string, string> //utm tags (without utm prefix, e.g key will be "source", not utm_source. See
|
|
242
|
+
click_id: Record<string, string> //all external click ids (passed through URL). See CLICK_IDS for supported all supported click ids
|
|
243
|
+
[propName: string]: any //context is extendable, any extra properties can be added here
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Optional data that can be added to each event. Consist from optional fields,
|
|
248
|
+
*/
|
|
249
|
+
export type EventPayload = {
|
|
250
|
+
conversion?: Conversion //Conversion data if events indicates a conversion
|
|
251
|
+
src_payload?: any, //Third-party payload if event is intercepted from third-party source
|
|
252
|
+
[propName: string]: any //payload is extendable, any extra properties can be added here
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export type Transport = (url: string, jsonPayload: string) => Promise<void>
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Type of event source
|
|
259
|
+
*/
|
|
260
|
+
export type EventSrc =
|
|
261
|
+
'jitsu' | //event came directly from Usermaven
|
|
262
|
+
'eventn' | //same as usermaven but for 'compat' mode, see
|
|
263
|
+
'ga' | //event is intercepted from GA
|
|
264
|
+
'3rdparty' | //event is intercepted from 3rdparty source
|
|
265
|
+
'ajs'; //event is intercepted from analytics.js
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Basic information about the event
|
|
269
|
+
*/
|
|
270
|
+
export type EventBasics = {
|
|
271
|
+
source_ip?: string //IP address. Do not set this field on a client side, it will be rewritten on the server
|
|
272
|
+
anon_ip?: string //First 3 octets of an IP address. Same as IP - will be set on a server
|
|
273
|
+
api_key: string //JS api key
|
|
274
|
+
src: EventSrc //Event source
|
|
275
|
+
event_type: string //event type
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Event object. A final object which is send to server
|
|
280
|
+
*/
|
|
281
|
+
export type Event = EventBasics & EventPayload & EventCtx;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Event object, if tracker works in compatibility mode
|
|
285
|
+
*/
|
|
286
|
+
export type EventCompat = EventBasics & {
|
|
287
|
+
eventn_ctx: EventCtx
|
|
288
|
+
} & EventPayload;
|
|
289
|
+
|