aesirx-analytics 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -29,4 +29,10 @@ interface AnalyticsContextType {
29
29
  }
30
30
  declare const AnalyticsContext: React.Context<AnalyticsContextType>;
31
31
 
32
- export { AnalyticsContext, AnalyticsNext, AnalyticsReact, trackEvent };
32
+ /**
33
+ * Function to get browser finger print
34
+ * @returns
35
+ */
36
+ declare const getFingerprint: () => string;
37
+
38
+ export { AnalyticsContext, AnalyticsNext, AnalyticsReact, getFingerprint, trackEvent };
package/dist/index.js CHANGED
@@ -34,7 +34,293 @@ var trackerService = async (endpoint, payload) => {
34
34
 
35
35
  // src/utils/index.ts
36
36
  import Bowser from "bowser";
37
- import * as FingerprintJS from "@fingerprintjs/fingerprintjs";
37
+
38
+ // src/lib/envHelper.ts
39
+ var getHashKey = () => {
40
+ let value = null;
41
+ try {
42
+ if (typeof process.env != "undefined") {
43
+ value = process.env.SECURE_LOCAL_STORAGE_HASH_KEY || process.env.REACT_APP_SECURE_LOCAL_STORAGE_HASH_KEY || process.env.NEXT_PUBLIC_SECURE_LOCAL_STORAGE_HASH_KEY || process.env.VITE_SECURE_LOCAL_STORAGE_HASH_KEY;
44
+ } else {
45
+ console.warn(`react-secure-storage : process is not defined! Just a warning!`);
46
+ }
47
+ } catch (ex) {
48
+ return null;
49
+ }
50
+ return value;
51
+ };
52
+ var getStoragePrefix = () => {
53
+ let value = null;
54
+ try {
55
+ if (typeof process.env != "undefined") {
56
+ value = process.env.SECURE_LOCAL_STORAGE_PREFIX || process.env.REACT_APP_SECURE_LOCAL_STORAGE_PREFIX || process.env.NEXT_PUBLIC_SECURE_LOCAL_STORAGE_PREFIX || process.env.VITE_SECURE_LOCAL_STORAGE_PREFIX;
57
+ } else {
58
+ console.warn(`react-secure-storage : process is not defined! Just a warning!`);
59
+ }
60
+ } catch (ex) {
61
+ return null;
62
+ }
63
+ return value;
64
+ };
65
+ var getDisabledKeys = () => {
66
+ let value = null;
67
+ try {
68
+ if (typeof process.env != "undefined") {
69
+ value = process.env.SECURE_LOCAL_STORAGE_DISABLED_KEYS || process.env.REACT_APP_SECURE_LOCAL_STORAGE_DISABLED_KEYS || process.env.NEXT_PUBLIC_SECURE_LOCAL_STORAGE_DISABLED_KEYS || process.env.VITE_SECURE_LOCAL_STORAGE_DISABLED_KEYS;
70
+ } else {
71
+ console.warn(`react-secure-storage : process is not defined! Just a warning!`);
72
+ }
73
+ } catch (ex) {
74
+ return null;
75
+ }
76
+ return value;
77
+ };
78
+ var envHelper = {
79
+ getHashKey,
80
+ getStoragePrefix,
81
+ getDisabledKeys
82
+ };
83
+ var envHelper_default = envHelper;
84
+
85
+ // src/lib/fingerpint.lib.ts
86
+ import murmurhash3_32_gc from "murmurhash-js/murmurhash3_gc";
87
+
88
+ // src/lib/utils.ts
89
+ var FINGERPRINT_KEYS = {
90
+ USERAGENT: "UserAgent",
91
+ SCREEN_PRINT: "ScreenPrint",
92
+ PLUGINS: "Plugins",
93
+ FONTS: "Fonts",
94
+ LOCAL_STORAGE: "LocalStorage",
95
+ SESSION_STORAGE: "SessionStorage",
96
+ TIMEZONE: "TimeZone",
97
+ LANGUAGE: "Language",
98
+ SYSTEM_LANGUAGE: "SystemLanguage",
99
+ COOKIE: "Cookie",
100
+ CANVAS: "Canvas",
101
+ HOSTNAME: "Hostname"
102
+ };
103
+ var getDisabledKeys2 = () => {
104
+ const DISABLED_KEYS = envHelper_default.getDisabledKeys() || "";
105
+ if (DISABLED_KEYS === "")
106
+ return [];
107
+ const allOptions = [
108
+ FINGERPRINT_KEYS.USERAGENT,
109
+ FINGERPRINT_KEYS.SCREEN_PRINT,
110
+ FINGERPRINT_KEYS.PLUGINS,
111
+ FINGERPRINT_KEYS.FONTS,
112
+ FINGERPRINT_KEYS.LOCAL_STORAGE,
113
+ FINGERPRINT_KEYS.SESSION_STORAGE,
114
+ FINGERPRINT_KEYS.TIMEZONE,
115
+ FINGERPRINT_KEYS.LANGUAGE,
116
+ FINGERPRINT_KEYS.SYSTEM_LANGUAGE,
117
+ FINGERPRINT_KEYS.COOKIE,
118
+ FINGERPRINT_KEYS.CANVAS,
119
+ FINGERPRINT_KEYS.HOSTNAME
120
+ ];
121
+ const response = [];
122
+ DISABLED_KEYS.split("|").forEach((key) => {
123
+ if (key === "") {
124
+ console.log("test");
125
+ } else if (allOptions.includes(key))
126
+ response.push(key);
127
+ else
128
+ console.warn(
129
+ `react-secure-storage : ${key} is not present in the available disabled keys options! Please go through the documentation`
130
+ );
131
+ });
132
+ return response;
133
+ };
134
+
135
+ // src/lib/fingerpint.lib.ts
136
+ var ClientJS = class {
137
+ //
138
+ // MAIN METHODS
139
+ //
140
+ // Get Fingerprint. Return a 32-bit integer representing the browsers fingerprint.
141
+ getFingerprint() {
142
+ const bar = "|";
143
+ const disabledKeys = getDisabledKeys2();
144
+ let key = "";
145
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.USERAGENT)) {
146
+ key += navigator.userAgent + bar;
147
+ }
148
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.HOSTNAME)) {
149
+ key += window.location.hostname + bar;
150
+ }
151
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.SCREEN_PRINT)) {
152
+ key += this.getScreenPrint() + bar;
153
+ }
154
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.PLUGINS)) {
155
+ key += this.getPlugins() + bar;
156
+ }
157
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.FONTS)) {
158
+ key += this.getFonts() + bar;
159
+ }
160
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.LOCAL_STORAGE)) {
161
+ key += this.isLocalStorage() + bar;
162
+ }
163
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.SESSION_STORAGE)) {
164
+ key += this.isSessionStorage() + bar;
165
+ }
166
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.TIMEZONE)) {
167
+ key += this.getTimeZone() + bar;
168
+ }
169
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.LANGUAGE)) {
170
+ key += this.getLanguage() + bar;
171
+ }
172
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.SYSTEM_LANGUAGE)) {
173
+ key += this.getSystemLanguage() + bar;
174
+ }
175
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.COOKIE)) {
176
+ key += this.isCookie() + bar;
177
+ }
178
+ if (!disabledKeys.includes(FINGERPRINT_KEYS.CANVAS)) {
179
+ key += this.getCanvasPrint();
180
+ }
181
+ if (key.endsWith(bar))
182
+ key = key.substring(0, key.length - 1);
183
+ const seed = 256;
184
+ return murmurhash3_32_gc(key, seed);
185
+ }
186
+ //
187
+ // SCREEN METHODS
188
+ //
189
+ // Get Screen Print. Return a string containing screen information.
190
+ getScreenPrint() {
191
+ return "Color Depth: " + this.getColorDepth() + ", Device XDPI: " + this.getDeviceXDPI() + ", Device YDPI: " + this.getDeviceYDPI();
192
+ }
193
+ // Get Color Depth. Return a string containing the color depth.
194
+ getColorDepth() {
195
+ return window.screen.colorDepth;
196
+ }
197
+ // Get Current Resolution. Return a string containing the current resolution.
198
+ getCurrentResolution() {
199
+ return window.screen.width + "x" + window.screen.height;
200
+ }
201
+ // Get Available Resolution. Return a string containing the available resolution.
202
+ getAvailableResolution() {
203
+ return window.screen.availWidth + "x" + window.screen.availHeight;
204
+ }
205
+ // Get Device XPDI. Return a string containing the device XPDI.
206
+ getDeviceXDPI() {
207
+ return "";
208
+ }
209
+ // Get Device YDPI. Return a string containing the device YDPI.
210
+ getDeviceYDPI() {
211
+ return "";
212
+ }
213
+ //
214
+ // PLUGIN METHODS
215
+ //
216
+ // Get Plugins. Return a string containing a list of installed plugins.
217
+ getPlugins() {
218
+ let pluginsList = "";
219
+ for (let i = 0; i < navigator.plugins.length; i++) {
220
+ if (i === navigator.plugins.length - 1) {
221
+ pluginsList += navigator.plugins[i].name;
222
+ } else {
223
+ pluginsList += navigator.plugins[i].name + ", ";
224
+ }
225
+ }
226
+ return pluginsList;
227
+ }
228
+ //
229
+ // FONT METHODS
230
+ //
231
+ // Get Fonts. Return a string containing a list of installed fonts.
232
+ getFonts() {
233
+ const fontString = "";
234
+ return fontString;
235
+ }
236
+ //
237
+ // STORAGE METHODS
238
+ //
239
+ // Is Local Storage. Check if local storage is enabled.
240
+ isLocalStorage() {
241
+ try {
242
+ return !!localStorage;
243
+ } catch (e) {
244
+ return true;
245
+ }
246
+ }
247
+ // Is Session Storage. Check if session storage is enabled.
248
+ isSessionStorage() {
249
+ try {
250
+ return !!sessionStorage;
251
+ } catch (e) {
252
+ return true;
253
+ }
254
+ }
255
+ // Is Cookie. Check if cookies are enabled.
256
+ isCookie() {
257
+ return navigator.cookieEnabled;
258
+ }
259
+ //
260
+ // TIME METHODS
261
+ //
262
+ // Get Time Zone. Return a string containing the time zone.
263
+ getTimeZone() {
264
+ const rightNow = /* @__PURE__ */ new Date();
265
+ let myNumber, formattedNumber, result;
266
+ myNumber = String(-(rightNow.getTimezoneOffset() / 60));
267
+ if (myNumber < 0) {
268
+ myNumber = myNumber * -1;
269
+ formattedNumber = ("0" + myNumber).slice(-2);
270
+ result = "-" + formattedNumber;
271
+ } else {
272
+ formattedNumber = ("0" + myNumber).slice(-2);
273
+ result = "+" + formattedNumber;
274
+ }
275
+ return result;
276
+ }
277
+ //
278
+ // LANGUAGE METHODS
279
+ //
280
+ // Get Language. Return a string containing the user language.
281
+ getLanguage() {
282
+ return navigator.language;
283
+ }
284
+ // Get System Language. Return a string containing the system language.
285
+ getSystemLanguage() {
286
+ return navigator.language || window.navigator.language;
287
+ }
288
+ // Get Canvas Print. Return a string containing the canvas URI data.
289
+ getCanvasPrint() {
290
+ const canvas = document.createElement("canvas");
291
+ let ctx;
292
+ try {
293
+ ctx = canvas.getContext("2d");
294
+ } catch (e) {
295
+ return "";
296
+ }
297
+ const txt = "ClientJS,org <canvas> 1.0";
298
+ ctx.textBaseline = "top";
299
+ ctx.font = "14px 'Arial'";
300
+ ctx.textBaseline = "alphabetic";
301
+ ctx.fillStyle = "#f60";
302
+ ctx.fillRect(125, 1, 62, 20);
303
+ ctx.fillStyle = "#069";
304
+ ctx.fillText(txt, 2, 15);
305
+ ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
306
+ ctx.fillText(txt, 4, 17);
307
+ return canvas.toDataURL();
308
+ }
309
+ };
310
+ var clientJS = new ClientJS();
311
+ var fingerpint_lib_default = clientJS;
312
+
313
+ // src/lib/fingerprint.ts
314
+ var HASH_KEY = "E86E2612010258B35137";
315
+ var getFingerprint = () => {
316
+ const HASH_KEY_CUSTOM = envHelper_default.getHashKey() || HASH_KEY;
317
+ if (typeof window === "undefined")
318
+ return HASH_KEY_CUSTOM;
319
+ return fingerpint_lib_default.getFingerprint() + HASH_KEY_CUSTOM;
320
+ };
321
+ var fingerprint_default = getFingerprint;
322
+
323
+ // src/utils/index.ts
38
324
  var createRequest = (endpoint, task) => {
39
325
  return `${endpoint}/visitor/v1/${task}`;
40
326
  };
