@dotcms/analytics 1.0.2-next.3 → 1.0.2-next.5

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 CHANGED
@@ -11,9 +11,9 @@ Lightweight JavaScript SDK for tracking content-aware events in dotCMS. Works in
11
11
  ```html
12
12
  <script
13
13
  src="ca.min.js"
14
- data-analytics-server="https://demo.dotcms.com"
15
- data-analytics-key="SITE_KEY"
16
- data-analytics-auto-page-view></script>
14
+ data-server="https://demo.dotcms.com"
15
+ data-site-key="SITE_KEY"
16
+ data-auto-page-view></script>
17
17
  ```
18
18
 
19
19
  **npm (ES Module)**
@@ -1,32 +1,31 @@
1
- import { useContext as c, useRef as u, useCallback as a } from "react";
2
- import { getUVEState as i } from "../../../uve/src/lib/core/core.utils.js";
3
- import "../../../uve/src/internal/constants.js";
1
+ import { useContext as c, useRef as u, useCallback as i } from "react";
4
2
  import l from "../contexts/DotContentAnalyticsContext.js";
5
- const S = () => {
6
- const t = c(l), n = u(null);
3
+ import { isInsideUVE as o } from "../internal/uve.utils.js";
4
+ const w = () => {
5
+ const t = c(l), e = u(null);
7
6
  if (!t)
8
7
  throw new Error(
9
8
  "useContentAnalytics must be used within a DotContentAnalyticsProvider and analytics must be successfully initialized"
10
9
  );
11
- const s = a(
12
- (o, e = {}) => {
13
- i() || t.track(o, {
14
- ...e,
10
+ const s = i(
11
+ (n, r = {}) => {
12
+ o() || t.track(n, {
13
+ ...r,
15
14
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
16
15
  });
17
16
  },
18
17
  [t]
19
- ), r = a(() => {
20
- if (!i()) {
21
- const e = window.location.pathname;
22
- e !== n.current && (n.current = e, t.pageView());
18
+ ), a = i(() => {
19
+ if (!o()) {
20
+ const n = window.location.pathname;
21
+ n !== e.current && (e.current = n, t.pageView());
23
22
  }
24
23
  }, [t]);
25
24
  return {
26
25
  track: s,
27
- pageView: r
26
+ pageView: a
28
27
  };
29
28
  };
30
29
  export {
31
- S as useContentAnalytics
30
+ w as useContentAnalytics
32
31
  };
@@ -1,12 +1,11 @@
1
- import { useRef as u, useEffect as i } from "react";
2
- import { getUVEState as a } from "../../../uve/src/lib/core/core.utils.js";
3
- import "../../../uve/src/internal/constants.js";
4
- function p(t) {
5
- const n = u(null);
6
- i(() => {
1
+ import { useRef as i, useEffect as u } from "react";
2
+ import { isInsideUVE as d } from "../internal/uve.utils.js";
3
+ function a(t) {
4
+ const n = i(null);
5
+ u(() => {
7
6
  if (!t) return;
8
7
  function e() {
9
- const o = window.location.pathname, r = a();
8
+ const o = window.location.pathname, r = d();
10
9
  o !== n.current && !r && t && (n.current = o, t.pageView());
11
10
  }
12
11
  return e(), window.addEventListener("popstate", e), window.addEventListener("beforeunload", e), () => {
@@ -15,5 +14,5 @@ function p(t) {
15
14
  }, [t]);
16
15
  }
17
16
  export {
18
- p as useRouterTracker
17
+ a as useRouterTracker
19
18
  };
@@ -0,0 +1 @@
1
+ export * from './uve.utils';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks if the code is running inside the DotCMS Universal Visual Editor (UVE).
3
+ *
4
+ * @returns {boolean} Returns true if running inside the editor, false otherwise.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * if (isInsideUVE()) {
9
+ * // Running inside UVE editor
10
+ * console.log('Inside editor');
11
+ * } else {
12
+ * // Running in normal mode
13
+ * console.log('Outside editor');
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function isInsideUVE(): boolean;
@@ -0,0 +1,6 @@
1
+ function n() {
2
+ return !(typeof window > "u" || window.parent === window || !window.location);
3
+ }
4
+ export {
5
+ n as isInsideUVE
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/analytics",
3
- "version": "1.0.2-next.3",
3
+ "version": "1.0.2-next.5",
4
4
  "description": "Official JavaScript library for Content Analytics with DotCMS.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,23 +20,39 @@
20
20
  },
21
21
  "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/analytics/README.md",
22
22
  "dependencies": {
23
- "analytics": "^0.8.14"
23
+ "analytics": "^0.8.0",
24
+ "@analytics/core": "^0.13.0",
25
+ "@analytics/storage-utils": "^0.4.0"
24
26
  },
25
27
  "peerDependencies": {
26
- "react": "^18",
27
- "@dotcms/uve": "^1.0.2"
28
+ "react": "^18 || ^19"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@testing-library/jest-dom": "^6.1.6",
31
32
  "@testing-library/react": "^14.0.0",
32
33
  "vite": "~5.0.0"
33
34
  },
34
- "main": "./index.cjs.js",
35
- "module": "./index.esm.js",
35
+ "main": "./index.js",
36
+ "module": "./index.js",
37
+ "types": "./index.d.ts",
38
+ "typesVersions": {
39
+ "*": {
40
+ "react": [
41
+ "lib/react/index.d.ts"
42
+ ],
43
+ "*": [
44
+ "index.d.ts"
45
+ ]
46
+ }
47
+ },
36
48
  "exports": {
49
+ ".": {
50
+ "import": "./index.js",
51
+ "types": "./index.d.ts"
52
+ },
37
53
  "./react": {
38
54
  "import": "./react/index.js",
39
- "types": "./src/lib/react/index.d.ts"
55
+ "types": "./lib/react/index.d.ts"
40
56
  }
41
57
  }
42
58
  }
@@ -1,5 +0,0 @@
1
- var N = /* @__PURE__ */ ((r) => (r.EDIT = "EDIT_MODE", r.PREVIEW = "PREVIEW_MODE", r.LIVE = "LIVE", r.UNKNOWN = "UNKNOWN", r))(N || {}), E = /* @__PURE__ */ ((r) => (r.CONTENT_CHANGES = "changes", r.PAGE_RELOAD = "page-reload", r.REQUEST_BOUNDS = "request-bounds", r.IFRAME_SCROLL = "iframe-scroll", r.CONTENTLET_HOVERED = "contentlet-hovered", r))(E || {});
2
- export {
3
- E as UVEEventType,
4
- N as UVE_MODE
5
- };
@@ -1,4 +0,0 @@
1
- var t = /* @__PURE__ */ ((e) => (e.UVE_RELOAD_PAGE = "uve-reload-page", e.UVE_REQUEST_BOUNDS = "uve-request-bounds", e.UVE_EDITOR_PONG = "uve-editor-pong", e.UVE_SCROLL_INSIDE_IFRAME = "uve-scroll-inside-iframe", e.UVE_SET_PAGE_DATA = "uve-set-page-data", e.UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS = "uve-copy-contentlet-inline-editing-success", e))(t || {});
2
- export {
3
- t as __DOTCMS_UVE_EVENT__
4
- };
@@ -1,3 +0,0 @@
1
- import { UVEEventType as n } from "../../../types/src/lib/editor/public.js";
2
- import { onContentletHovered as r, onIframeScroll as o, onRequestBounds as t, onPageReload as E, onContentChanges as u } from "./events.js";
3
- n.CONTENT_CHANGES + "", n.PAGE_RELOAD + "", n.REQUEST_BOUNDS + "", n.IFRAME_SCROLL + "", n.CONTENTLET_HOVERED + "";
@@ -1,107 +0,0 @@
1
- import { UVEEventType as a } from "../../../types/src/lib/editor/public.js";
2
- import { __DOTCMS_UVE_EVENT__ as s } from "../../../types/src/lib/events/internal.js";
3
- import { findDotCMSElement as M, findDotCMSVTLData as p, getClosestDotCMSContainerData as w, getDotCMSPageBounds as S } from "../lib/dom/dom.utils.js";
4
- function U(o) {
5
- const t = (n) => {
6
- n.data.name === s.UVE_SET_PAGE_DATA && o(n.data.payload);
7
- };
8
- return window.addEventListener("message", t), {
9
- unsubscribe: () => {
10
- window.removeEventListener("message", t);
11
- },
12
- event: a.CONTENT_CHANGES
13
- };
14
- }
15
- function V(o) {
16
- const t = (n) => {
17
- n.data.name === s.UVE_RELOAD_PAGE && o();
18
- };
19
- return window.addEventListener("message", t), {
20
- unsubscribe: () => {
21
- window.removeEventListener("message", t);
22
- },
23
- event: a.PAGE_RELOAD
24
- };
25
- }
26
- function I(o) {
27
- const t = (n) => {
28
- if (n.data.name === s.UVE_REQUEST_BOUNDS) {
29
- const e = Array.from(
30
- document.querySelectorAll('[data-dot-object="container"]')
31
- ), i = S(e);
32
- o(i);
33
- }
34
- };
35
- return window.addEventListener("message", t), {
36
- unsubscribe: () => {
37
- window.removeEventListener("message", t);
38
- },
39
- event: a.REQUEST_BOUNDS
40
- };
41
- }
42
- function Y(o) {
43
- const t = (n) => {
44
- if (n.data.name === s.UVE_SCROLL_INSIDE_IFRAME) {
45
- const e = n.data.direction;
46
- o(e);
47
- }
48
- };
49
- return window.addEventListener("message", t), {
50
- unsubscribe: () => {
51
- window.removeEventListener("message", t);
52
- },
53
- event: a.IFRAME_SCROLL
54
- };
55
- }
56
- function B(o) {
57
- const t = (n) => {
58
- var d, r, E, c, T, l, m, _, u, C;
59
- const e = M(n.target);
60
- if (!e) return;
61
- const { x: i, y: g, width: v, height: N } = e.getBoundingClientRect(), f = ((d = e.dataset) == null ? void 0 : d.dotObject) === "container", L = {
62
- identifier: "TEMP_EMPTY_CONTENTLET",
63
- title: "TEMP_EMPTY_CONTENTLET",
64
- contentType: "TEMP_EMPTY_CONTENTLET_TYPE",
65
- inode: "TEMPY_EMPTY_CONTENTLET_INODE",
66
- widgetTitle: "TEMP_EMPTY_CONTENTLET",
67
- baseType: "TEMP_EMPTY_CONTENTLET",
68
- onNumberOfPages: 1
69
- }, P = {
70
- identifier: (r = e.dataset) == null ? void 0 : r.dotIdentifier,
71
- title: (E = e.dataset) == null ? void 0 : E.dotTitle,
72
- inode: (c = e.dataset) == null ? void 0 : c.dotInode,
73
- contentType: (T = e.dataset) == null ? void 0 : T.dotType,
74
- baseType: (l = e.dataset) == null ? void 0 : l.dotBasetype,
75
- widgetTitle: (m = e.dataset) == null ? void 0 : m.dotWidgetTitle,
76
- onNumberOfPages: (_ = e.dataset) == null ? void 0 : _.dotOnNumberOfPages
77
- }, O = p(e), b = {
78
- container: (
79
- // Here extract dot-container from contentlet if it is Headless
80
- // or search in parent container if it is VTL
81
- (u = e.dataset) != null && u.dotContainer ? JSON.parse((C = e.dataset) == null ? void 0 : C.dotContainer) : w(e)
82
- ),
83
- contentlet: f ? L : P,
84
- vtlFiles: O
85
- };
86
- o({
87
- x: i,
88
- y: g,
89
- width: v,
90
- height: N,
91
- payload: b
92
- });
93
- };
94
- return document.addEventListener("pointermove", t), {
95
- unsubscribe: () => {
96
- document.removeEventListener("pointermove", t);
97
- },
98
- event: a.CONTENTLET_HOVERED
99
- };
100
- }
101
- export {
102
- U as onContentChanges,
103
- B as onContentletHovered,
104
- Y as onIframeScroll,
105
- V as onPageReload,
106
- I as onRequestBounds
107
- };
@@ -1,21 +0,0 @@
1
- import { UVE_MODE as t } from "../../../../types/src/lib/editor/public.js";
2
- import "../../internal/constants.js";
3
- function p() {
4
- if (typeof window > "u" || window.parent === window || !window.location)
5
- return;
6
- const e = new URL(window.location.href), o = Object.values(t);
7
- let a = e.searchParams.get("mode") ?? t.EDIT;
8
- const s = e.searchParams.get("language_id"), n = e.searchParams.get("personaId"), r = e.searchParams.get("variantName"), i = e.searchParams.get("experimentId"), c = e.searchParams.get("publishDate"), d = e.searchParams.get("dotCMSHost");
9
- return o.includes(a) || (a = t.EDIT), {
10
- mode: a,
11
- languageId: s,
12
- persona: n,
13
- variantName: r,
14
- experimentId: i,
15
- publishDate: c,
16
- dotCMSHost: d
17
- };
18
- }
19
- export {
20
- p as getUVEState
21
- };
@@ -1,80 +0,0 @@
1
- import "../../internal/constants.js";
2
- function C(t) {
3
- return t.map((a) => {
4
- const o = a.getBoundingClientRect(), n = Array.from(
5
- a.querySelectorAll('[data-dot-object="contentlet"]')
6
- );
7
- return {
8
- x: o.x,
9
- y: o.y,
10
- width: o.width,
11
- height: o.height,
12
- payload: JSON.stringify({
13
- container: u(a)
14
- }),
15
- contentlets: f(o, n)
16
- };
17
- });
18
- }
19
- function f(t, a) {
20
- return a.map((o) => {
21
- var d, r, i, e, s, c;
22
- const n = o.getBoundingClientRect();
23
- return {
24
- x: 0,
25
- y: n.y - t.y,
26
- width: n.width,
27
- height: n.height,
28
- payload: JSON.stringify({
29
- container: (d = o.dataset) != null && d.dotContainer ? JSON.parse((r = o.dataset) == null ? void 0 : r.dotContainer) : y(o),
30
- contentlet: {
31
- identifier: (i = o.dataset) == null ? void 0 : i.dotIdentifier,
32
- title: (e = o.dataset) == null ? void 0 : e.dotTitle,
33
- inode: (s = o.dataset) == null ? void 0 : s.dotInode,
34
- contentType: (c = o.dataset) == null ? void 0 : c.dotType
35
- }
36
- })
37
- };
38
- });
39
- }
40
- function u(t) {
41
- var a, o, n, d;
42
- return {
43
- acceptTypes: ((a = t.dataset) == null ? void 0 : a.dotAcceptTypes) || "",
44
- identifier: ((o = t.dataset) == null ? void 0 : o.dotIdentifier) || "",
45
- maxContentlets: ((n = t.dataset) == null ? void 0 : n.maxContentlets) || "",
46
- uuid: ((d = t.dataset) == null ? void 0 : d.dotUuid) || ""
47
- };
48
- }
49
- function y(t) {
50
- const a = t.closest('[data-dot-object="container"]');
51
- return a ? u(a) : (console.warn("No container found for the contentlet"), null);
52
- }
53
- function g(t) {
54
- var o, n, d;
55
- if (!t) return null;
56
- const a = t.querySelector('[data-dot-object="empty-content"]');
57
- return ((o = t == null ? void 0 : t.dataset) == null ? void 0 : o.dotObject) === "contentlet" || // The container inside Headless components have a span with the data-dot-object="container" attribute
58
- ((n = t == null ? void 0 : t.dataset) == null ? void 0 : n.dotObject) === "container" && a || // The container inside Traditional have no content inside
59
- ((d = t == null ? void 0 : t.dataset) == null ? void 0 : d.dotObject) === "container" && t.children.length === 0 ? t : g(t == null ? void 0 : t.parentElement);
60
- }
61
- function h(t) {
62
- const a = t.querySelectorAll(
63
- '[data-dot-object="vtl-file"]'
64
- );
65
- return a.length ? Array.from(a).map((o) => {
66
- var n, d;
67
- return {
68
- inode: (n = o.dataset) == null ? void 0 : n.dotInode,
69
- name: (d = o.dataset) == null ? void 0 : d.dotUrl
70
- };
71
- }) : null;
72
- }
73
- export {
74
- g as findDotCMSElement,
75
- h as findDotCMSVTLData,
76
- y as getClosestDotCMSContainerData,
77
- u as getDotCMSContainerData,
78
- f as getDotCMSContentletsBound,
79
- C as getDotCMSPageBounds
80
- };