aesirx-analytics 2.2.19 → 2.2.21

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.
@@ -0,0 +1,182 @@
1
+ import {
2
+ fingerprint_default
3
+ } from "./chunk-NTEWP6UQ.js";
4
+
5
+ // src/utils/services.ts
6
+ var cache;
7
+ var assign = (a, b) => {
8
+ Object.keys(b).forEach((key) => {
9
+ if (b[key] !== void 0)
10
+ a[key] = b[key];
11
+ });
12
+ return a;
13
+ };
14
+ var trackerService = async (endpoint, payload) => {
15
+ const fetchData = await fetch(endpoint, {
16
+ method: "POST",
17
+ body: JSON.stringify(payload),
18
+ headers: assign({ "Content-Type": "application/json" }, { ["x-tracker-cache"]: cache })
19
+ });
20
+ const response = await fetchData.json();
21
+ if (response.error) {
22
+ throw response.error;
23
+ } else {
24
+ return response;
25
+ }
26
+ };
27
+
28
+ // src/utils/index.ts
29
+ import Bowser from "bowser";
30
+ var createRequest = (endpoint, task) => {
31
+ return `${endpoint}/visitor/v1/${task}`;
32
+ };
33
+ var createRequestV2 = (endpoint, task) => {
34
+ return `${endpoint}/visitor/v2/${task}`;
35
+ };
36
+ var rememberFlow = (endpoint, flow) => {
37
+ return `${endpoint}/remember_flow/${flow}`;
38
+ };
39
+ var startTracker = async (endpoint, url, referer, user_agent, attributesVisit) => {
40
+ const allow = sessionStorage.getItem("aesirx-analytics-allow");
41
+ const reject = sessionStorage.getItem("aesirx-analytics-rejected");
42
+ if (allow === "0" || reject === "true") {
43
+ return null;
44
+ }
45
+ const { location, document: document2 } = window;
46
+ const { pathname, search, origin } = location;
47
+ url = `${origin}${pathname}${search}`;
48
+ referer = referer ? location.protocol + "//" + location.host + referer : document2.referrer ? document2.referrer : window["referer"] ? window["referer"] === "/" ? location.protocol + "//" + location.host : location.protocol + "//" + location.host + window["referer"] : "";
49
+ user_agent = window.navigator.userAgent;
50
+ const browser = Bowser.parse(window.navigator.userAgent);
51
+ const browser_name = browser?.browser?.name;
52
+ const browser_version = browser?.browser?.version ?? "0";
53
+ const lang = window.navigator["userLanguage"] || window.navigator.language;
54
+ const device = browser?.platform?.model ?? browser?.platform?.type;
55
+ const queryString = window.location.search;
56
+ const urlParams = new URLSearchParams(queryString);
57
+ const ip = "";
58
+ try {
59
+ const fingerprint = fingerprint_default();
60
+ const attributes = [];
61
+ for (const key of urlParams.keys()) {
62
+ if (key.startsWith("utm_")) {
63
+ urlParams.get(key) && attributes.push({ name: key, value: urlParams.get(key) });
64
+ }
65
+ }
66
+ if (attributesVisit?.length) {
67
+ attributesVisit?.forEach((element) => {
68
+ element?.name && attributes.push({ name: element?.name, value: element?.value });
69
+ });
70
+ }
71
+ const responseStart = await trackerService(createRequestV2(endpoint, "start"), {
72
+ fingerprint,
73
+ url: url?.replace(/^(https?:\/\/)?(www\.)?/, "$1"),
74
+ ...referer && (referer !== url || document2.referrer) && {
75
+ referer: referer !== url ? referer?.replace(/^(https?:\/\/)?(www\.)?/, "$1") : document2.referrer?.replace(/^(https?:\/\/)?(www\.)?/, "$1")
76
+ },
77
+ user_agent,
78
+ ip,
79
+ browser_name,
80
+ browser_version,
81
+ lang,
82
+ device: device?.includes("iPhone") ? "mobile" : device?.includes("iPad") ? "tablet" : device,
83
+ ...attributes?.length && {
84
+ event_name: "visit",
85
+ event_type: "action",
86
+ attributes
87
+ }
88
+ });
89
+ if (window["aesirxTrackEcommerce"] === "true" && sessionStorage.getItem("aesirx-analytics-flow") !== (await responseStart)?.flow_uuid) {
90
+ sessionStorage.setItem("aesirx-analytics-flow", (await responseStart)?.flow_uuid);
91
+ try {
92
+ await trackerService(
93
+ rememberFlow(window.location.origin, (await responseStart)?.flow_uuid),
94
+ {}
95
+ );
96
+ } catch (error) {
97
+ console.log("Remember Flow Error", error);
98
+ }
99
+ }
100
+ return responseStart;
101
+ } catch (error) {
102
+ console.error("Analytics Error: ", error);
103
+ }
104
+ };
105
+ var trackEvent = async (endpoint, referer, data) => {
106
+ const allow = sessionStorage.getItem("aesirx-analytics-allow");
107
+ const reject = sessionStorage.getItem("aesirx-analytics-rejected");
108
+ if (allow === "0" || reject === "true") {
109
+ return null;
110
+ }
111
+ const { location, document: document2 } = window;
112
+ referer = referer ? location.protocol + "//" + location.host + referer : document2.referrer ? document2.referrer : window["referer"] ? window["referer"] === "/" ? location.protocol + "//" + location.host : location.protocol + "//" + location.host + window["referer"] : "";
113
+ const url = location.protocol + "//" + location.host + location.pathname;
114
+ const user_agent = window.navigator.userAgent;
115
+ const browser = Bowser.parse(window.navigator.userAgent);
116
+ const browser_name = browser?.browser?.name;
117
+ const browser_version = browser?.browser?.version ?? "0";
118
+ const lang = window.navigator["userLanguage"] || window.navigator.language;
119
+ const device = browser?.platform?.model ?? browser?.platform?.type;
120
+ const ip = "";
121
+ const fingerprint = fingerprint_default();
122
+ const headers = { type: "application/json" };
123
+ const blobData = new Blob(
124
+ [
125
+ JSON.stringify({
126
+ fingerprint,
127
+ url: url?.replace(/^(https?:\/\/)?(www\.)?/, "$1"),
128
+ ...referer !== "/" && referer && {
129
+ referer: referer?.replace(/^(https?:\/\/)?(www\.)?/, "$1")
130
+ },
131
+ user_agent,
132
+ ip,
133
+ browser_name,
134
+ browser_version,
135
+ lang,
136
+ device: device?.includes("iPhone") ? "mobile" : device?.includes("iPad") ? "tablet" : device,
137
+ ...data
138
+ })
139
+ ],
140
+ headers
141
+ );
142
+ const responseStart = navigator.sendBeacon(createRequestV2(endpoint, "start"), blobData);
143
+ return responseStart;
144
+ };
145
+ var endTracker = (endPoint, event_uuid, visitor_uuid) => {
146
+ if (event_uuid && visitor_uuid) {
147
+ const body = {
148
+ event_uuid,
149
+ visitor_uuid
150
+ };
151
+ const headers = { type: "application/json" };
152
+ const blob = new Blob([JSON.stringify(body)], headers);
153
+ navigator.sendBeacon(createRequest(endPoint, "end"), blob);
154
+ }
155
+ };
156
+ var endTrackerVisibilityState = (endPoint) => {
157
+ document.addEventListener("visibilitychange", async () => {
158
+ if (document.visibilityState === "hidden") {
159
+ endTracker(endPoint, window["event_uuid"], window["visitor_uuid"]);
160
+ }
161
+ if (document.visibilityState === "visible") {
162
+ const response = await startTracker(endPoint, "", "", "", window["attributes"]);
163
+ window["event_uuid"] = response?.event_uuid;
164
+ }
165
+ });
166
+ window.addEventListener(
167
+ "pagehide",
168
+ (event) => {
169
+ if (event.persisted) {
170
+ endTracker(endPoint, window["event_uuid"], window["visitor_uuid"]);
171
+ }
172
+ },
173
+ false
174
+ );
175
+ };
176
+
177
+ export {
178
+ startTracker,
179
+ trackEvent,
180
+ endTracker,
181
+ endTrackerVisibilityState
182
+ };
package/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  endTracker,
3
3
  endTrackerVisibilityState,