@@ -62,34 +348,31 @@ var startTracker = async (endpoint, url, referer, user_agent) => {
62
348
  const queryString = window.location.search;
63
349
  const urlParams = new URLSearchParams(queryString);
64
350
  const ip = "";
65
- const fpPromise = FingerprintJS.load({ monitoring: false });
66
351
  try {
67
- const responseStart = fpPromise.then((fp) => fp.get()).then(async (result) => {
68
- const fingerprint = result.visitorId;
69
- const attributes = [];
70
- for (const key of urlParams.keys()) {
71
- if (key.startsWith("utm_")) {
72
- urlParams.get(key) && attributes.push({ name: key, value: urlParams.get(key) });
73
- }
352
+ const fingerprint = fingerprint_default();
353
+ const attributes = [];
354
+ for (const key of urlParams.keys()) {
355
+ if (key.startsWith("utm_")) {
356
+ urlParams.get(key) && attributes.push({ name: key, value: urlParams.get(key) });
357
+ }
358
+ }
359
+ const responseStart = await trackerService(createRequestV2(endpoint, "start"), {
360
+ fingerprint,
361
+ url,
362
+ ...referer && (referer !== url || document2.referrer) && {
363
+ referer: referer !== url ? referer : document2.referrer
364
+ },
365
+ user_agent,
366
+ ip,
367
+ browser_name,
368
+ browser_version,
369
+ lang,
370
+ device,
371
+ ...attributes?.length && {
372
+ event_name: "visit",
373
+ event_type: "action",
374
+ attributes
74
375
  }
75
- return await trackerService(createRequestV2(endpoint, "start"), {
76
- fingerprint,
77
- url,
78
- ...referer && (referer !== url || document2.referrer) && {
79
- referer: referer !== url ? referer : document2.referrer
80
- },
81
- user_agent,
82
- ip,
83
- browser_name,
84
- browser_version,
85
- lang,
86
- device,
87
- ...attributes?.length && {
88
- event_name: "visit",
89
- event_type: "action",
90
- attributes
91
- }
92
- });
93
376
  });
94
377
  if (window["aesirxTrackEcommerce"] === "true" && sessionStorage.getItem("aesirx-analytics-flow") !== (await responseStart)?.flow_uuid) {
95
378
  sessionStorage.setItem("aesirx-analytics-flow", (await responseStart)?.flow_uuid);
@@ -118,31 +401,28 @@ var trackEvent = async (endpoint, referer, data) => {
118
401
  const lang = window.navigator["userLanguage"] || window.navigator.language;
119
402
  const device = browser?.platform?.model ?? browser?.platform?.type;
120
403
  const ip = "";
121
- const fpPromise = FingerprintJS.load({ monitoring: false });
122
- const responseStart = fpPromise.then((fp) => fp.get()).then(async (result) => {
123
- const fingerprint = result.visitorId;
124
- const headers = { type: "application/json" };
125
- const blobData = new Blob(
126
- [
127
- JSON.stringify({
128
- fingerprint,
129
- url,
130
- ...referer !== "/" && referer && {
131
- referer
132
- },
133
- user_agent,
134
- ip,
135
- browser_name,
136
- browser_version,
137
- lang,
138
- device,
139
- ...data
140
- })
141
- ],
142
- headers
143
- );
144
- return navigator.sendBeacon(createRequestV2(endpoint, "start"), blobData);
145
- });
404
+ const fingerprint = fingerprint_default();
405
+ const headers = { type: "application/json" };
406
+ const blobData = new Blob(
407
+ [
408
+ JSON.stringify({
409
+ fingerprint,
410
+ url,
411
+ ...referer !== "/" && referer && {
412
+ referer
413
+ },
414
+ user_agent,
415
+ ip,
416
+ browser_name,
417
+ browser_version,
418
+ lang,
419
+ device,
420
+ ...data
421
+ })
422
+ ],
423
+ headers
424
+ );
425
+ const responseStart = navigator.sendBeacon(createRequestV2(endpoint, "start"), blobData);
146
426
  return responseStart;
147
427
  };
148
428
  var endTracker = (endPoint, event_uuid, visitor_uuid) => {
@@ -233,12 +513,13 @@ var handle_default = AnalyticsHandle;
233
513
 
234
514
  // src/AnalyticsNext/index.tsx
235
515
  import dynamic from "next/dynamic";
236
- var ConsentComponent = dynamic(() => import("./Consent-3FMR7JQE.js"), { ssr: false });
516
+ var ConsentComponent = dynamic(() => import("./Consent-HRGYMPE6.js"), { ssr: false });
237
517
  var AnalyticsNext = ({ router, children }) => {
238
518
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(AnalyticsContextProvider_default, null, /* @__PURE__ */ React2.createElement(handle_default, { router }, children, process.env.NEXT_PUBLIC_DISABLE_ANALYTICS_CONSENT !== "true" && /* @__PURE__ */ React2.createElement(
239
519
  ConsentComponent,
240
520
  {
241
521
  endpoint: process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL,
522
+ networkEnv: process.env.NEXT_PUBLIC_CONCORDIUM_NETWORK,
242
523
  aesirXEndpoint: process.env.NEXT_PUBLIC_ENDPOINT_URL ?? "https://api.aesirx.io"
243
524
  }
244
525
  ))));
@@ -285,12 +566,13 @@ var AnalyticsHandle2 = ({ location, history, children }) => {
285
566
  var handle_default2 = AnalyticsHandle2;
286
567
 
287
568
  // src/AnalyticsReact/index.tsx
288
- var ConsentComponent2 = React4.lazy(() => import("./Consent-3FMR7JQE.js"));
569
+ var ConsentComponent2 = React4.lazy(() => import("./Consent-HRGYMPE6.js"));
289
570
  var AnalyticsReact = ({ location, history, children }) => {
290
571
  return /* @__PURE__ */ React4.createElement(AnalyticsContextProvider_default, null, /* @__PURE__ */ React4.createElement(handle_default2, { location, history }, children, process.env.REACT_APP_DISABLE_ANALYTICS_CONSENT !== "true" && /* @__PURE__ */ React4.createElement(Suspense, { fallback: /* @__PURE__ */ React4.createElement(React4.Fragment, null) }, /* @__PURE__ */ React4.createElement(
291
572
  ConsentComponent2,
292
573
  {
293
574
  endpoint: process.env.REACT_APP_ENDPOINT_ANALYTICS_URL,
575
+ networkEnv: process.env.REACT_APP_CONCORDIUM_NETWORK,
294
576
  aesirXEndpoint: process.env.REACT_APP_ENDPOINT_URL ?? "https://api.aesirx.io"
295
577
  }
296
578
  ))));
@@ -300,5 +582,6 @@ export {
300
582
  AnalyticsContext,
301
583
  AnalyticsNext_default as AnalyticsNext,
302
584
  AnalyticsReact_default as AnalyticsReact,
585
+ fingerprint_default as getFingerprint,
303
586
  trackEvent
304
587
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aesirx-analytics",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "license": "GPL-3.0-only",
5
5
  "author": "AesirX",
6
6
  "repository": "https://gitlab.redweb.dk/aesirx/analytics",
@@ -9,20 +9,20 @@
9
9
  "types": "dist/index.d.ts",
10
10
  "type": "module",
11
11
  "dependencies": {
12
- "@concordium/browser-wallet-api-helpers": "^2",
13
- "@concordium/react-components": "^0.3.0",
14
- "@concordium/web-sdk": "^6",
15
- "@fingerprintjs/fingerprintjs": "3.4.2",
12
+ "@concordium/browser-wallet-api-helpers": "^3.0.0",
13
+ "@concordium/react-components": "^0.4.0-rc.7",
14
+ "@concordium/web-sdk": "^7.0.4-rc.3",
16
15
  "@web3modal/ethereum": "^2.7.0",
17
16
  "@web3modal/react": "^2.7.0",
18
- "aesirx-sso": "^1.4.3",
19
- "axios": "^1.4.0",
17
+ "aesirx-sso": "^1.4.5",
18
+ "axios": "^1.6.0",
20
19
  "bootstrap": "^5.3.2",
21
20
  "bowser": "^2.11.0",
22
21
  "buffer": "^6.0.3",
23
22
  "ethers": "^6.6.5",
24
- "i18next": "^23.4.4",
23
+ "i18next": "^23.6.0",
25
24
  "i18next-browser-languagedetector": "^7.1.0",
25
+ "murmurhash-js": "^1.0.0",
26
26
  "next": "^13.5.4",
27
27
  "query-string": "^7.1.1",
28
28
  "react": "^18.2.0",
@@ -67,9 +67,10 @@
67
67
  "@babel/preset-typescript": "^7.23.0",
68
68
  "@jest/globals": "^29.7.0",
69
69
  "@types/jest": "^29.5.0",
70
+ "@types/murmurhash-js": "^1.0.3",
70
71
  "@types/node": "^20.8.0",
71
72
  "@types/react": "^18.2.21",
72
- "@types/react-dom": "^18.2.4",
73
+ "@types/react-dom": "^18.2.14",
73
74
  "@typescript-eslint/eslint-plugin": "^5.57.0",
74
75
  "@typescript-eslint/parser": "^5.57.0",
75
76
  "@walletconnect/types": "^2.10.0",
@@ -78,7 +79,7 @@
78
79
  "esbuild-sass-plugin": "^2.15.0",
79
80
  "esbuild-scss-modules-plugin": "^1.1.1",
80
81
  "eslint": "^8.48.0",
81
- "eslint-plugin-react": "^7.31.10",
82
+ "eslint-plugin-react": "^7.33.2",
82
83
  "jest": "^29.4.3",
83
84
  "jest-environment-jsdom": "^29.4.3",
84
85
  "node-fetch": "^3.3.1",