@nommos/core 0.0.3
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 +527 -0
- package/package.json +16 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +11 -0
- package/src/index.js.map +1 -0
- package/src/lib/constants.d.ts +11 -0
- package/src/lib/constants.js +55 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/data-attribution.d.ts +65 -0
- package/src/lib/data-attribution.js +213 -0
- package/src/lib/data-attribution.js.map +1 -0
- package/src/lib/enums.d.ts +30 -0
- package/src/lib/enums.js +37 -0
- package/src/lib/enums.js.map +1 -0
- package/src/lib/event-tracker.d.ts +55 -0
- package/src/lib/event-tracker.js +174 -0
- package/src/lib/event-tracker.js.map +1 -0
- package/src/lib/types.d.ts +40 -0
- package/src/lib/types.js +3 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/utils.d.ts +24 -0
- package/src/lib/utils.js +52 -0
- package/src/lib/utils.js.map +1 -0
- package/src/lib/webSocket-client.d.ts +69 -0
- package/src/lib/webSocket-client.js +132 -0
- package/src/lib/webSocket-client.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
# @nommos/core
|
|
2
|
+
|
|
3
|
+
A core typed library, have constants, functions, types, enums and classes which serve as bases for the framework based nommos user activity tracking module.
|
|
4
|
+
|
|
5
|
+
## 🧩 Compatibility
|
|
6
|
+
|
|
7
|
+
| Technology | Version |
|
|
8
|
+
|-----------|---------|
|
|
9
|
+
| **Node.js** | ≥ 14.x |
|
|
10
|
+
| **TypeScript** | ≥ 4.7 |
|
|
11
|
+
| **Browser Support** | Modern browsers + evergreen versions |
|
|
12
|
+
|
|
13
|
+
## 🛠 Technologies & Build System
|
|
14
|
+
|
|
15
|
+
This library is built with:
|
|
16
|
+
|
|
17
|
+
- TypeScript
|
|
18
|
+
- RxJS
|
|
19
|
+
- ES2022 output
|
|
20
|
+
- Jest
|
|
21
|
+
- UUID
|
|
22
|
+
- STOMP-JS
|
|
23
|
+
|
|
24
|
+
## 🏷 Tags
|
|
25
|
+
|
|
26
|
+
tracking, analytics, typescript, events, observables, nommos, webSockets
|
|
27
|
+
|
|
28
|
+
## Enums Definitions
|
|
29
|
+
|
|
30
|
+
### `ANALYTICS_ACTION`
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
enum ANALYTICS_ACTION {
|
|
34
|
+
SIGNIN = 'SIGNIN',
|
|
35
|
+
REGISTRATION = 'REGISTRATION',
|
|
36
|
+
BET = 'BET',
|
|
37
|
+
MENU = 'MENU',
|
|
38
|
+
TOURNAMENT = 'TOURNAMENT',
|
|
39
|
+
SPORT = 'SPORT',
|
|
40
|
+
DEPOSIT = 'DEPOSIT',
|
|
41
|
+
VISIT = 'VISIT',
|
|
42
|
+
COUPON = 'COUPON',
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
#### Description
|
|
46
|
+
Represents the various actions that are carried by a user.
|
|
47
|
+
|
|
48
|
+
#### Members
|
|
49
|
+
| Member | Value | Description |
|
|
50
|
+
|--------|-------|-------------|
|
|
51
|
+
| `SIGNIN` | `"SIGNIN"` | login or sign in action |
|
|
52
|
+
| `REGISTRATION` | `"REGISTRATION"` | registration or sign up action |
|
|
53
|
+
| `BET` | `"BET"` | Bet selection and placement action |
|
|
54
|
+
| `MENU` | `"MENU"` | Menu selection action |
|
|
55
|
+
| `TOURNAMENT` | `"TOURNAMENT"` | Tournament selection action |
|
|
56
|
+
| `SPORT` | `"SPORT"` | Sport selection action |
|
|
57
|
+
| `DEPOSIT` | `"DEPOSIT"` | Deposit or refill account action |
|
|
58
|
+
| `VISIT` | `"VISIT"` | Site or platform is visited action |
|
|
59
|
+
| `COUPON` | `"COUPON"` | Making or using a coupon code action |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### `ANALYTICS_ACTION_STATE`
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
enum ANALYTICS_ACTION_STATE {
|
|
67
|
+
SELECT = 'SELECT',
|
|
68
|
+
UNSELECT = 'UN_SELECT',
|
|
69
|
+
SUBMIT = 'SUBMIT',
|
|
70
|
+
SUCCESS = 'SUCCESS',
|
|
71
|
+
FAILURE = 'FAILURE',
|
|
72
|
+
INIT = 'INIT',
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
#### Description
|
|
76
|
+
Represents the various states associated to an action carried by a user.
|
|
77
|
+
|
|
78
|
+
### Members
|
|
79
|
+
| Member | Value | Description |
|
|
80
|
+
|--------|-------|-------------|
|
|
81
|
+
| `SELECT` | `"SELECT"` | An action was selected |
|
|
82
|
+
| `UNSELECT` | `"UN_SELECT"` | An action was unselected |
|
|
83
|
+
| `SUBMIT` | `"SUBMIT"` | An action was submitted |
|
|
84
|
+
| `SUCCESS` | `"SUCCESS"` | An action was successful |
|
|
85
|
+
| `FAILURE` | `"FAILURE"` | An action failed |
|
|
86
|
+
| `INIT` | `"INIT"` | An action was initialized |
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### `SITE_SOURCE`
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
enum SITE_SOURCE {
|
|
94
|
+
FACEBOOK = 'FACEBOOK',
|
|
95
|
+
INSTAGRAM = 'INSTAGRAM',
|
|
96
|
+
TWITTER = 'TWITTER',
|
|
97
|
+
TELEGRAM = 'TELEGRAM',
|
|
98
|
+
DIRECT = 'DIRECT',
|
|
99
|
+
SMS = 'SMS',
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
#### Description
|
|
103
|
+
Represents the platform (Social Media, SMS or direct access) the user used to have access to the site where his actions are monitored.
|
|
104
|
+
|
|
105
|
+
#### Members
|
|
106
|
+
| Member | Value | Description |
|
|
107
|
+
|--------|-------|-------------|
|
|
108
|
+
| `FACEBOOK` | `"FACEBOOK"` | Accessed from Facebook |
|
|
109
|
+
| `INSTAGRAM` | `"INSTAGRAM"` | Accessed from Instagram |
|
|
110
|
+
| `TWITTER` | `"TWITTER"` | Accessed from Twitter |
|
|
111
|
+
| `TELEGRAM` | `"TELEGRAM"` | Accessed from Telegram |
|
|
112
|
+
| `DIRECT` | `"DIRECT"` | Accessed directly |
|
|
113
|
+
| `SMS` | `"SMS"` | Accessed from an SMS |
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Types and Interfaces Definitions
|
|
117
|
+
|
|
118
|
+
### `Interface: ConnectionConfig`
|
|
119
|
+
```ts
|
|
120
|
+
interface ConnectionConfig {
|
|
121
|
+
token: string;
|
|
122
|
+
mode: string;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
#### Description
|
|
126
|
+
An Interface representing the required information for initializing the tracking module. All connection details are fetched from the API using the provided token.
|
|
127
|
+
|
|
128
|
+
#### Fields
|
|
129
|
+
| Field | type | Description |
|
|
130
|
+
|--------|-------|-------------|
|
|
131
|
+
| `token` | `string` | The access token for fetching configuration |
|
|
132
|
+
| `mode` | `string` | Run tracking module in 'dev' or 'prod' mode |
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### `Interface: UrlTrackingKey`
|
|
136
|
+
```ts
|
|
137
|
+
interface UrlTrackingKey {
|
|
138
|
+
source: string;
|
|
139
|
+
affiliateKey?: string;
|
|
140
|
+
parrainageKey?: string;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
#### Description
|
|
144
|
+
An Interface representing the query parameters that should be tracked on the site url to get the `SITE_SOURCE` and optionly the `affiliateCode` (for affiliate Tracking) and the `parrainageCode` (for parrainage Tracking)
|
|
145
|
+
|
|
146
|
+
#### Fields
|
|
147
|
+
| Field | type | Description |
|
|
148
|
+
|--------|-------|-------------|
|
|
149
|
+
| `source` | `string` | The query parameter key for `SITE_SOURCE`|
|
|
150
|
+
| `affiliateKey` | `string` | The optional query parameter key for `affiliateCode`|
|
|
151
|
+
| `parrainageKey` | `string` | The optional query parameter key for `parrainageCode` |
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### `Interface: AnalyticsEvent`
|
|
155
|
+
```ts
|
|
156
|
+
interface AnalyticsEvent {
|
|
157
|
+
timeStamp: number;
|
|
158
|
+
channel: number;
|
|
159
|
+
source: SITE_SOURCE;
|
|
160
|
+
action: ANALYTICS_ACTION;
|
|
161
|
+
state: ANALYTICS_ACTION_STATE;
|
|
162
|
+
affiliateCode?: string;
|
|
163
|
+
uid: string;
|
|
164
|
+
bid: string;
|
|
165
|
+
ip?: string;
|
|
166
|
+
data?: Record<string, unknown>;
|
|
167
|
+
meta?: Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
#### Description
|
|
171
|
+
An Interface representing the event being actually tracked, holding information which are exploited in analytics.
|
|
172
|
+
|
|
173
|
+
#### Fields
|
|
174
|
+
| Field | type | Description |
|
|
175
|
+
|--------|-------|-------------|
|
|
176
|
+
| `timeStamp` | `number` | The date and time at which the action was carried|
|
|
177
|
+
| `channel` | `number` | Information if the action was carried out on a mobile device or a desktop|
|
|
178
|
+
| `source` | `SITE_SOURCE` | The platform from which the user came from |
|
|
179
|
+
| `action` | `ANALYTICS_ACTION` | The action carried out by the user |
|
|
180
|
+
| `state` | `ANALYTICS_ACTION_STATE` | The state associated to the action carried out by the user |
|
|
181
|
+
| `affiliateCode` | `string` | The affilate code tracked from the site url |
|
|
182
|
+
| `uid` | `string` | The ID of the user who carried out the action |
|
|
183
|
+
| `bid` | `string` | An string to uniquely identify a user from the navigator used |
|
|
184
|
+
| `ip` | `string` | Optional IP address of the machine from which the user is accessing the site |
|
|
185
|
+
| `data` | `Record<string, unknown>` | Optional extra information concerning the action carried out by the user|
|
|
186
|
+
| `meta` | `Record<string, unknown>` | Optional meta data of where the action was carried by the user|
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### `Type: ActionSelectState`
|
|
190
|
+
```ts
|
|
191
|
+
type AnalyticsEvent = Record<ANALYTICS_ACTION, boolean>;
|
|
192
|
+
```
|
|
193
|
+
#### Description
|
|
194
|
+
A type to represent the select state (`SELECT` or `UNSELECT`) of actions (`ANALYTICS_ACTION`) tracked.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
## Functions
|
|
198
|
+
|
|
199
|
+
### `Function: getQueryParams`
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
getQueryParams(url)
|
|
203
|
+
```
|
|
204
|
+
#### Description
|
|
205
|
+
Extracts the query parameters from a url.
|
|
206
|
+
|
|
207
|
+
#### Parameters
|
|
208
|
+
| Name | Type | Required | Description |
|
|
209
|
+
|------|------|----------|-------------|
|
|
210
|
+
| `url` | `string` | `true`| The url from which to extra query parameters |
|
|
211
|
+
|
|
212
|
+
#### Returns
|
|
213
|
+
- `Record<string, string>` - The records of the query parameters (key, value)
|
|
214
|
+
|
|
215
|
+
### Examples
|
|
216
|
+
```ts
|
|
217
|
+
import { getQueryParams } from "@nommos/core";
|
|
218
|
+
|
|
219
|
+
getQueryParams("http://example.com?name=james&department=science&count=61");
|
|
220
|
+
// Returns: { name: "james", department: "science", count: "61"}
|
|
221
|
+
|
|
222
|
+
getQueryParams("http://example.com");
|
|
223
|
+
// Returns: {}
|
|
224
|
+
|
|
225
|
+
getQueryParams("");
|
|
226
|
+
// Returns: {}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### `Function: normString`
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
normString(s)
|
|
233
|
+
```
|
|
234
|
+
#### Description
|
|
235
|
+
Format a string by removing trailing spaces and lower cases it.
|
|
236
|
+
|
|
237
|
+
#### Parameters
|
|
238
|
+
| Name | Type | Required | Description |
|
|
239
|
+
|------|------|----------|-------------|
|
|
240
|
+
| `s` | `string` | `true`| The string to format|
|
|
241
|
+
|
|
242
|
+
#### Returns
|
|
243
|
+
- `string` - formatted string
|
|
244
|
+
|
|
245
|
+
### Examples
|
|
246
|
+
```ts
|
|
247
|
+
import { normString } from "@nommos/core";
|
|
248
|
+
|
|
249
|
+
normString(" hello world ");
|
|
250
|
+
// Returns: "hello world"
|
|
251
|
+
|
|
252
|
+
getQueryParams("Big Bang Theory ");
|
|
253
|
+
// Returns: "big bang theory"
|
|
254
|
+
|
|
255
|
+
getQueryParams("GOOD-MORNING");
|
|
256
|
+
// Returns: "good-morning"
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### `Function: userAgentInfo`
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
userAgentInfo(ua)
|
|
263
|
+
```
|
|
264
|
+
#### Description
|
|
265
|
+
Get browser, operating system and channel (mobile or desktop) of a user agent.
|
|
266
|
+
|
|
267
|
+
#### Parameters
|
|
268
|
+
| Name | Type | Required | Description |
|
|
269
|
+
|------|------|----------|-------------|
|
|
270
|
+
| `ua` | `string` | `true`| The user agent of the device|
|
|
271
|
+
|
|
272
|
+
#### Returns
|
|
273
|
+
- `{browser: string, os: string, channel: 3 | 7}` - Object having browser, operating system and channel information|
|
|
274
|
+
|
|
275
|
+
### Examples
|
|
276
|
+
```ts
|
|
277
|
+
import { userAgentInfo } from "@nommos/core";
|
|
278
|
+
|
|
279
|
+
userAgentInfo("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36");
|
|
280
|
+
// Returns: {browser: "Chrome 119", os: "macOs 10.15.7", channel: 7 }
|
|
281
|
+
|
|
282
|
+
userAgentInfo("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0");
|
|
283
|
+
// Returns: {browser: "Chrome 119", os: "Windows 10.0", channel: 7 }
|
|
284
|
+
|
|
285
|
+
userAgentInfo("Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36");
|
|
286
|
+
// Returns: {browser: "Chrome 114", os: "Android 10", channel: 3 }
|
|
287
|
+
```
|
|
288
|
+
## Classes
|
|
289
|
+
|
|
290
|
+
### `Class: DataAttribution`
|
|
291
|
+
|
|
292
|
+
#### Description
|
|
293
|
+
Represents a wrapper to extract informations associated to events being tracked and make them accessible for user activity tracking.
|
|
294
|
+
|
|
295
|
+
#### Properties
|
|
296
|
+
| Property | Type | Description | Default|
|
|
297
|
+
|----------|------|-------------|--------|
|
|
298
|
+
| `loadedUserIp$` | `Observable<boolean>` | Observable to know if the user IP address was captured | none |
|
|
299
|
+
| `hasParrainOrAffiliate$` | `Observable<boolean>` | Observable to know if Affiliate or Parrainage code was captured | none|
|
|
300
|
+
| `stripUrlTrackedParams$` | `Observable<boolean>` | Observable to know whether to strip tracked query parameters from the url | none|
|
|
301
|
+
| `stripUrlTrackedParams$` | `Observable<boolean>` | Observable to know whether to strip tracked query parameters from the url | none|
|
|
302
|
+
|
|
303
|
+
#### Constructor
|
|
304
|
+
```ts
|
|
305
|
+
constructor(private readonly urlTrackingKey: UrlTrackingKey)
|
|
306
|
+
```
|
|
307
|
+
##### Parameters
|
|
308
|
+
| Name | Type | Required |Description|
|
|
309
|
+
|------|------|----------|-----------|
|
|
310
|
+
| `urlTrackingKey` | `UrlTrackingKey` | `true` | Query parameters to capture from url for tracking |
|
|
311
|
+
|
|
312
|
+
#### Getters
|
|
313
|
+
##### `Getter: browserId`
|
|
314
|
+
###### Description
|
|
315
|
+
Unique identifier for the browser used to visit the site
|
|
316
|
+
###### Returns `string`
|
|
317
|
+
|
|
318
|
+
##### `Getter: userIp`
|
|
319
|
+
###### Description
|
|
320
|
+
IP address of the machine used to visit the site
|
|
321
|
+
###### Returns `string`
|
|
322
|
+
|
|
323
|
+
##### `Getter: source`
|
|
324
|
+
###### Description
|
|
325
|
+
Source of the user visiting the site
|
|
326
|
+
###### Returns `SITE_SOURCE`
|
|
327
|
+
|
|
328
|
+
##### `Getter: affiliate`
|
|
329
|
+
###### Description
|
|
330
|
+
Affiliate code from the url used by the user
|
|
331
|
+
###### Returns `string | null`
|
|
332
|
+
|
|
333
|
+
##### `Getter: parrainage`
|
|
334
|
+
###### Description
|
|
335
|
+
Parrainage code from the url used by the user
|
|
336
|
+
###### Returns `string | null`
|
|
337
|
+
|
|
338
|
+
##### `Getter: trackAffiliate`
|
|
339
|
+
###### Description
|
|
340
|
+
Tells us if an affiliate code was not yet tracked and should be tracked or it should not.
|
|
341
|
+
###### Returns `boolean`
|
|
342
|
+
|
|
343
|
+
#### Methods
|
|
344
|
+
#### `Method: init`
|
|
345
|
+
##### Description
|
|
346
|
+
Initialize the capturing of query parameters to track from the site url
|
|
347
|
+
|
|
348
|
+
##### Parameters
|
|
349
|
+
|
|
350
|
+
| Name | Type | Required |Description|
|
|
351
|
+
|------|------|----------|-----------|
|
|
352
|
+
| `currentUrl` | `string` | `true` | Url from which to capture query parameters for tracking |
|
|
353
|
+
| `options` | `{ stripFromUrl?: boolean }` | `false` | Object to strip query parameters from url after capturing them. By default they are stripped off |
|
|
354
|
+
|
|
355
|
+
##### Returns `void`
|
|
356
|
+
|
|
357
|
+
#### `Method: setLoadedIP`
|
|
358
|
+
##### Description
|
|
359
|
+
Pushes a true to the `loadedUserIP$` observable
|
|
360
|
+
##### Parameters `none`
|
|
361
|
+
##### Returns `void`
|
|
362
|
+
|
|
363
|
+
#### `Method: fetchIp`
|
|
364
|
+
##### Description
|
|
365
|
+
Fetches the IP address of the machine used to accessed the site and sets the current user IP address.
|
|
366
|
+
##### Parameters `none`
|
|
367
|
+
##### Returns `Observable<void>`
|
|
368
|
+
|
|
369
|
+
#### `Method: clearSourceSession`
|
|
370
|
+
##### Description
|
|
371
|
+
Clears the source key value from session storage
|
|
372
|
+
##### Parameters `none`
|
|
373
|
+
##### Returns `void`
|
|
374
|
+
|
|
375
|
+
#### `Method: clearAffiliateSession`
|
|
376
|
+
##### Description
|
|
377
|
+
Clears the affiliate code key value from session storage
|
|
378
|
+
##### Parameters `none`
|
|
379
|
+
##### Returns `void`
|
|
380
|
+
|
|
381
|
+
#### `Method: clearAffiliateHistory`
|
|
382
|
+
##### Description
|
|
383
|
+
Clears the affiliate code key value history from session storage
|
|
384
|
+
##### Parameters `none`
|
|
385
|
+
##### Returns `void`
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
### `Class: WebSocketClient`
|
|
389
|
+
|
|
390
|
+
#### Description
|
|
391
|
+
Represents a wrapper for connecting/disconnecting from rabbit, keeping track of pending events tracked not yet published, publishing events tracked and managed rabbit reconnections and publishing of pending events tracked.
|
|
392
|
+
|
|
393
|
+
#### Properties
|
|
394
|
+
| Property | Type | Description | Default|
|
|
395
|
+
|----------|------|-------------|--------|
|
|
396
|
+
| `pendingEvents` | `AnalyticsEvent[]` | List of pending tracked events not yet published | `[]` |
|
|
397
|
+
| `stompAnalyticsConnected$` | `Observable<boolean>` | Observable for connection status to web socket for events publishing | none |
|
|
398
|
+
|
|
399
|
+
#### Constructor
|
|
400
|
+
```ts
|
|
401
|
+
constructor()
|
|
402
|
+
```
|
|
403
|
+
##### Parameters - `none`
|
|
404
|
+
|
|
405
|
+
#### Methods
|
|
406
|
+
#### `Method: connectAnalyticsStomp`
|
|
407
|
+
##### Description
|
|
408
|
+
Establishes a STOMP WebSocket connection and wires lifecycle handlers.
|
|
409
|
+
- On successful connection:
|
|
410
|
+
- Emits `true` for reactive subscribers
|
|
411
|
+
- Flushes all queued analytics events
|
|
412
|
+
- On broker error:
|
|
413
|
+
- Logs structured error output
|
|
414
|
+
|
|
415
|
+
##### Parameters
|
|
416
|
+
|
|
417
|
+
| Name | Type | Required |Description|
|
|
418
|
+
|------|------|----------|-----------|
|
|
419
|
+
| `cfg` | `ConnectionConfig` | `true` | Configuration including URL, credentials, mode etc for connecting to the websocket |
|
|
420
|
+
|
|
421
|
+
##### Returns `void`
|
|
422
|
+
|
|
423
|
+
#### `Method: publishAnalyticsMessage`
|
|
424
|
+
##### Description
|
|
425
|
+
Publishes a tracked event to a RabbitMQ queue.
|
|
426
|
+
If the connection is not ready, the event is automatically queued and delivered once the socket reconnects.
|
|
427
|
+
|
|
428
|
+
##### Parameters
|
|
429
|
+
|
|
430
|
+
| Name | Type | Required |Description|
|
|
431
|
+
|------|------|----------|-----------|
|
|
432
|
+
| `payload` | `AnalyticsEvent` | `true` | The analytics event to send |
|
|
433
|
+
|
|
434
|
+
##### Returns `void`
|
|
435
|
+
|
|
436
|
+
#### `Method: disconnect`
|
|
437
|
+
##### Description
|
|
438
|
+
Gracefully shuts down the STOMP client and updates connection status.
|
|
439
|
+
Safe to call even if the client was never created or already disconnected.
|
|
440
|
+
|
|
441
|
+
##### Parameters `none`
|
|
442
|
+
|
|
443
|
+
##### Returns `void`
|
|
444
|
+
|
|
445
|
+
### `Class: EventTracker`
|
|
446
|
+
|
|
447
|
+
#### Description
|
|
448
|
+
Represents a wrapper to initialize tracking and publishing of events with required informations and meta data. Once an instance is made, data about the user and found on the site current url are captured, and connection to the rabbit webs socket is established.
|
|
449
|
+
|
|
450
|
+
#### Properties
|
|
451
|
+
| Property | Type | Description | Default|
|
|
452
|
+
|----------|------|-------------|--------|
|
|
453
|
+
| `analyticsEvent$` | `Observable<AnalyticsEvent>` | Observable holding recently pushed tracked event | none |
|
|
454
|
+
|
|
455
|
+
#### Constructor
|
|
456
|
+
```ts
|
|
457
|
+
constructor( private readonly cfg: ConnectionConfig, private readonly urlTrackingKey: UrlTrackingKey)
|
|
458
|
+
```
|
|
459
|
+
##### Parameters
|
|
460
|
+
| Name | Type | Required |Description|
|
|
461
|
+
|------|------|----------|-----------|
|
|
462
|
+
| `cfg` | `ConnectionConfig` | `true` | Configuration config to initialize the web socket connection |
|
|
463
|
+
| `urlTrackingKey` | `UrlTrackingKey` | `true` | Query parameters to initialize an instance of `DataAttribution` for information collection |
|
|
464
|
+
|
|
465
|
+
#### Methods
|
|
466
|
+
#### `Method: trackingIsEnabled`
|
|
467
|
+
##### Description
|
|
468
|
+
Tells whether tracking is enabled/disabled from config
|
|
469
|
+
|
|
470
|
+
##### Parameters - `none`
|
|
471
|
+
|
|
472
|
+
##### Returns `boolean`
|
|
473
|
+
|
|
474
|
+
#### `Method: getActionSelectState`
|
|
475
|
+
##### Description
|
|
476
|
+
Get the selection state of an action
|
|
477
|
+
|
|
478
|
+
##### Parameters
|
|
479
|
+
| Name | Type | Required |Description|
|
|
480
|
+
|------|------|----------|-----------|
|
|
481
|
+
| `action` | `ANALYTICS_ACTION` | `true` | Action you want to know the selection state |
|
|
482
|
+
|
|
483
|
+
##### Returns `boolean`
|
|
484
|
+
|
|
485
|
+
#### `Method: setActionSelectState`
|
|
486
|
+
##### Description
|
|
487
|
+
Set the selection state of an action
|
|
488
|
+
|
|
489
|
+
##### Parameters
|
|
490
|
+
| Name | Type | Required |Description|
|
|
491
|
+
|------|------|----------|-----------|
|
|
492
|
+
| `action` | `ANALYTICS_ACTION` | `true` | Action you want to set the selection state |
|
|
493
|
+
| `selected` | `boolean` | `true` | selection state |
|
|
494
|
+
|
|
495
|
+
##### Returns `void`
|
|
496
|
+
|
|
497
|
+
#### `Method: trackEvent`
|
|
498
|
+
##### Description
|
|
499
|
+
Constructs the user interaction event and emits it into a pipeline for storage. The event has the action, action state, extra information associated to the action and the user, and information gotten from the `DataAttribution` instance and the user agent of the device used. the mode of operation to set the action state. This method:
|
|
500
|
+
- Resolves the correct `SELECT` or `UNSELECT` state
|
|
501
|
+
- Enriches the event with attribution information
|
|
502
|
+
- Extracts browser/channel/OS from the user agent
|
|
503
|
+
- Publishes the event to s pipeline for storage
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
##### Parameters
|
|
507
|
+
| Name | Type | Required |Description|
|
|
508
|
+
|------|------|----------|-----------|
|
|
509
|
+
| `action` | `ANALYTICS_ACTION` | `true` | Action to be tracked|
|
|
510
|
+
| `state` | `ANALYTICS_ACTION_STATE` | `true` | State associated to the action being tracked|
|
|
511
|
+
| `data` | `Record<string, unknown> \| null` | `false` | Extra information associated to the action being tracked|
|
|
512
|
+
| `toggle` | `boolean` | `false` | Boolean value to know whether toggle selection state of the Action|
|
|
513
|
+
| `selected` | `boolean \| null` | `false` | Boolean value to set the selection state of the action tracked, it is prioritized over `toggle`|
|
|
514
|
+
| `userId` | `string` | `false` | ID of the user whom carried out the `action`|
|
|
515
|
+
| `currentUrl` | `string` | `false` | The url of the page where the action was carried out by the user|
|
|
516
|
+
|
|
517
|
+
##### Returns `void`
|
|
518
|
+
|
|
519
|
+
#### `Method: unsubscribe`
|
|
520
|
+
##### Description
|
|
521
|
+
Unsubscribe to subscriptions made during connection to the web socket, fetching the machine IP address and publishing events tracked. This should be called on destroying an instance of this class.
|
|
522
|
+
|
|
523
|
+
##### Parameters `none`
|
|
524
|
+
|
|
525
|
+
##### Returns `void`
|
|
526
|
+
|
|
527
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nommos/core",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.3.0",
|
|
9
|
+
"@stomp/stompjs": "^7.2.1",
|
|
10
|
+
"rxjs": "~7.8.0",
|
|
11
|
+
"uuid": "^13.0.0"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=14 <23"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/enums"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/types"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/utils"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/constants"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/data-attribution"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/webSocket-client"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/event-tracker"), exports);
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../nommos/core/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,sDAA4B;AAC5B,sDAA4B;AAC5B,0DAAgC;AAChC,iEAAuC;AACvC,iEAAuC;AACvC,8DAAoC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UaDef } from './types';
|
|
2
|
+
export declare const CONFIG_ENDPOINT = "https://api.nommos.ai/api/social/init";
|
|
3
|
+
export declare const SOURCE_KEY = "attr:source";
|
|
4
|
+
export declare const AFFILIATE_KEY = "attr:affiliate";
|
|
5
|
+
export declare const PARRAINAGE_KEY = "attr:parrainage";
|
|
6
|
+
export declare const AFFILIATE_HISTORY_KEY = "attr:affiliate:history";
|
|
7
|
+
export declare const ONE_YEAR_MS: number;
|
|
8
|
+
export declare const BROWSER_KEY = "anon:device_id";
|
|
9
|
+
export declare const ANALYTICS_QUEUE = "/queue/user.activity";
|
|
10
|
+
export declare const BROWSER_DEFS: UaDef[];
|
|
11
|
+
export declare const OS_DEFS: UaDef[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OS_DEFS = exports.BROWSER_DEFS = exports.ANALYTICS_QUEUE = exports.BROWSER_KEY = exports.ONE_YEAR_MS = exports.AFFILIATE_HISTORY_KEY = exports.PARRAINAGE_KEY = exports.AFFILIATE_KEY = exports.SOURCE_KEY = exports.CONFIG_ENDPOINT = void 0;
|
|
4
|
+
exports.CONFIG_ENDPOINT = 'https://api.nommos.ai/api/social/init';
|
|
5
|
+
exports.SOURCE_KEY = 'attr:source';
|
|
6
|
+
exports.AFFILIATE_KEY = 'attr:affiliate';
|
|
7
|
+
exports.PARRAINAGE_KEY = 'attr:parrainage';
|
|
8
|
+
exports.AFFILIATE_HISTORY_KEY = 'attr:affiliate:history'; // { v: string[], e: number }
|
|
9
|
+
exports.ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
|
|
10
|
+
exports.BROWSER_KEY = 'anon:device_id';
|
|
11
|
+
exports.ANALYTICS_QUEUE = '/queue/user.activity';
|
|
12
|
+
exports.BROWSER_DEFS = [
|
|
13
|
+
[/Edg\/([\d.]+)/, 'Edge'],
|
|
14
|
+
[/OPR\/([\d.]+)/, 'Opera'],
|
|
15
|
+
[/Chrome\/([\d.]+)/, 'Chrome'], // Edge/Opera are checked first, so this is safe
|
|
16
|
+
[/Firefox\/([\d.]+)/, 'Firefox'],
|
|
17
|
+
[/Version\/([\d.]+)\s+Safari\//, 'Safari'],
|
|
18
|
+
[/Mozilla\/([\d.]+)/, 'Mozilla'],
|
|
19
|
+
[/MSIE ([\d.]+)/, 'Internet Explorer'],
|
|
20
|
+
[/Trident\/.*rv:([\d.]+)/, 'Internet Explorer'],
|
|
21
|
+
[/Brave\/([\d.]+)/, 'Brave'],
|
|
22
|
+
[/Vivaldi\/([\d.]+)/, 'Vivaldi'],
|
|
23
|
+
[/SamsungBrowser\/([\d.]+)/, 'Samsung Internet'],
|
|
24
|
+
[/UCBrowser\/([\d.]+)/, 'UC Browser'],
|
|
25
|
+
[/YaBrowser\/([\d.]+)/, 'Yandex Browser'],
|
|
26
|
+
[/QQBrowser\/([\d.]+)/, 'QQ Browser'],
|
|
27
|
+
[/SogouMobileBrowser\/([\d.]+)/, 'Sogou Mobile Browser'],
|
|
28
|
+
[/Puffin\/([\d.]+)/, 'Puffin'],
|
|
29
|
+
[/DuckDuckGo\/([\d.]+)/, 'DuckDuckGo'],
|
|
30
|
+
];
|
|
31
|
+
exports.OS_DEFS = [
|
|
32
|
+
[/Windows NT ([\d.]+)/i, 'Windows'],
|
|
33
|
+
[/Android\s+([\d.]+)/i, 'Android'],
|
|
34
|
+
[/iPhone OS (\d+[_\d.]*)/i, 'iOS', (m) => m[1].replace(/_/g, '.')],
|
|
35
|
+
[/iPad; CPU OS (\d+[_\d.]*)/i, 'iPadOS', (m) => m[1].replace(/_/g, '.')],
|
|
36
|
+
[/Mac OS X (\d+[_\d.]*)/i, 'macOS', (m) => m[1].replace(/_/g, '.')],
|
|
37
|
+
[/Linux (\w+)? ([\d.]+)/i, 'Linux', (m) => m[2]],
|
|
38
|
+
[/CrOS (\w+) ([\d.]+)/i, 'Chrome OS', (m) => m[2]],
|
|
39
|
+
[/KaiOS\/([\d.]+)/i, 'KaiOS'],
|
|
40
|
+
[/Tizen\/([\d.]+)/i, 'Tizen'],
|
|
41
|
+
[/webOS\/([\d.]+)/i, 'webOS'],
|
|
42
|
+
[/BlackBerry[\d.]+\/([\d.]+)/i, 'BlackBerry'],
|
|
43
|
+
[/Windows Phone ([\d.]+)/i, 'Windows Phone'],
|
|
44
|
+
[/FreeBSD ([\d.]+)/i, 'FreeBSD'],
|
|
45
|
+
[/OpenBSD ([\d.]+)/i, 'OpenBSD'],
|
|
46
|
+
[/NetBSD ([\d.]+)/i, 'NetBSD'],
|
|
47
|
+
[/SunOS ([\d.]+)/i, 'Solaris'],
|
|
48
|
+
[/Haiku ([\d.]+)/i, 'Haiku'],
|
|
49
|
+
[/AIX ([\d.]+)/i, 'AIX'],
|
|
50
|
+
[/HP-UX ([\d.]+)/i, 'HP-UX'],
|
|
51
|
+
[/IRIX ([\d.]+)/i, 'IRIX'],
|
|
52
|
+
[/BeOS ([\d.]+)/i, 'BeOS'],
|
|
53
|
+
[/AmigaOS ([\d.]+)/i, 'AmigaOS'],
|
|
54
|
+
];
|
|
55
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../nommos/core/src/lib/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,eAAe,GAAG,uC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