4
- fingerprint_default,
5
4
  startTracker,
6
5
  trackEvent
7
- } from "./chunk-UJTYOAT7.js";
6
+ } from "./chunk-YOHHSMUP.js";
8
7
  import {
9
8
  AnalyticsContext,
10
9
  AnalyticsContextProvider_default,
11
10
  bg_default,
11
+ fingerprint_default,
12
12
  getConsentTemplate,
13
13
  no_default,
14
14
  privacy_default,
15
15
  useTranslation
16
- } from "./chunk-EL2DBQXP.js";
16
+ } from "./chunk-NTEWP6UQ.js";
17
17
 
18
18
  // src/AnalyticsNext/index.tsx
19
19
  import React2, { useEffect as useEffect2, useState as useState2 } from "react";
@@ -76,8 +76,8 @@ var handle_default = AnalyticsHandle;
76
76
 
77
77
  // src/AnalyticsNext/index.tsx
78
78
  import dynamic from "next/dynamic";
79
- var ConsentComponent = dynamic(() => import("./Consent-TGYEV2XV.js"), { ssr: false });
80
- var ConsentComponentCustom = dynamic(() => import("./ConsentCustom-IBIHKHPV.js"), { ssr: false });
79
+ var ConsentComponent = dynamic(() => import("./Consent-OHFGKDZJ.js"), { ssr: false });
80
+ var ConsentComponentCustom = dynamic(() => import("./ConsentCustom-UTTNESFI.js"), { ssr: false });
81
81
  var AnalyticsNext = ({
82
82
  router,
83
83
  attributes,
@@ -180,8 +180,8 @@ var AnalyticsHandle2 = ({ location, history, children }) => {
180
180
  var handle_default2 = AnalyticsHandle2;
181
181
 
182
182
  // src/AnalyticsReact/index.tsx
183
- var ConsentComponent2 = React4.lazy(() => import("./Consent-TGYEV2XV.js"));
184
- var ConsentComponentCustom2 = React4.lazy(() => import("./ConsentCustom-IBIHKHPV.js"));
183
+ var ConsentComponent2 = React4.lazy(() => import("./Consent-OHFGKDZJ.js"));
184
+ var ConsentComponentCustom2 = React4.lazy(() => import("./ConsentCustom-UTTNESFI.js"));
185
185
  var AnalyticsReact = ({
186
186
  location,
187
187
  history,
@@ -241,6 +241,7 @@ var AnalyticsReact_default = AnalyticsReact;
241
241
  // src/Components/OptInConsent.tsx
242
242
  import React5, { useEffect as useEffect5, useState as useState4 } from "react";
243
243
  import { Button, Form } from "react-bootstrap";
244
+ var endpoint = window["aesirx1stparty"] ? window["aesirx1stparty"] : process?.env?.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL ? process?.env?.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL : process?.env?.REACT_APP_ENDPOINT_ANALYTICS_URL ? process?.env?.REACT_APP_ENDPOINT_ANALYTICS_URL : "";
244
245
  var OptInConsent = ({
245
246
  optInConsentData = window?.optInConsentData ? JSON.parse(window?.optInConsentData) : []
246
247
  }) => {
@@ -277,7 +278,8 @@ var OptInConsent = ({
277
278
  "img",
278
279
  {
279
280
  className: "cover-img position-absolute h-100 w-100 object-fit-cover",
280
- src: bg_default
281
+ src: bg_default,
282
+ alt: "Background Image"
281
283
  }
282
284
  ), /* @__PURE__ */ React5.createElement(
283
285
  "div",
@@ -287,8 +289,8 @@ var OptInConsent = ({
287
289
  setShowExpandRevoke(true);
288
290
  }
289
291
  },
290
- /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "Shield of Privacy" }),
291
- t("txt_shield_of_privacy")
292
+ /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "SoP Icon" }),
293
+ window?.aesirx_analytics_translate?.txt_shield_of_privacy ?? t("txt_shield_of_privacy")
292
294
  )),
293
295
  showExpandRevoke && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
294
296
  "div",
@@ -298,7 +300,7 @@ var OptInConsent = ({
298
300
  borderBottom: "1px solid #DEDEDE"
299
301
  }
300
302
  },
301
- /* @__PURE__ */ React5.createElement("div", { className: "text-primary text-nowrap" }, t("txt_tracking_data_privacy")),
303
+ /* @__PURE__ */ React5.createElement("div", { className: "text-primary text-nowrap" }, window?.aesirx_analytics_translate?.txt_tracking_data_privacy ?? t("txt_tracking_data_privacy")),
302
304
  /* @__PURE__ */ React5.createElement("div", { className: "d-flex align-items-center fs-14 text-primary" }, /* @__PURE__ */ React5.createElement(
303
305
  "a",
304
306
  {
@@ -311,10 +313,11 @@ var OptInConsent = ({
311
313
  "img",
312
314
  {
313
315
  className: "cover-img position-absolute h-100 w-100 object-fit-cover z-1",
314
- src: bg_default
316
+ src: bg_default,
317
+ alt: "Background Image"
315
318
  }
316
319
  ),
317
- /* @__PURE__ */ React5.createElement("div", { className: "minimize-shield position-relative z-2 py-2" }, /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "Shield of Privacy" }), t("txt_shield_of_privacy"))
320
+ /* @__PURE__ */ React5.createElement("div", { className: "minimize-shield position-relative z-2 py-2" }, /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "SoP Icon" }), window?.aesirx_analytics_translate?.txt_shield_of_privacy ?? t("txt_shield_of_privacy"))
318
321
  ))
