@amplifyup/sdk 0.1.74 → 0.1.76
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/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +197 -100
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +197 -100
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +22 -5
- package/dist/index.d.ts +22 -5
- package/dist/index.js +199 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -122
- package/dist/index.mjs.map +1 -1
- package/dist/{query-NcrxJQvI.d.ts → query-B23UsNIv.d.ts} +1 -1
- package/dist/{query-_SMo6VRf.d.mts → query-CV8x3oQT.d.mts} +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +204 -123
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +204 -123
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +2 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-BGZYaFxP.d.mts → types-D4TSd2Yt.d.mts} +8 -2
- package/dist/{types-BGZYaFxP.d.ts → types-D4TSd2Yt.d.ts} +8 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, R as ResolvedPageResourceRef, b as
|
|
2
|
-
export { Z as ZoneConfig,
|
|
1
|
+
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, R as ResolvedPageResourceRef, b as PageTaxonomies, c as CDPAdapter, d as AmplifyUpConfig, e as EventProperties, f as AmplifyPageContextInput, g as AttachedPageEventContext, I as IdentifyInput, h as IdentifyTraits, i as ProfileFieldsInput, j as AmplifyUpTarget } from './types-D4TSd2Yt.mjs';
|
|
2
|
+
export { Z as ZoneConfig, l as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, k as resolveAmplifyUpUrls } from './types-D4TSd2Yt.mjs';
|
|
3
3
|
export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
|
|
4
4
|
export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.mjs';
|
|
5
|
-
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-
|
|
5
|
+
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-CV8x3oQT.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Storage utilities for instance ID and user ID
|
|
@@ -73,6 +73,8 @@ interface EdgeResolvedPayload {
|
|
|
73
73
|
pageData?: PageDataSnapshot;
|
|
74
74
|
/** resource name → document this URL resolved to. */
|
|
75
75
|
pageResources?: Record<string, ResolvedPageResourceRef>;
|
|
76
|
+
/** taxonomy key → term ids this page is tagged with. */
|
|
77
|
+
pageTaxonomies?: PageTaxonomies;
|
|
76
78
|
meta: {
|
|
77
79
|
variantKeys: Record<string, string>;
|
|
78
80
|
audienceLookup?: {
|
|
@@ -205,6 +207,12 @@ declare class AmplifyUpSDK {
|
|
|
205
207
|
private resolvedPageResource;
|
|
206
208
|
private resolvedPageRoute;
|
|
207
209
|
private resolvedRouteParams;
|
|
210
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
211
|
+
private pendingResolvePath;
|
|
212
|
+
private heldPageView;
|
|
213
|
+
private resolvedPageTaxonomies;
|
|
214
|
+
/** Path the taxonomies above were resolved for. */
|
|
215
|
+
private resolvedTaxonomiesPath;
|
|
208
216
|
private historyHooksInstalled;
|
|
209
217
|
private pageEngagementState;
|
|
210
218
|
constructor(adapter?: CDPAdapter);
|
|
@@ -274,15 +282,24 @@ declare class AmplifyUpSDK {
|
|
|
274
282
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
275
283
|
* mapped page fields can run.
|
|
276
284
|
*/
|
|
277
|
-
applyResolvedPageData(pageData: PageDataSnapshot | null | undefined, pageRoute?: string, routeParams?: Record<string, string>, pageResources?: Record<string, ResolvedPageResourceRef> | null): void;
|
|
285
|
+
applyResolvedPageData(pageData: PageDataSnapshot | null | undefined, pageRoute?: string, routeParams?: Record<string, string>, pageResources?: Record<string, ResolvedPageResourceRef> | null, pageTaxonomies?: PageTaxonomies | null): void;
|
|
278
286
|
private recomputeAttachedContext;
|
|
279
287
|
/** Stamp the resolved entry onto the context so events carry it. */
|
|
280
288
|
private withPageResource;
|
|
281
289
|
getAttachedPageContext(): AttachedPageEventContext | null;
|
|
290
|
+
/**
|
|
291
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
292
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
293
|
+
* taxonomies.
|
|
294
|
+
*/
|
|
295
|
+
beginPageResolve(path: string): void;
|
|
296
|
+
endPageResolve(path: string): void;
|
|
297
|
+
private flushHeldPageView;
|
|
282
298
|
/**
|
|
283
299
|
* Track a page view
|
|
284
300
|
*/
|
|
285
301
|
page(url: string, properties?: EventProperties): void;
|
|
302
|
+
private sendPageView;
|
|
286
303
|
/**
|
|
287
304
|
* Track an event
|
|
288
305
|
*/
|
|
@@ -576,4 +593,4 @@ declare const verifyAWSConnection: () => {
|
|
|
576
593
|
|
|
577
594
|
declare const _default: AmplifyUpSDK;
|
|
578
595
|
|
|
579
|
-
export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
596
|
+
export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, R as ResolvedPageResourceRef, b as
|
|
2
|
-
export { Z as ZoneConfig,
|
|
1
|
+
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as PageDataSnapshot, R as ResolvedPageResourceRef, b as PageTaxonomies, c as CDPAdapter, d as AmplifyUpConfig, e as EventProperties, f as AmplifyPageContextInput, g as AttachedPageEventContext, I as IdentifyInput, h as IdentifyTraits, i as ProfileFieldsInput, j as AmplifyUpTarget } from './types-D4TSd2Yt.js';
|
|
2
|
+
export { Z as ZoneConfig, l as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, k as resolveAmplifyUpUrls } from './types-D4TSd2Yt.js';
|
|
3
3
|
export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
|
|
4
4
|
export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.js';
|
|
5
|
-
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-
|
|
5
|
+
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-B23UsNIv.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Storage utilities for instance ID and user ID
|
|
@@ -73,6 +73,8 @@ interface EdgeResolvedPayload {
|
|
|
73
73
|
pageData?: PageDataSnapshot;
|
|
74
74
|
/** resource name → document this URL resolved to. */
|
|
75
75
|
pageResources?: Record<string, ResolvedPageResourceRef>;
|
|
76
|
+
/** taxonomy key → term ids this page is tagged with. */
|
|
77
|
+
pageTaxonomies?: PageTaxonomies;
|
|
76
78
|
meta: {
|
|
77
79
|
variantKeys: Record<string, string>;
|
|
78
80
|
audienceLookup?: {
|
|
@@ -205,6 +207,12 @@ declare class AmplifyUpSDK {
|
|
|
205
207
|
private resolvedPageResource;
|
|
206
208
|
private resolvedPageRoute;
|
|
207
209
|
private resolvedRouteParams;
|
|
210
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
211
|
+
private pendingResolvePath;
|
|
212
|
+
private heldPageView;
|
|
213
|
+
private resolvedPageTaxonomies;
|
|
214
|
+
/** Path the taxonomies above were resolved for. */
|
|
215
|
+
private resolvedTaxonomiesPath;
|
|
208
216
|
private historyHooksInstalled;
|
|
209
217
|
private pageEngagementState;
|
|
210
218
|
constructor(adapter?: CDPAdapter);
|
|
@@ -274,15 +282,24 @@ declare class AmplifyUpSDK {
|
|
|
274
282
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
275
283
|
* mapped page fields can run.
|
|
276
284
|
*/
|
|
277
|
-
applyResolvedPageData(pageData: PageDataSnapshot | null | undefined, pageRoute?: string, routeParams?: Record<string, string>, pageResources?: Record<string, ResolvedPageResourceRef> | null): void;
|
|
285
|
+
applyResolvedPageData(pageData: PageDataSnapshot | null | undefined, pageRoute?: string, routeParams?: Record<string, string>, pageResources?: Record<string, ResolvedPageResourceRef> | null, pageTaxonomies?: PageTaxonomies | null): void;
|
|
278
286
|
private recomputeAttachedContext;
|
|
279
287
|
/** Stamp the resolved entry onto the context so events carry it. */
|
|
280
288
|
private withPageResource;
|
|
281
289
|
getAttachedPageContext(): AttachedPageEventContext | null;
|
|
290
|
+
/**
|
|
291
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
292
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
293
|
+
* taxonomies.
|
|
294
|
+
*/
|
|
295
|
+
beginPageResolve(path: string): void;
|
|
296
|
+
endPageResolve(path: string): void;
|
|
297
|
+
private flushHeldPageView;
|
|
282
298
|
/**
|
|
283
299
|
* Track a page view
|
|
284
300
|
*/
|
|
285
301
|
page(url: string, properties?: EventProperties): void;
|
|
302
|
+
private sendPageView;
|
|
286
303
|
/**
|
|
287
304
|
* Track an event
|
|
288
305
|
*/
|
|
@@ -576,4 +593,4 @@ declare const verifyAWSConnection: () => {
|
|
|
576
593
|
|
|
577
594
|
declare const _default: AmplifyUpSDK;
|
|
578
595
|
|
|
579
|
-
export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
596
|
+
export { ANON_COOKIE_NAME, AmplifyContentMeta, AmplifyPageContextInput, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, PageDataSnapshot, PageTaxonomies, ProfileFieldsInput, SESSION_COOKIE_NAME, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getSessionId, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,121 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
/* @amplifyup/sdk - https://amplifyup.ai */
|
|
6
6
|
|
|
7
|
+
// src/storage.ts
|
|
8
|
+
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
9
|
+
var USER_ID_KEY = "amplifyup_user_id";
|
|
10
|
+
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
11
|
+
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
12
|
+
var VISITOR_FIRST_SEEN_KEY = "amplifyup_visitor_first_seen";
|
|
13
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
14
|
+
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
15
|
+
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
16
|
+
function generateGuid() {
|
|
17
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
18
|
+
return crypto.randomUUID();
|
|
19
|
+
}
|
|
20
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
21
|
+
const r = Math.random() * 16 | 0;
|
|
22
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
23
|
+
return v.toString(16);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function readCookie(name) {
|
|
27
|
+
if (typeof document === "undefined") return null;
|
|
28
|
+
const parts = document.cookie.split(";");
|
|
29
|
+
for (const part of parts) {
|
|
30
|
+
const idx = part.indexOf("=");
|
|
31
|
+
if (idx === -1) continue;
|
|
32
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
33
|
+
const value = part.slice(idx + 1).trim();
|
|
34
|
+
try {
|
|
35
|
+
return value ? decodeURIComponent(value) : null;
|
|
36
|
+
} catch {
|
|
37
|
+
return value || null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
43
|
+
if (typeof document === "undefined") return;
|
|
44
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
45
|
+
}
|
|
46
|
+
function getInstanceId() {
|
|
47
|
+
if (typeof window === "undefined") {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
51
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
52
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
53
|
+
if (fromLs !== instanceId) {
|
|
54
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
55
|
+
}
|
|
56
|
+
if (fromCookie !== instanceId) {
|
|
57
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
58
|
+
}
|
|
59
|
+
return instanceId;
|
|
60
|
+
}
|
|
61
|
+
function getUserId() {
|
|
62
|
+
if (typeof window === "undefined") {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return localStorage.getItem(USER_ID_KEY);
|
|
66
|
+
}
|
|
67
|
+
function getSessionId() {
|
|
68
|
+
if (typeof window === "undefined") {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
73
|
+
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
74
|
+
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
75
|
+
let sessionId = fromLs || fromCookie || "";
|
|
76
|
+
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
77
|
+
sessionId = generateGuid();
|
|
78
|
+
}
|
|
79
|
+
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
80
|
+
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
81
|
+
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
82
|
+
return sessionId;
|
|
83
|
+
}
|
|
84
|
+
function getVisitorFirstSeenAt() {
|
|
85
|
+
if (typeof window === "undefined") {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const existing = localStorage.getItem(VISITOR_FIRST_SEEN_KEY);
|
|
90
|
+
if (existing) return existing;
|
|
91
|
+
const firstSeenAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
92
|
+
localStorage.setItem(VISITOR_FIRST_SEEN_KEY, firstSeenAt);
|
|
93
|
+
return firstSeenAt;
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function setUserId(userId) {
|
|
99
|
+
if (typeof window === "undefined") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
localStorage.setItem(USER_ID_KEY, userId);
|
|
103
|
+
}
|
|
104
|
+
function clearIds() {
|
|
105
|
+
if (typeof window === "undefined") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
109
|
+
localStorage.removeItem(USER_ID_KEY);
|
|
110
|
+
localStorage.removeItem(SESSION_ID_KEY);
|
|
111
|
+
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
112
|
+
localStorage.removeItem(VISITOR_FIRST_SEEN_KEY);
|
|
113
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
114
|
+
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
115
|
+
}
|
|
116
|
+
|
|
7
117
|
// src/adapters/aws.ts
|
|
118
|
+
function visitorContext() {
|
|
119
|
+
const firstSeenAt = getVisitorFirstSeenAt();
|
|
120
|
+
return firstSeenAt ? { firstSeenAt } : void 0;
|
|
121
|
+
}
|
|
8
122
|
var AWSAdapter = class {
|
|
9
123
|
constructor() {
|
|
10
124
|
this.initialized = false;
|
|
@@ -44,7 +158,9 @@ var AWSAdapter = class {
|
|
|
44
158
|
console.warn("AmplifyUp SDK: AWS configuration missing");
|
|
45
159
|
return;
|
|
46
160
|
}
|
|
47
|
-
const
|
|
161
|
+
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
162
|
+
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
163
|
+
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
48
164
|
try {
|
|
49
165
|
const response = await fetch(url, {
|
|
50
166
|
method: "POST",
|
|
@@ -106,7 +222,8 @@ var AWSAdapter = class {
|
|
|
106
222
|
page: {
|
|
107
223
|
path: properties.path || properties.url,
|
|
108
224
|
referrer: properties.referrer
|
|
109
|
-
}
|
|
225
|
+
},
|
|
226
|
+
visitor: visitorContext()
|
|
110
227
|
},
|
|
111
228
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
112
229
|
};
|
|
@@ -144,7 +261,8 @@ var AWSAdapter = class {
|
|
|
144
261
|
...properties
|
|
145
262
|
},
|
|
146
263
|
context: {
|
|
147
|
-
url: properties.url || (typeof window !== "undefined" ? window.location.href : "")
|
|
264
|
+
url: properties.url || (typeof window !== "undefined" ? window.location.href : ""),
|
|
265
|
+
visitor: visitorContext()
|
|
148
266
|
},
|
|
149
267
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
150
268
|
};
|
|
@@ -200,100 +318,6 @@ var AWSAdapter = class {
|
|
|
200
318
|
}
|
|
201
319
|
};
|
|
202
320
|
|
|
203
|
-
// src/storage.ts
|
|
204
|
-
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
205
|
-
var USER_ID_KEY = "amplifyup_user_id";
|
|
206
|
-
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
207
|
-
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
208
|
-
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
209
|
-
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
210
|
-
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
211
|
-
function generateGuid() {
|
|
212
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
213
|
-
return crypto.randomUUID();
|
|
214
|
-
}
|
|
215
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
216
|
-
const r = Math.random() * 16 | 0;
|
|
217
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
218
|
-
return v.toString(16);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
function readCookie(name) {
|
|
222
|
-
if (typeof document === "undefined") return null;
|
|
223
|
-
const parts = document.cookie.split(";");
|
|
224
|
-
for (const part of parts) {
|
|
225
|
-
const idx = part.indexOf("=");
|
|
226
|
-
if (idx === -1) continue;
|
|
227
|
-
if (part.slice(0, idx).trim() !== name) continue;
|
|
228
|
-
const value = part.slice(idx + 1).trim();
|
|
229
|
-
try {
|
|
230
|
-
return value ? decodeURIComponent(value) : null;
|
|
231
|
-
} catch {
|
|
232
|
-
return value || null;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
238
|
-
if (typeof document === "undefined") return;
|
|
239
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
240
|
-
}
|
|
241
|
-
function getInstanceId() {
|
|
242
|
-
if (typeof window === "undefined") {
|
|
243
|
-
return "";
|
|
244
|
-
}
|
|
245
|
-
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
246
|
-
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
247
|
-
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
248
|
-
if (fromLs !== instanceId) {
|
|
249
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
250
|
-
}
|
|
251
|
-
if (fromCookie !== instanceId) {
|
|
252
|
-
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
253
|
-
}
|
|
254
|
-
return instanceId;
|
|
255
|
-
}
|
|
256
|
-
function getUserId() {
|
|
257
|
-
if (typeof window === "undefined") {
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
return localStorage.getItem(USER_ID_KEY);
|
|
261
|
-
}
|
|
262
|
-
function getSessionId() {
|
|
263
|
-
if (typeof window === "undefined") {
|
|
264
|
-
return "";
|
|
265
|
-
}
|
|
266
|
-
const now = Date.now();
|
|
267
|
-
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
268
|
-
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
269
|
-
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
270
|
-
let sessionId = fromLs || fromCookie || "";
|
|
271
|
-
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
272
|
-
sessionId = generateGuid();
|
|
273
|
-
}
|
|
274
|
-
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
275
|
-
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
276
|
-
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
277
|
-
return sessionId;
|
|
278
|
-
}
|
|
279
|
-
function setUserId(userId) {
|
|
280
|
-
if (typeof window === "undefined") {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
localStorage.setItem(USER_ID_KEY, userId);
|
|
284
|
-
}
|
|
285
|
-
function clearIds() {
|
|
286
|
-
if (typeof window === "undefined") {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
290
|
-
localStorage.removeItem(USER_ID_KEY);
|
|
291
|
-
localStorage.removeItem(SESSION_ID_KEY);
|
|
292
|
-
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
293
|
-
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
294
|
-
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
321
|
// src/targets.ts
|
|
298
322
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
299
323
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
@@ -747,6 +771,7 @@ function applyPageContext(input, opts) {
|
|
|
747
771
|
}
|
|
748
772
|
const pageFields = {};
|
|
749
773
|
for (const pf of opts.pageData?.pageFields || []) {
|
|
774
|
+
if (pf.dataType === "taxonomy") continue;
|
|
750
775
|
if (pf.source === "static") {
|
|
751
776
|
if (pf.value !== void 0) pageFields[pf.key] = pf.value;
|
|
752
777
|
continue;
|
|
@@ -769,6 +794,7 @@ function applyPageContext(input, opts) {
|
|
|
769
794
|
function staticPageFieldsFromSnapshot(pageData) {
|
|
770
795
|
const pageFields = {};
|
|
771
796
|
for (const pf of pageData?.pageFields || []) {
|
|
797
|
+
if (pf.dataType === "taxonomy") continue;
|
|
772
798
|
if (pf.source === "static" && pf.value !== void 0) {
|
|
773
799
|
pageFields[pf.key] = pf.value;
|
|
774
800
|
}
|
|
@@ -786,6 +812,11 @@ function attachStaticPageContext(pageData, pageRoute) {
|
|
|
786
812
|
pageRoute: pageRoute || ""
|
|
787
813
|
};
|
|
788
814
|
}
|
|
815
|
+
function withPageTaxonomies(properties, taxonomies) {
|
|
816
|
+
if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
|
|
817
|
+
const page2 = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
|
|
818
|
+
return { ...properties, page: { ...page2, taxonomies } };
|
|
819
|
+
}
|
|
789
820
|
function mergeEventContext(properties, attached) {
|
|
790
821
|
if (!attached) return properties;
|
|
791
822
|
return {
|
|
@@ -796,6 +827,27 @@ function mergeEventContext(properties, attached) {
|
|
|
796
827
|
...attached.pageResource ? { pageResource: attached.pageResource } : {}
|
|
797
828
|
};
|
|
798
829
|
}
|
|
830
|
+
|
|
831
|
+
// src/edge/normalizeRoute.ts
|
|
832
|
+
function normalizeRoute(route) {
|
|
833
|
+
let path = String(route || "").trim();
|
|
834
|
+
if (!path) return "/";
|
|
835
|
+
try {
|
|
836
|
+
if (/^https?:\/\//i.test(path)) {
|
|
837
|
+
path = new URL(path).pathname;
|
|
838
|
+
}
|
|
839
|
+
} catch {
|
|
840
|
+
}
|
|
841
|
+
const q = path.indexOf("?");
|
|
842
|
+
if (q >= 0) path = path.slice(0, q);
|
|
843
|
+
const h = path.indexOf("#");
|
|
844
|
+
if (h >= 0) path = path.slice(0, h);
|
|
845
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
846
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
847
|
+
path = path.replace(/\/+$/, "");
|
|
848
|
+
}
|
|
849
|
+
return path || "/";
|
|
850
|
+
}
|
|
799
851
|
function setPageResourceFields(fields) {
|
|
800
852
|
}
|
|
801
853
|
|
|
@@ -873,27 +925,6 @@ function isAmplifyUpEditorRoute(pathname) {
|
|
|
873
925
|
return pathname === AMPLIFYUP_EDITOR_ROUTE || pathname.startsWith(`${AMPLIFYUP_EDITOR_ROUTE}/`);
|
|
874
926
|
}
|
|
875
927
|
|
|
876
|
-
// src/edge/normalizeRoute.ts
|
|
877
|
-
function normalizeRoute(route) {
|
|
878
|
-
let path = String(route || "").trim();
|
|
879
|
-
if (!path) return "/";
|
|
880
|
-
try {
|
|
881
|
-
if (/^https?:\/\//i.test(path)) {
|
|
882
|
-
path = new URL(path).pathname;
|
|
883
|
-
}
|
|
884
|
-
} catch {
|
|
885
|
-
}
|
|
886
|
-
const q = path.indexOf("?");
|
|
887
|
-
if (q >= 0) path = path.slice(0, q);
|
|
888
|
-
const h = path.indexOf("#");
|
|
889
|
-
if (h >= 0) path = path.slice(0, h);
|
|
890
|
-
if (!path.startsWith("/")) path = `/${path}`;
|
|
891
|
-
if (path.length > 1 && path.endsWith("/")) {
|
|
892
|
-
path = path.replace(/\/+$/, "");
|
|
893
|
-
}
|
|
894
|
-
return path || "/";
|
|
895
|
-
}
|
|
896
|
-
|
|
897
928
|
// src/edge/variantKeys.ts
|
|
898
929
|
function serializeVariantKeys(keys) {
|
|
899
930
|
if (!keys) return "";
|
|
@@ -1015,7 +1046,8 @@ function mapResolvedToPageConfig(payload) {
|
|
|
1015
1046
|
},
|
|
1016
1047
|
...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
|
|
1017
1048
|
...payload.pageData ? { pageData: payload.pageData } : {},
|
|
1018
|
-
...payload.pageResources ? { pageResources: payload.pageResources } : {}
|
|
1049
|
+
...payload.pageResources ? { pageResources: payload.pageResources } : {},
|
|
1050
|
+
...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
|
|
1019
1051
|
};
|
|
1020
1052
|
}
|
|
1021
1053
|
function collectDegraded(payload) {
|
|
@@ -1247,6 +1279,7 @@ function searchSpec(pagination, field, term) {
|
|
|
1247
1279
|
}
|
|
1248
1280
|
|
|
1249
1281
|
// src/index.ts
|
|
1282
|
+
var PAGE_VIEW_HOLD_MS = 1500;
|
|
1250
1283
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
1251
1284
|
var DWELL_POLL_MS = 5e3;
|
|
1252
1285
|
function readPreviewQueryOverrides() {
|
|
@@ -1320,6 +1353,12 @@ var AmplifyUpSDK = class {
|
|
|
1320
1353
|
this.resolvedPageResource = null;
|
|
1321
1354
|
this.resolvedPageRoute = "";
|
|
1322
1355
|
this.resolvedRouteParams = {};
|
|
1356
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
1357
|
+
this.pendingResolvePath = null;
|
|
1358
|
+
this.heldPageView = null;
|
|
1359
|
+
this.resolvedPageTaxonomies = null;
|
|
1360
|
+
/** Path the taxonomies above were resolved for. */
|
|
1361
|
+
this.resolvedTaxonomiesPath = null;
|
|
1323
1362
|
this.historyHooksInstalled = false;
|
|
1324
1363
|
this.pageEngagementState = {
|
|
1325
1364
|
reached: /* @__PURE__ */ new Set(),
|
|
@@ -1850,8 +1889,10 @@ var AmplifyUpSDK = class {
|
|
|
1850
1889
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
1851
1890
|
* mapped page fields can run.
|
|
1852
1891
|
*/
|
|
1853
|
-
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources) {
|
|
1892
|
+
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
|
|
1854
1893
|
this.resolvedPageData = pageData || null;
|
|
1894
|
+
this.resolvedPageTaxonomies = pageTaxonomies || null;
|
|
1895
|
+
this.resolvedTaxonomiesPath = this.pendingResolvePath;
|
|
1855
1896
|
if (pageRoute) this.resolvedPageRoute = pageRoute;
|
|
1856
1897
|
if (routeParams) this.resolvedRouteParams = routeParams;
|
|
1857
1898
|
const firstResourceName = pageData?.resources?.[0]?.name;
|
|
@@ -1884,6 +1925,28 @@ var AmplifyUpSDK = class {
|
|
|
1884
1925
|
getAttachedPageContext() {
|
|
1885
1926
|
return this.attachedPageContext;
|
|
1886
1927
|
}
|
|
1928
|
+
/**
|
|
1929
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
1930
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
1931
|
+
* taxonomies.
|
|
1932
|
+
*/
|
|
1933
|
+
beginPageResolve(path) {
|
|
1934
|
+
this.pendingResolvePath = normalizeRoute(path);
|
|
1935
|
+
this.resolvedPageTaxonomies = null;
|
|
1936
|
+
this.resolvedTaxonomiesPath = null;
|
|
1937
|
+
}
|
|
1938
|
+
endPageResolve(path) {
|
|
1939
|
+
if (this.pendingResolvePath !== normalizeRoute(path)) return;
|
|
1940
|
+
this.pendingResolvePath = null;
|
|
1941
|
+
this.flushHeldPageView();
|
|
1942
|
+
}
|
|
1943
|
+
flushHeldPageView() {
|
|
1944
|
+
const held = this.heldPageView;
|
|
1945
|
+
if (!held) return;
|
|
1946
|
+
clearTimeout(held.timer);
|
|
1947
|
+
this.heldPageView = null;
|
|
1948
|
+
this.sendPageView(held.url, held.properties);
|
|
1949
|
+
}
|
|
1887
1950
|
/**
|
|
1888
1951
|
* Track a page view
|
|
1889
1952
|
*/
|
|
@@ -1894,6 +1957,21 @@ var AmplifyUpSDK = class {
|
|
|
1894
1957
|
if (!this.isInitialized()) {
|
|
1895
1958
|
return;
|
|
1896
1959
|
}
|
|
1960
|
+
this.lastTrackedPath = url;
|
|
1961
|
+
if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
|
|
1962
|
+
this.flushHeldPageView();
|
|
1963
|
+
this.heldPageView = {
|
|
1964
|
+
url,
|
|
1965
|
+
properties,
|
|
1966
|
+
timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
|
|
1967
|
+
};
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
this.flushHeldPageView();
|
|
1971
|
+
this.sendPageView(url, properties);
|
|
1972
|
+
}
|
|
1973
|
+
sendPageView(url, properties) {
|
|
1974
|
+
const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
|
|
1897
1975
|
const instanceId = getInstanceId();
|
|
1898
1976
|
const sessionId = getSessionId();
|
|
1899
1977
|
const pageProperties = {
|
|
@@ -1905,10 +1983,9 @@ var AmplifyUpSDK = class {
|
|
|
1905
1983
|
sessionId,
|
|
1906
1984
|
trackingId: this.config?.trackingId,
|
|
1907
1985
|
// Timestamp is included in event payload
|
|
1908
|
-
...mergeEventContext(properties || {}, this.attachedPageContext)
|
|
1986
|
+
...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
|
|
1909
1987
|
};
|
|
1910
1988
|
this.adapter.page(pageProperties);
|
|
1911
|
-
this.lastTrackedPath = url;
|
|
1912
1989
|
}
|
|
1913
1990
|
/**
|
|
1914
1991
|
* Track an event
|