@dotcms/analytics 1.1.1 → 1.2.0-next.10
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 +475 -72
- package/lib/core/{dot-content-analytics.d.ts → dot-analytics.content.d.ts} +8 -1
- package/lib/core/dot-analytics.content.js +63 -0
- package/lib/core/plugin/click/dot-analytics.click-tracker.d.ts +108 -0
- package/lib/core/plugin/click/dot-analytics.click-tracker.js +144 -0
- package/lib/core/plugin/click/dot-analytics.click.plugin.d.ts +36 -0
- package/lib/core/plugin/click/dot-analytics.click.plugin.js +27 -0
- package/lib/core/plugin/click/dot-analytics.click.utils.d.ts +12 -0
- package/lib/core/plugin/click/dot-analytics.click.utils.js +55 -0
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +18 -30
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +30 -20
- package/lib/core/plugin/identity/dot-analytics.identity.activity-tracker.d.ts +20 -0
- package/lib/core/{shared/dot-content-analytics.activity-tracker.js → plugin/identity/dot-analytics.identity.activity-tracker.js} +19 -38
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +13 -31
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +14 -12
- package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -22
- package/lib/core/plugin/impression/dot-analytics.impression-tracker.d.ts +62 -0
- package/lib/core/plugin/impression/dot-analytics.impression-tracker.js +200 -0
- package/lib/core/plugin/impression/dot-analytics.impression.plugin.d.ts +40 -0
- package/lib/core/plugin/impression/dot-analytics.impression.plugin.js +27 -0
- package/lib/core/plugin/impression/dot-analytics.impression.utils.d.ts +26 -0
- package/lib/core/plugin/impression/dot-analytics.impression.utils.js +27 -0
- package/lib/core/plugin/impression/index.d.ts +2 -0
- package/lib/core/plugin/main/dot-analytics.plugin.d.ts +46 -0
- package/lib/core/plugin/main/dot-analytics.plugin.js +114 -0
- package/lib/core/shared/constants/dot-analytics.constants.d.ts +131 -0
- package/lib/core/shared/constants/dot-analytics.constants.js +52 -0
- package/lib/core/shared/constants/index.d.ts +4 -0
- package/lib/core/shared/dot-analytics.logger.d.ts +85 -0
- package/lib/core/shared/dot-analytics.logger.js +90 -0
- package/lib/core/shared/http/dot-analytics.http.d.ts +9 -0
- package/lib/core/shared/http/dot-analytics.http.js +34 -0
- package/lib/core/shared/models/data.model.d.ts +141 -0
- package/lib/core/shared/models/event.model.d.ts +135 -0
- package/lib/core/shared/models/index.d.ts +7 -0
- package/lib/core/shared/models/library.model.d.ts +243 -0
- package/lib/core/shared/models/request.model.d.ts +32 -0
- package/lib/core/shared/queue/dot-analytics.queue.utils.d.ts +28 -0
- package/lib/core/shared/queue/dot-analytics.queue.utils.js +80 -0
- package/lib/core/shared/queue/index.d.ts +1 -0
- package/lib/core/shared/utils/dot-analytics.utils.d.ts +260 -0
- package/lib/core/shared/utils/dot-analytics.utils.js +202 -0
- package/lib/react/components/DotContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useContentAnalytics.d.ts +43 -15
- package/lib/react/hook/useContentAnalytics.js +18 -21
- package/lib/react/hook/useRouterTracker.d.ts +1 -1
- package/lib/react/hook/useRouterTracker.js +4 -4
- package/lib/react/internal/utils.d.ts +1 -1
- package/lib/react/internal/utils.js +3 -3
- package/lib/react/public-api.d.ts +1 -1
- package/lib/standalone.d.ts +2 -2
- package/package.json +7 -5
- package/uve/src/internal/constants.js +8 -3
- package/lib/core/dot-content-analytics.js +0 -43
- package/lib/core/plugin/dot-analytics.plugin.d.ts +0 -32
- package/lib/core/plugin/dot-analytics.plugin.js +0 -79
- package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +0 -28
- package/lib/core/shared/dot-content-analytics.constants.d.ts +0 -37
- package/lib/core/shared/dot-content-analytics.constants.js +0 -14
- package/lib/core/shared/dot-content-analytics.http.d.ts +0 -8
- package/lib/core/shared/dot-content-analytics.http.js +0 -29
- package/lib/core/shared/dot-content-analytics.model.d.ts +0 -351
- package/lib/core/shared/dot-content-analytics.utils.d.ts +0 -111
- package/lib/core/shared/dot-content-analytics.utils.js +0 -123
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { PageData } from 'analytics';
|
|
2
|
-
import { DotCMSAnalyticsConfig, DotCMSAnalyticsContext, DotCMSAnalyticsPayload, DotCMSBrowserEventData, DotCMSDeviceData, DotCMSPageData, DotCMSUtmData } from './dot-content-analytics.model';
|
|
3
|
-
export { cleanupActivityTracking, getLastActivity, getSessionInfo, initializeActivityTracking, isUserInactive, updateSessionActivity } from './dot-content-analytics.activity-tracker';
|
|
4
|
-
/**
|
|
5
|
-
* Generates a cryptographically secure random ID
|
|
6
|
-
*/
|
|
7
|
-
export declare const generateSecureId: (prefix: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
* Safe sessionStorage wrapper with error handling
|
|
10
|
-
*/
|
|
11
|
-
export declare const safeSessionStorage: {
|
|
12
|
-
getItem: (key: string) => string | null;
|
|
13
|
-
setItem: (key: string, value: string) => void;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Gets or generates a user ID
|
|
17
|
-
*/
|
|
18
|
-
export declare const getUserId: () => string;
|
|
19
|
-
/**
|
|
20
|
-
* Gets session ID with comprehensive lifecycle management
|
|
21
|
-
* Returns existing valid session ID or creates a new one if needed
|
|
22
|
-
*
|
|
23
|
-
* Session validation criteria:
|
|
24
|
-
* 1. User is still active (< 30 min inactivity)
|
|
25
|
-
* 2. Session hasn't passed midnight (UTC)
|
|
26
|
-
* 3. UTM parameters haven't changed
|
|
27
|
-
*/
|
|
28
|
-
export declare const getSessionId: () => string;
|
|
29
|
-
/**
|
|
30
|
-
* Gets analytics context with user and session identification
|
|
31
|
-
*/
|
|
32
|
-
export declare const getAnalyticsContext: (config: DotCMSAnalyticsConfig) => DotCMSAnalyticsContext;
|
|
33
|
-
/**
|
|
34
|
-
* Configuration result with warnings for analytics setup
|
|
35
|
-
*/
|
|
36
|
-
export interface AnalyticsConfigResult {
|
|
37
|
-
config: DotCMSAnalyticsConfig;
|
|
38
|
-
warnings?: string[];
|
|
39
|
-
missingAttributes?: string[];
|
|
40
|
-
hasIssues: boolean;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Gets analytics configuration, always returns a config (with defaults if needed)
|
|
44
|
-
* - If no data-analytics-server attribute is found, uses the current domain as the server endpoint
|
|
45
|
-
* - Both debug and autoPageView default to false (must be explicitly set to "true")
|
|
46
|
-
*/
|
|
47
|
-
export declare const getAnalyticsConfig: () => DotCMSAnalyticsConfig;
|
|
48
|
-
/**
|
|
49
|
-
* Retrieves the browser event data - optimized but accurate.
|
|
50
|
-
*/
|
|
51
|
-
export declare const getBrowserEventData: (location: Location) => DotCMSBrowserEventData;
|
|
52
|
-
/**
|
|
53
|
-
* Extracts UTM parameters from the URL - cached for performance
|
|
54
|
-
*/
|
|
55
|
-
export declare const extractUTMParameters: (location: Location) => Record<string, string>;
|
|
56
|
-
/**
|
|
57
|
-
* Default redirect function
|
|
58
|
-
*/
|
|
59
|
-
export declare const defaultRedirectFn: (href: string) => string;
|
|
60
|
-
/**
|
|
61
|
-
* Gets local time in ISO format without milliseconds
|
|
62
|
-
*/
|
|
63
|
-
export declare const getLocalTime: () => string;
|
|
64
|
-
/**
|
|
65
|
-
* Gets page data from browser event data and payload
|
|
66
|
-
*/
|
|
67
|
-
export declare const getPageData: (browserData: DotCMSBrowserEventData, payload: DotCMSAnalyticsPayload) => PageData;
|
|
68
|
-
/**
|
|
69
|
-
* Gets device data from browser event data
|
|
70
|
-
*/
|
|
71
|
-
export declare const getDeviceData: (browserData: DotCMSBrowserEventData) => DotCMSDeviceData;
|
|
72
|
-
/**
|
|
73
|
-
* Gets UTM data from browser event data
|
|
74
|
-
*/
|
|
75
|
-
export declare const getUtmData: (browserData: DotCMSBrowserEventData) => DotCMSUtmData;
|
|
76
|
-
/**
|
|
77
|
-
* Enriches payload with UTM data
|
|
78
|
-
*/
|
|
79
|
-
export declare const enrichWithUtmData: (payload: DotCMSAnalyticsPayload) => DotCMSAnalyticsPayload;
|
|
80
|
-
/**
|
|
81
|
-
* Optimized payload enrichment using existing analytics.js data
|
|
82
|
-
* Reuses payload.properties data instead of recalculating from DOM when available
|
|
83
|
-
* Maintains the same output structure as the original function
|
|
84
|
-
*/
|
|
85
|
-
export declare const enrichPagePayloadOptimized: (payload: DotCMSAnalyticsPayload, location?: Location) => {
|
|
86
|
-
local_time: string;
|
|
87
|
-
utm?: DotCMSUtmData;
|
|
88
|
-
page: DotCMSPageData;
|
|
89
|
-
device: DotCMSDeviceData;
|
|
90
|
-
event: string;
|
|
91
|
-
properties: Record<string, unknown>;
|
|
92
|
-
options: Record<string, unknown>;
|
|
93
|
-
context?: DotCMSAnalyticsContext;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Use enrichPagePayloadOptimized instead to avoid data duplication
|
|
97
|
-
* Legacy function that enriches page payload with all data in one call
|
|
98
|
-
* This function duplicates data already available in analytics.js payload
|
|
99
|
-
*/
|
|
100
|
-
export declare const enrichPagePayload: (payload: DotCMSAnalyticsPayload, location?: Location) => {
|
|
101
|
-
payload: {
|
|
102
|
-
local_time: string;
|
|
103
|
-
utm?: DotCMSUtmData;
|
|
104
|
-
page: PageData;
|
|
105
|
-
device: DotCMSDeviceData;
|
|
106
|
-
event: string;
|
|
107
|
-
properties: Record<string, unknown>;
|
|
108
|
-
options: Record<string, unknown>;
|
|
109
|
-
context?: DotCMSAnalyticsContext;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { SESSION_STORAGE_KEY as h, DEFAULT_SESSION_TIMEOUT_MINUTES as S, USER_ID_KEY as m } from "./dot-content-analytics.constants.js";
|
|
2
|
-
let d = null;
|
|
3
|
-
const u = (t) => {
|
|
4
|
-
const e = Date.now(), n = Math.random().toString(36).substr(2, 9), o = Math.random().toString(36).substr(2, 9);
|
|
5
|
-
return `${t}_${e}_${n}${o}`;
|
|
6
|
-
}, l = {
|
|
7
|
-
getItem: (t) => {
|
|
8
|
-
try {
|
|
9
|
-
return localStorage.getItem(t);
|
|
10
|
-
} catch {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
setItem: (t, e) => {
|
|
15
|
-
try {
|
|
16
|
-
localStorage.setItem(t, e);
|
|
17
|
-
} catch {
|
|
18
|
-
console.warn(`DotAnalytics: Could not save ${t} to localStorage`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}, f = () => {
|
|
22
|
-
let t = l.getItem(m);
|
|
23
|
-
return t || (t = u("user"), l.setItem(m, t)), t;
|
|
24
|
-
}, _ = (t) => {
|
|
25
|
-
const e = new Date(t), n = /* @__PURE__ */ new Date(), o = new Date(
|
|
26
|
-
e.getUTCFullYear(),
|
|
27
|
-
e.getUTCMonth(),
|
|
28
|
-
e.getUTCDate()
|
|
29
|
-
), s = new Date(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate());
|
|
30
|
-
return o.getTime() !== s.getTime();
|
|
31
|
-
}, p = () => {
|
|
32
|
-
const t = Date.now();
|
|
33
|
-
if (typeof window > "u")
|
|
34
|
-
return u("session_fallback");
|
|
35
|
-
try {
|
|
36
|
-
const e = sessionStorage.getItem(h);
|
|
37
|
-
if (e) {
|
|
38
|
-
const { sessionId: s, startTime: c, lastActivity: i } = JSON.parse(e), g = !_(c), a = t - i < S * 60 * 1e3;
|
|
39
|
-
if (g && a)
|
|
40
|
-
return sessionStorage.setItem(
|
|
41
|
-
h,
|
|
42
|
-
JSON.stringify({
|
|
43
|
-
sessionId: s,
|
|
44
|
-
startTime: c,
|
|
45
|
-
lastActivity: t
|
|
46
|
-
})
|
|
47
|
-
), s;
|
|
48
|
-
}
|
|
49
|
-
const n = u("session"), o = {
|
|
50
|
-
sessionId: n,
|
|
51
|
-
startTime: t,
|
|
52
|
-
lastActivity: t
|
|
53
|
-
};
|
|
54
|
-
return sessionStorage.setItem(h, JSON.stringify(o)), n;
|
|
55
|
-
} catch {
|
|
56
|
-
return u("session_fallback");
|
|
57
|
-
}
|
|
58
|
-
}, T = (t) => {
|
|
59
|
-
const e = p(), n = f();
|
|
60
|
-
return t.debug && console.warn("DotAnalytics Identity Context:", {
|
|
61
|
-
sessionId: e,
|
|
62
|
-
userId: n
|
|
63
|
-
}), {
|
|
64
|
-
site_key: t.siteKey,
|
|
65
|
-
session_id: e,
|
|
66
|
-
user_id: n
|
|
67
|
-
};
|
|
68
|
-
}, w = () => d || (d = {
|
|
69
|
-
user_language: navigator.language || void 0,
|
|
70
|
-
doc_encoding: document.characterSet || document.charset || void 0,
|
|
71
|
-
screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : void 0
|
|
72
|
-
}, d), I = () => {
|
|
73
|
-
try {
|
|
74
|
-
const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", n = Math.abs(t), o = Math.floor(n / 60), s = n % 60;
|
|
75
|
-
return `${e}${o.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
|
|
76
|
-
} catch {
|
|
77
|
-
return "+00:00";
|
|
78
|
-
}
|
|
79
|
-
}, D = () => {
|
|
80
|
-
try {
|
|
81
|
-
const t = /* @__PURE__ */ new Date(), e = I(), n = t.getFullYear(), o = (t.getMonth() + 1).toString().padStart(2, "0"), s = t.getDate().toString().padStart(2, "0"), c = t.getHours().toString().padStart(2, "0"), i = t.getMinutes().toString().padStart(2, "0"), g = t.getSeconds().toString().padStart(2, "0");
|
|
82
|
-
return `${n}-${o}-${s}T${c}:${i}:${g}${e}`;
|
|
83
|
-
} catch {
|
|
84
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
85
|
-
}
|
|
86
|
-
}, $ = (t, e = typeof window < "u" ? window.location : {}) => {
|
|
87
|
-
const n = D(), o = w(), { properties: s } = t, { utm: c } = s, i = {
|
|
88
|
-
url: s.url ?? e.href,
|
|
89
|
-
doc_encoding: o.doc_encoding,
|
|
90
|
-
doc_hash: s.hash ?? e.hash ?? "",
|
|
91
|
-
doc_protocol: e.protocol,
|
|
92
|
-
doc_search: s.search ?? e.search ?? "",
|
|
93
|
-
doc_host: e.hostname,
|
|
94
|
-
doc_path: s.path ?? e.pathname,
|
|
95
|
-
title: s.title ?? (document == null ? void 0 : document.title),
|
|
96
|
-
language_id: void 0,
|
|
97
|
-
persona: void 0
|
|
98
|
-
}, g = {
|
|
99
|
-
screen_resolution: o.screen_resolution,
|
|
100
|
-
language: o.user_language,
|
|
101
|
-
viewport_width: String(s.width),
|
|
102
|
-
viewport_height: String(s.height)
|
|
103
|
-
}, a = {};
|
|
104
|
-
if (c && typeof c == "object") {
|
|
105
|
-
const r = c;
|
|
106
|
-
r.medium && (a.medium = r.medium), r.source && (a.source = r.source), r.campaign && (a.campaign = r.campaign), r.term && (a.term = r.term), r.content && (a.content = r.content);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
...t,
|
|
110
|
-
page: i,
|
|
111
|
-
device: g,
|
|
112
|
-
...Object.keys(a).length > 0 && { utm: a },
|
|
113
|
-
local_time: n
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
export {
|
|
117
|
-
$ as enrichPagePayloadOptimized,
|
|
118
|
-
u as generateSecureId,
|
|
119
|
-
T as getAnalyticsContext,
|
|
120
|
-
D as getLocalTime,
|
|
121
|
-
p as getSessionId,
|
|
122
|
-
f as getUserId
|
|
123
|
-
};
|