319
322
  ), /* @__PURE__ */ React5.createElement(
320
323
  "div",
@@ -324,8 +327,8 @@ var OptInConsent = ({
324
327
  setShowExpandRevoke(false);
325
328
  }
326
329
  },
327
- /* @__PURE__ */ React5.createElement("img", { src: no_default })
328
- ), /* @__PURE__ */ React5.createElement("div", { className: "p-3 bg-white" }, t("txt_you_can_revoke")), /* @__PURE__ */ React5.createElement(Form, { className: "mb-0 w-100 bg-white px-3" }, optInRevokes?.map((item, key) => {
330
+ /* @__PURE__ */ React5.createElement("img", { src: no_default, alt: "No Icon" })
331
+ ), /* @__PURE__ */ React5.createElement("div", { className: "p-3 bg-white" }, window?.aesirx_analytics_translate?.txt_you_can_revoke ?? t("txt_you_can_revoke")), /* @__PURE__ */ React5.createElement(Form, { className: "mb-0 w-100 bg-white px-3" }, optInRevokes?.map((item, key) => {
329
332
  return /* @__PURE__ */ React5.createElement(
330
333
  Form.Check,
331
334
  {
@@ -333,7 +336,7 @@ var OptInConsent = ({
333
336
  id: `option-revoke-${item}`,
334
337
  checked: revokeConsentOption === item,
335
338
  type: "checkbox",
336
- label: item === "aesirx-analytics-optin-default" ? t("txt_revoke_opt_in") : t("txt_revoke_opt_in") + " " + item?.replace("aesirx-analytics-optin-", ""),
339
+ label: item === "aesirx-analytics-optin-default" ? window?.aesirx_analytics_translate?.txt_revoke_opt_in ?? t("txt_revoke_opt_in") : window?.aesirx_analytics_translate?.txt_revoke_opt_in ?? t("txt_revoke_opt_in") + " " + item?.replace("aesirx-analytics-optin-", ""),
337
340
  value: item,
338
341
  onChange: ({ target: { value } }) => {
339
342
  setRevokeConsentOption(value);
@@ -348,7 +351,7 @@ var OptInConsent = ({
348
351
  target: "_blank",
349
352
  rel: "noreferrer"
350
353
  },
351
- t("txt_manage_consent")
354
+ window?.aesirx_analytics_translate?.txt_manage_consent ?? t("txt_manage_consent")
352
355
  ), /* @__PURE__ */ React5.createElement(
353
356
  Button,
354
357
  {
@@ -366,7 +369,7 @@ var OptInConsent = ({
366
369
  },
367
370
  className: "d-flex align-items-center justify-content-center w-100 w-lg-35 revoke-btn fs-14 rounded-pill py-2 py-lg-3"
368
371
  },
369
- t("txt_revoke_consent")
372
+ window?.aesirx_analytics_translate?.txt_revoke_consent ?? t("txt_revoke_consent")
370
373
  ))))))
371
374
  ))
372
375
  )
@@ -390,6 +393,12 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
390
393
  optIn?.handleConsent && optIn?.handleConsent();
391
394
  window?.funcAfterOptInConsent && window.funcAfterOptInConsent();
392
395
  window?.optInConsentData && document.querySelector(`.opt-in-consent.${optIn?.title}`).classList.remove("show");
396
+ const hostUrl = endpoint ? endpoint : "";
397
+ const root = hostUrl ? hostUrl.replace(/\/$/, "") : "";
398
+ root && trackEvent(root, "", {
399
+ event_name: "Opt-in consent",
400
+ event_type: "opt-in-consent"
401
+ });
393
402
  };
394
403
  const handleClose = () => {
395
404
  setShow(false);
@@ -441,7 +450,8 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
441
450
  "img",
442
451
  {
443
452
  className: "cover-img position-absolute h-100 w-100 object-fit-cover",
444
- src: bg_default
453
+ src: bg_default,
454
+ alt: "Background Image"
445
455
  }
446
456
  ), /* @__PURE__ */ React5.createElement(
447
457
  "div",
@@ -453,8 +463,8 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
453
463
  sessionStorage.removeItem("aesirx-analytics-rejected");
454
464
  }
455
465
  },
456
- /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "Shield of Privacy" }),
457
- t("txt_shield_of_privacy")
466
+ /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "SoP Icon" }),
467
+ window?.aesirx_analytics_translate?.txt_shield_of_privacy ?? t("txt_shield_of_privacy")
458
468
  ))) : /* @__PURE__ */ React5.createElement("div", { className: "bg-white" }, /* @__PURE__ */ React5.createElement(
459
469
  "div",
460
470
  {
@@ -463,7 +473,7 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
463
473
  borderBottom: "1px solid #DEDEDE"
464
474
  }
465
475
  },
466
- /* @__PURE__ */ React5.createElement("div", { className: "text-primary text-nowrap" }, t("txt_tracking_data_privacy")),
476
+ /* @__PURE__ */ React5.createElement("div", { className: "text-primary text-nowrap" }, window?.aesirx_analytics_translate?.txt_tracking_data_privacy ?? t("txt_tracking_data_privacy")),
467
477
  /* @__PURE__ */ React5.createElement("div", { className: "d-flex align-items-center fs-14 text-primary" }, /* @__PURE__ */ React5.createElement(
468
478
  "a",
469
479
  {
@@ -476,10 +486,11 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
476
486
  "img",
477
487
  {
478
488
  className: "cover-img position-absolute h-100 w-100 object-fit-cover z-1",
479
- src: bg_default
489
+ src: bg_default,
490
+ alt: "Background Image"
480
491
  }
481
492
  ),
482
- /* @__PURE__ */ React5.createElement("div", { className: "minimize-shield position-relative z-2 py-2" }, /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "Shield of Privacy" }), t("txt_shield_of_privacy"))
493
+ /* @__PURE__ */ React5.createElement("div", { className: "minimize-shield position-relative z-2 py-2" }, /* @__PURE__ */ React5.createElement("img", { src: privacy_default, alt: "SoP Icon" }), window?.aesirx_analytics_translate?.txt_shield_of_privacy ?? t("txt_shield_of_privacy"))
483
494
  ))
