@amplifyup/sdk 0.1.21 → 0.1.23
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 +65 -38
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +144 -17
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +144 -17
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +125 -6
- package/dist/index.d.ts +125 -6
- package/dist/index.js +319 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +313 -18
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +5 -3
- package/dist/react.d.ts +5 -3
- package/dist/react.js +383 -45
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +383 -45
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +26 -8
- package/dist/server.d.ts +26 -8
- package/dist/server.js +277 -20
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +277 -21
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Cy5aWQ5c.d.mts → types-BxpG9Gsy.d.mts} +37 -2
- package/dist/{types-Cy5aWQ5c.d.ts → types-BxpG9Gsy.d.ts} +37 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -141,17 +141,42 @@ var AWSAdapter = class {
|
|
|
141
141
|
};
|
|
142
142
|
this.sendEvent("/v1/track", eventData);
|
|
143
143
|
}
|
|
144
|
-
identify(
|
|
144
|
+
identify(userIdOrIdentifiers, traits = {}) {
|
|
145
145
|
if (!this.initialized) {
|
|
146
146
|
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
|
+
const isMap = userIdOrIdentifiers !== null && typeof userIdOrIdentifiers === "object" && !Array.isArray(userIdOrIdentifiers);
|
|
150
|
+
const identifiers = isMap ? userIdOrIdentifiers : traits.identifiers;
|
|
151
|
+
const userId = isMap ? void 0 : String(userIdOrIdentifiers);
|
|
149
152
|
const eventData = {
|
|
150
153
|
type: "identify",
|
|
151
|
-
userId,
|
|
152
154
|
anonymousId: traits.instanceId,
|
|
153
155
|
traits: {
|
|
154
|
-
...traits
|
|
156
|
+
...traits,
|
|
157
|
+
...identifiers ? { identifiers } : {}
|
|
158
|
+
},
|
|
159
|
+
...identifiers ? { identifiers } : {},
|
|
160
|
+
...userId ? { userId } : {},
|
|
161
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
162
|
+
};
|
|
163
|
+
this.sendEvent("/v1/track", eventData);
|
|
164
|
+
}
|
|
165
|
+
setProfileFields(fields, context = {}) {
|
|
166
|
+
if (!this.initialized) {
|
|
167
|
+
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const eventData = {
|
|
171
|
+
type: "set_fields",
|
|
172
|
+
anonymousId: context.instanceId,
|
|
173
|
+
fields,
|
|
174
|
+
traits: {
|
|
175
|
+
instanceId: context.instanceId,
|
|
176
|
+
trackingId: context.trackingId
|
|
177
|
+
},
|
|
178
|
+
properties: {
|
|
179
|
+
trackingId: context.trackingId
|
|
155
180
|
},
|
|
156
181
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
157
182
|
};
|
|
@@ -213,6 +238,7 @@ function clearIds() {
|
|
|
213
238
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
214
239
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
215
240
|
var PROD_ORCHESTRATOR = "https://amplifyup.ai";
|
|
241
|
+
var PROD_EDGE = "https://edge.amplifyup.ai";
|
|
216
242
|
function isAmplifyUpTarget(value) {
|
|
217
243
|
return value === "local" || value === "dev" || value === "production";
|
|
218
244
|
}
|
|
@@ -248,6 +274,10 @@ function localAwsApiUrl() {
|
|
|
248
274
|
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL : void 0;
|
|
249
275
|
return (fromEnv || AWS_DEV_API).replace(/\/$/, "");
|
|
250
276
|
}
|
|
277
|
+
function localEdgeUrl() {
|
|
278
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL : void 0;
|
|
279
|
+
return (fromEnv || "http://localhost:8787").replace(/\/$/, "");
|
|
280
|
+
}
|
|
251
281
|
function resolveAmplifyUpUrls(target) {
|
|
252
282
|
if (target === "local") {
|
|
253
283
|
const orchestratorUrl2 = localOrchestratorUrl();
|
|
@@ -258,18 +288,22 @@ function resolveAmplifyUpUrls(target) {
|
|
|
258
288
|
orchestratorUrl: orchestratorUrl2,
|
|
259
289
|
// Events + personalize → AWS development stack
|
|
260
290
|
apiGatewayUrl,
|
|
261
|
-
decisionApiUrl: `${apiGatewayUrl}/v1/personalize
|
|
291
|
+
decisionApiUrl: `${apiGatewayUrl}/v1/personalize`,
|
|
292
|
+
edgeUrl: localEdgeUrl()
|
|
262
293
|
};
|
|
263
294
|
}
|
|
264
295
|
const resolvedApi = typeof process !== "undefined" && process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL?.replace(/\/$/, "") || AWS_PROD_API;
|
|
265
296
|
const orchestratorFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
266
297
|
const isLocalOrchestrator = !!orchestratorFromEnv && (orchestratorFromEnv.includes("localhost") || orchestratorFromEnv.includes("127.0.0.1"));
|
|
267
298
|
const orchestratorUrl = isLocalOrchestrator || !orchestratorFromEnv ? PROD_ORCHESTRATOR : orchestratorFromEnv.replace(/\/$/, "");
|
|
299
|
+
const edgeFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL?.replace(/\/$/, "") : void 0;
|
|
300
|
+
const edgeUrl = edgeFromEnv && !edgeFromEnv.includes("localhost") && !edgeFromEnv.includes("127.0.0.1") ? edgeFromEnv : PROD_EDGE;
|
|
268
301
|
return {
|
|
269
302
|
target: "production",
|
|
270
303
|
apiGatewayUrl: resolvedApi,
|
|
271
304
|
orchestratorUrl,
|
|
272
|
-
decisionApiUrl: `${resolvedApi}/v1/personalize
|
|
305
|
+
decisionApiUrl: `${resolvedApi}/v1/personalize`,
|
|
306
|
+
edgeUrl
|
|
273
307
|
};
|
|
274
308
|
}
|
|
275
309
|
|
|
@@ -299,7 +333,179 @@ function isComposerPreview() {
|
|
|
299
333
|
return false;
|
|
300
334
|
}
|
|
301
335
|
|
|
336
|
+
// src/edge/normalizeRoute.ts
|
|
337
|
+
function normalizeRoute(route) {
|
|
338
|
+
let path = String(route || "").trim();
|
|
339
|
+
if (!path) return "/";
|
|
340
|
+
try {
|
|
341
|
+
if (/^https?:\/\//i.test(path)) {
|
|
342
|
+
path = new URL(path).pathname;
|
|
343
|
+
}
|
|
344
|
+
} catch {
|
|
345
|
+
}
|
|
346
|
+
const q = path.indexOf("?");
|
|
347
|
+
if (q >= 0) path = path.slice(0, q);
|
|
348
|
+
const h = path.indexOf("#");
|
|
349
|
+
if (h >= 0) path = path.slice(0, h);
|
|
350
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
351
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
352
|
+
path = path.replace(/\/+$/, "");
|
|
353
|
+
}
|
|
354
|
+
return path || "/";
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/edge/resolve.ts
|
|
358
|
+
var EdgeResolveError = class extends Error {
|
|
359
|
+
constructor(message, status, body) {
|
|
360
|
+
super(message);
|
|
361
|
+
this.name = "EdgeResolveError";
|
|
362
|
+
this.status = status;
|
|
363
|
+
this.body = body;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
async function fetchEdgeResolve(options) {
|
|
367
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
368
|
+
const route = normalizeRoute(options.route);
|
|
369
|
+
const params = new URLSearchParams({
|
|
370
|
+
route,
|
|
371
|
+
trackingId: options.trackingId
|
|
372
|
+
});
|
|
373
|
+
if (options.siteId) params.set("site", options.siteId);
|
|
374
|
+
if (options.anonId) params.set("anonId", options.anonId);
|
|
375
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
376
|
+
const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, {
|
|
377
|
+
method: "GET",
|
|
378
|
+
headers: { Accept: "application/json" }
|
|
379
|
+
});
|
|
380
|
+
const body = await res.json().catch(() => ({}));
|
|
381
|
+
if (!res.ok) {
|
|
382
|
+
throw new EdgeResolveError(
|
|
383
|
+
(body && typeof body === "object" && "error" in body ? String(body.error) : `Edge resolve failed (${res.status})`) || `Edge resolve failed (${res.status})`,
|
|
384
|
+
res.status,
|
|
385
|
+
body
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
return body;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/edge/mapResolvedToPageConfig.ts
|
|
392
|
+
function mapResolvedComponent(node) {
|
|
393
|
+
const slots = [];
|
|
394
|
+
if (node.children) {
|
|
395
|
+
for (const [slotId, kids] of Object.entries(node.children)) {
|
|
396
|
+
slots.push({
|
|
397
|
+
slotId,
|
|
398
|
+
children: (kids || []).map(mapResolvedComponent)
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
id: node.instanceId,
|
|
404
|
+
componentId: node.componentId,
|
|
405
|
+
props: { ...node.props || {} },
|
|
406
|
+
...slots.length > 0 ? { slots } : {},
|
|
407
|
+
_contentSource: "edge"
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function mapResolvedToPageConfig(payload) {
|
|
411
|
+
let layoutTree = [];
|
|
412
|
+
if (payload.tree && payload.tree.length > 0) {
|
|
413
|
+
layoutTree = payload.tree.map(mapResolvedComponent);
|
|
414
|
+
} else {
|
|
415
|
+
const zoneIds = Object.keys(payload.zones || {}).sort();
|
|
416
|
+
for (const zoneId of zoneIds) {
|
|
417
|
+
const roots = payload.zones[zoneId] || [];
|
|
418
|
+
layoutTree.push(...roots.map(mapResolvedComponent));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
id: `edge:${payload.siteId}:${payload.route}:v${payload.version}`,
|
|
423
|
+
route: payload.route,
|
|
424
|
+
title: "",
|
|
425
|
+
layoutTree,
|
|
426
|
+
meta: {
|
|
427
|
+
// Stash edge meta for diagnostics (not visitor-facing)
|
|
428
|
+
description: payload.meta?.degraded ? "degraded" : void 0
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function collectDegraded(payload) {
|
|
433
|
+
if (payload.meta?.degraded) return true;
|
|
434
|
+
const walk = (nodes) => nodes.some(
|
|
435
|
+
(n) => !!n.degraded || (n.children ? Object.values(n.children).some((kids) => walk(kids || [])) : false)
|
|
436
|
+
);
|
|
437
|
+
if (payload.tree && walk(payload.tree)) return true;
|
|
438
|
+
return Object.values(payload.zones || {}).some((roots) => walk(roots || []));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/content/fetchContent.ts
|
|
442
|
+
async function fetchContent(options) {
|
|
443
|
+
const preview = options.preview ?? (typeof window !== "undefined" ? isComposerPreview() : false);
|
|
444
|
+
if (preview) {
|
|
445
|
+
try {
|
|
446
|
+
const page2 = await options.fetchOrchestratorPage(options.route, true);
|
|
447
|
+
return {
|
|
448
|
+
pageConfig: page2,
|
|
449
|
+
source: "orchestrator",
|
|
450
|
+
meta: { source: "orchestrator" },
|
|
451
|
+
error: null
|
|
452
|
+
};
|
|
453
|
+
} catch (err) {
|
|
454
|
+
return {
|
|
455
|
+
pageConfig: null,
|
|
456
|
+
source: "orchestrator",
|
|
457
|
+
meta: { source: "orchestrator" },
|
|
458
|
+
error: err instanceof Error ? err.message : "Failed to load preview"
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
try {
|
|
463
|
+
const payload = await fetchEdgeResolve({
|
|
464
|
+
edgeUrl: options.edgeUrl,
|
|
465
|
+
trackingId: options.trackingId,
|
|
466
|
+
route: options.route,
|
|
467
|
+
anonId: options.anonId,
|
|
468
|
+
siteId: options.siteId,
|
|
469
|
+
fetch: options.fetchFn
|
|
470
|
+
});
|
|
471
|
+
const pageConfig = mapResolvedToPageConfig(payload);
|
|
472
|
+
const degraded = collectDegraded(payload);
|
|
473
|
+
return {
|
|
474
|
+
pageConfig,
|
|
475
|
+
source: "edge",
|
|
476
|
+
meta: {
|
|
477
|
+
source: "edge",
|
|
478
|
+
version: payload.version,
|
|
479
|
+
siteId: payload.siteId,
|
|
480
|
+
variantKeys: payload.meta?.variantKeys,
|
|
481
|
+
degraded,
|
|
482
|
+
audienceLookup: payload.meta?.audienceLookup,
|
|
483
|
+
decideLookup: payload.meta?.decideLookup,
|
|
484
|
+
resolvedAt: payload.meta?.resolvedAt
|
|
485
|
+
},
|
|
486
|
+
error: null
|
|
487
|
+
};
|
|
488
|
+
} catch (err) {
|
|
489
|
+
if (err instanceof EdgeResolveError && err.status === 404) {
|
|
490
|
+
return {
|
|
491
|
+
pageConfig: null,
|
|
492
|
+
source: "edge",
|
|
493
|
+
meta: { source: "edge" },
|
|
494
|
+
error: null
|
|
495
|
+
// unpublished → site fallback, not an error banner
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
pageConfig: null,
|
|
500
|
+
source: "edge",
|
|
501
|
+
meta: { source: "edge" },
|
|
502
|
+
error: err instanceof Error ? err.message : "Couldn't load page content."
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
302
507
|
// src/index.ts
|
|
508
|
+
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
303
509
|
function readPreviewQueryOverrides() {
|
|
304
510
|
if (typeof window === "undefined") return {};
|
|
305
511
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -327,6 +533,8 @@ var AmplifyUpSDK = class {
|
|
|
327
533
|
this.apiGatewayUrl = "";
|
|
328
534
|
this.orchestratorUrl = "";
|
|
329
535
|
this.decisionApiUrl = "";
|
|
536
|
+
this.edgeUrl = "";
|
|
537
|
+
this.siteId = "";
|
|
330
538
|
this.target = "local";
|
|
331
539
|
this.initialized = false;
|
|
332
540
|
/** Prevents overlapping init() from React Strict Mode double-mount */
|
|
@@ -366,7 +574,9 @@ var AmplifyUpSDK = class {
|
|
|
366
574
|
reached: /* @__PURE__ */ new Set(),
|
|
367
575
|
visibleMs: 0,
|
|
368
576
|
visibleSince: null,
|
|
369
|
-
lastDwellSecondsSent: 0
|
|
577
|
+
lastDwellSecondsSent: 0,
|
|
578
|
+
/** When the tab last became hidden — used for idle-resume re-page. */
|
|
579
|
+
hiddenAt: null
|
|
370
580
|
};
|
|
371
581
|
this.adapter = adapter || new AWSAdapter();
|
|
372
582
|
if (typeof window !== "undefined") {
|
|
@@ -481,7 +691,8 @@ var AmplifyUpSDK = class {
|
|
|
481
691
|
isInitialized: () => this.isInitialized(),
|
|
482
692
|
page: (url, properties) => this.page(url, properties),
|
|
483
693
|
track: (eventName, properties) => this.track(eventName, properties),
|
|
484
|
-
identify: (
|
|
694
|
+
identify: (userIdOrIdentifiers, traits) => this.identify(userIdOrIdentifiers, traits),
|
|
695
|
+
setProfileFields: (fields) => this.setProfileFields(fields)
|
|
485
696
|
};
|
|
486
697
|
}
|
|
487
698
|
async performInit(config) {
|
|
@@ -496,6 +707,8 @@ var AmplifyUpSDK = class {
|
|
|
496
707
|
this.apiGatewayUrl = urls.apiGatewayUrl;
|
|
497
708
|
this.orchestratorUrl = urls.orchestratorUrl;
|
|
498
709
|
this.decisionApiUrl = urls.decisionApiUrl;
|
|
710
|
+
this.edgeUrl = urls.edgeUrl;
|
|
711
|
+
this.siteId = config.siteId || "";
|
|
499
712
|
const previewOverrides = readPreviewQueryOverrides();
|
|
500
713
|
if (previewOverrides.orchestratorUrl) {
|
|
501
714
|
this.orchestratorUrl = previewOverrides.orchestratorUrl;
|
|
@@ -504,6 +717,7 @@ var AmplifyUpSDK = class {
|
|
|
504
717
|
this.target = "production";
|
|
505
718
|
this.apiGatewayUrl = prodUrls.apiGatewayUrl;
|
|
506
719
|
this.decisionApiUrl = prodUrls.decisionApiUrl;
|
|
720
|
+
this.edgeUrl = prodUrls.edgeUrl;
|
|
507
721
|
}
|
|
508
722
|
}
|
|
509
723
|
this.config = {
|
|
@@ -511,7 +725,8 @@ var AmplifyUpSDK = class {
|
|
|
511
725
|
debug: config.debug ?? true,
|
|
512
726
|
// Enable debug by default
|
|
513
727
|
target: this.target,
|
|
514
|
-
dev: config.dev
|
|
728
|
+
dev: config.dev,
|
|
729
|
+
...config.siteId ? { siteId: config.siteId } : {}
|
|
515
730
|
};
|
|
516
731
|
try {
|
|
517
732
|
const adapterConfig = {
|
|
@@ -597,6 +812,7 @@ var AmplifyUpSDK = class {
|
|
|
597
812
|
state.visibleMs = 0;
|
|
598
813
|
state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
599
814
|
state.lastDwellSecondsSent = 0;
|
|
815
|
+
state.hiddenAt = document.visibilityState === "hidden" ? Date.now() : null;
|
|
600
816
|
let scrollRaf = null;
|
|
601
817
|
const path = () => this.currentPath();
|
|
602
818
|
const measureScrollPercent = () => {
|
|
@@ -639,12 +855,12 @@ var AmplifyUpSDK = class {
|
|
|
639
855
|
state.visibleMs += Date.now() - state.visibleSince;
|
|
640
856
|
state.visibleSince = Date.now();
|
|
641
857
|
};
|
|
642
|
-
const emitDwell = (
|
|
858
|
+
const emitDwell = (_force = false) => {
|
|
643
859
|
if (this.isPreviewMode()) return;
|
|
644
860
|
accumulateVisible();
|
|
645
861
|
const seconds = Math.floor(state.visibleMs / 1e3);
|
|
646
862
|
if (seconds <= 0) return;
|
|
647
|
-
if (
|
|
863
|
+
if (seconds <= state.lastDwellSecondsSent) return;
|
|
648
864
|
state.lastDwellSecondsSent = seconds;
|
|
649
865
|
this.track("Time on Page", {
|
|
650
866
|
seconds,
|
|
@@ -654,14 +870,34 @@ var AmplifyUpSDK = class {
|
|
|
654
870
|
this._emitPageDwell = emitDwell;
|
|
655
871
|
const onVisibility = () => {
|
|
656
872
|
if (document.visibilityState === "visible") {
|
|
873
|
+
const idleMs = state.hiddenAt != null ? Date.now() - state.hiddenAt : 0;
|
|
874
|
+
state.hiddenAt = null;
|
|
875
|
+
if (idleMs >= SESSION_IDLE_GAP_MS) {
|
|
876
|
+
this.resetEngagementQuiet();
|
|
877
|
+
const resumePath = path();
|
|
878
|
+
this.page(resumePath, { resumed: true });
|
|
879
|
+
this.lastTrackedPath = resumePath;
|
|
880
|
+
if (this.config?.debug) {
|
|
881
|
+
console.log(
|
|
882
|
+
"[AmplifyUp SDK] Idle resume page view",
|
|
883
|
+
resumePath,
|
|
884
|
+
`(hidden ${Math.round(idleMs / 6e4)}m)`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
657
888
|
state.visibleSince = Date.now();
|
|
658
889
|
} else {
|
|
659
890
|
emitDwell(true);
|
|
891
|
+
state.hiddenAt = Date.now();
|
|
660
892
|
state.visibleSince = null;
|
|
661
893
|
}
|
|
662
894
|
};
|
|
663
895
|
const onPageHide = () => {
|
|
664
896
|
emitDwell(true);
|
|
897
|
+
if (state.hiddenAt == null) {
|
|
898
|
+
state.hiddenAt = Date.now();
|
|
899
|
+
}
|
|
900
|
+
state.visibleSince = null;
|
|
665
901
|
};
|
|
666
902
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
667
903
|
document.addEventListener("visibilitychange", onVisibility);
|
|
@@ -690,13 +926,19 @@ var AmplifyUpSDK = class {
|
|
|
690
926
|
console.log("[AmplifyUp SDK] Page engagement tracking enabled");
|
|
691
927
|
}
|
|
692
928
|
}
|
|
929
|
+
/** Flush dwell then reset — used on SPA route changes. */
|
|
693
930
|
resetEngagementForNewPage() {
|
|
694
931
|
const emit = this._emitPageDwell;
|
|
695
932
|
emit?.(true);
|
|
933
|
+
this.resetEngagementQuiet();
|
|
934
|
+
}
|
|
935
|
+
/** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
|
|
936
|
+
resetEngagementQuiet() {
|
|
696
937
|
const state = this.pageEngagementState;
|
|
697
938
|
state.reached = /* @__PURE__ */ new Set();
|
|
698
939
|
state.visibleMs = 0;
|
|
699
940
|
state.lastDwellSecondsSent = 0;
|
|
941
|
+
state.hiddenAt = null;
|
|
700
942
|
state.visibleSince = typeof document !== "undefined" && document.visibilityState === "visible" ? Date.now() : null;
|
|
701
943
|
this.componentViewSeen.clear();
|
|
702
944
|
}
|
|
@@ -882,12 +1124,17 @@ var AmplifyUpSDK = class {
|
|
|
882
1124
|
});
|
|
883
1125
|
}
|
|
884
1126
|
/**
|
|
885
|
-
* Identify
|
|
1127
|
+
* Identify a visitor.
|
|
1128
|
+
* - identify('user_123') — bare string; server maps via org default type
|
|
1129
|
+
* - identify({ email: '...', crm_id: '...' }) — explicit types
|
|
1130
|
+
* - identify('user_123', traits) — legacy form
|
|
886
1131
|
*/
|
|
887
|
-
identify(
|
|
1132
|
+
identify(userIdOrIdentifiers, traits) {
|
|
888
1133
|
if (this.isPreviewMode()) {
|
|
889
1134
|
if (this.config?.debug) {
|
|
890
|
-
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
1135
|
+
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
1136
|
+
userIdOrIdentifiers
|
|
1137
|
+
});
|
|
891
1138
|
}
|
|
892
1139
|
return;
|
|
893
1140
|
}
|
|
@@ -903,10 +1150,45 @@ var AmplifyUpSDK = class {
|
|
|
903
1150
|
trackingId: this.config?.trackingId,
|
|
904
1151
|
...traits
|
|
905
1152
|
};
|
|
906
|
-
this.adapter.identify(
|
|
907
|
-
|
|
1153
|
+
this.adapter.identify(userIdOrIdentifiers, identifyTraits);
|
|
1154
|
+
if (typeof userIdOrIdentifiers === "string") {
|
|
1155
|
+
setUserId(userIdOrIdentifiers);
|
|
1156
|
+
}
|
|
1157
|
+
if (this.config?.debug) {
|
|
1158
|
+
console.log("AmplifyUp SDK: User identified", {
|
|
1159
|
+
userIdOrIdentifiers,
|
|
1160
|
+
instanceId
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Set profile fields (partial update). Omitted keys are left alone;
|
|
1166
|
+
* an explicit empty value clears the field.
|
|
1167
|
+
*/
|
|
1168
|
+
setProfileFields(fields) {
|
|
1169
|
+
if (this.isPreviewMode()) {
|
|
1170
|
+
if (this.config?.debug) {
|
|
1171
|
+
console.log("AmplifyUp SDK: setProfileFields disabled in preview mode", {
|
|
1172
|
+
fields
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (!this.isInitialized()) {
|
|
1178
|
+
if (this.config?.debug) {
|
|
1179
|
+
console.warn("AmplifyUp SDK: Not initialized. setProfileFields not called.");
|
|
1180
|
+
}
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
const instanceId = getInstanceId();
|
|
1184
|
+
if (typeof this.adapter.setProfileFields === "function") {
|
|
1185
|
+
this.adapter.setProfileFields(fields, {
|
|
1186
|
+
instanceId: instanceId || void 0,
|
|
1187
|
+
trackingId: this.config?.trackingId
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
908
1190
|
if (this.config?.debug) {
|
|
909
|
-
console.log("AmplifyUp SDK:
|
|
1191
|
+
console.log("AmplifyUp SDK: Profile fields set", { fields, instanceId });
|
|
910
1192
|
}
|
|
911
1193
|
}
|
|
912
1194
|
/**
|
|
@@ -1081,6 +1363,18 @@ Available Console Commands:
|
|
|
1081
1363
|
getDecisionApiUrl() {
|
|
1082
1364
|
return this.decisionApiUrl || void 0;
|
|
1083
1365
|
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Get Edge Worker URL (production content resolve)
|
|
1368
|
+
*/
|
|
1369
|
+
getEdgeUrl() {
|
|
1370
|
+
return this.edgeUrl || void 0;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Optional site id from config (Edge can resolve via trackingId alone).
|
|
1374
|
+
*/
|
|
1375
|
+
getSiteId() {
|
|
1376
|
+
return this.siteId || this.config?.siteId || void 0;
|
|
1377
|
+
}
|
|
1084
1378
|
/**
|
|
1085
1379
|
* Build API URL for fetching page config from the Layout Provider
|
|
1086
1380
|
*/
|
|
@@ -2363,7 +2657,8 @@ var trackClick = (elementId, elementText, properties) => getSDK().trackClick(ele
|
|
|
2363
2657
|
var trackFormSubmit = (formId, formData) => getSDK().trackFormSubmit(formId, formData);
|
|
2364
2658
|
var trackFormFieldInteraction = (fieldName, fieldValue) => getSDK().trackFormFieldInteraction(fieldName, fieldValue);
|
|
2365
2659
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
2366
|
-
var identify = (
|
|
2660
|
+
var identify = (userIdOrIdentifiers, traits) => getSDK().identify(userIdOrIdentifiers, traits);
|
|
2661
|
+
var setProfileFields = (fields) => getSDK().setProfileFields(fields);
|
|
2367
2662
|
var trackContentEngagement = (contentId, engagementType) => getSDK().trackContentEngagement(contentId, engagementType);
|
|
2368
2663
|
var reset = () => getSDK().reset();
|
|
2369
2664
|
var getInstanceId2 = () => getSDK().getInstanceId();
|
|
@@ -2393,6 +2688,6 @@ var verifyAWSConnection = () => {
|
|
|
2393
2688
|
};
|
|
2394
2689
|
var index_default = getSDK();
|
|
2395
2690
|
|
|
2396
|
-
export { AmplifyUpSDK, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, normalizeAmplifyUpTarget, page, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
2691
|
+
export { AmplifyUpSDK, EdgeResolveError, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, mapResolvedToPageConfig, normalizeAmplifyUpTarget, normalizeRoute, page, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
2397
2692
|
//# sourceMappingURL=index.mjs.map
|
|
2398
2693
|
//# sourceMappingURL=index.mjs.map
|