484
495
  ), /* @__PURE__ */ React5.createElement("div", { className: "p-4 pt-3 pb-0 bg-white" }, /* @__PURE__ */ React5.createElement(
485
496
  "div",
@@ -495,7 +506,7 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
495
506
  variant: "outline-success",
496
507
  className: "border-2 fs-7 fw-bold text-primary rounded-pill"
497
508
  },
498
- t("txt_reject_consent")
509
+ window?.aesirx_analytics_translate?.txt_reject_consent ?? t("txt_reject_consent")
499
510
  ), /* @__PURE__ */ React5.createElement(
500
511
  Button,
501
512
  {
@@ -503,7 +514,7 @@ var OptIntConsentDetail = ({ optIn, setShowRevoke }) => {
503
514
  variant: "outline-success",
504
515
  className: "border-2 fs-7 fw-bold text-primary rounded-pill"
505
516
  },
506
- t("txt_yes_i_consent")
517
+ window?.aesirx_analytics_translate?.txt_yes_i_consent ?? t("txt_yes_i_consent")
507
518
  ))))))
508
519
  )
509
520
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aesirx-analytics",
3
- "version": "2.2.19",
3
+ "version": "2.2.21",
4
4
  "license": "GPL-3.0-only",
5
5
  "author": "AesirX",
6
6
  "repository": "https://gitlab.redweb.dk/aesirx/analytics",