@active-reach/web-sdk 1.52.0 → 1.54.0
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 +14 -0
- package/dist/aegis-boot.min.js +2 -0
- package/dist/aegis-boot.min.js.map +1 -0
- package/dist/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-DMY0Q0rI.mjs → analytics-CM31xECy.mjs} +3 -211
- package/dist/analytics-CM31xECy.mjs.map +1 -0
- package/dist/boot.d.ts +46 -0
- package/dist/boot.d.ts.map +1 -0
- package/dist/boot.js +63 -0
- package/dist/boot.js.map +1 -0
- package/dist/core/bootstrap.d.ts.map +1 -1
- package/dist/core/prefetch-bundle-client.d.ts.map +1 -1
- package/dist/fetch-abort-Bs-Stg-I.mjs +216 -0
- package/dist/fetch-abort-Bs-Stg-I.mjs.map +1 -0
- package/dist/inapp/AegisInAppManager.d.ts +8 -0
- package/dist/inapp/AegisInAppManager.d.ts.map +1 -1
- package/dist/inapp/active-request.d.ts +63 -0
- package/dist/inapp/active-request.d.ts.map +1 -0
- package/dist/inapp/marketing-consent.d.ts +45 -0
- package/dist/inapp/marketing-consent.d.ts.map +1 -0
- package/dist/index.js +134 -183
- package/dist/index.js.map +1 -1
- package/dist/integrations/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/storage-D5jp9bO-.mjs +212 -0
- package/dist/storage-D5jp9bO-.mjs.map +1 -0
- package/dist/triggers/IntentRuleEvaluator.d.ts.map +1 -1
- package/dist/utils/fetch-abort.d.ts +17 -0
- package/dist/utils/fetch-abort.d.ts.map +1 -1
- package/dist/widgets/AegisWidgetManager.d.ts +2 -0
- package/dist/widgets/AegisWidgetManager.d.ts.map +1 -1
- package/package.json +9 -3
- package/dist/analytics-DMY0Q0rI.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing-consent.d.ts","sourceRoot":"","sources":["../../src/inapp/marketing-consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AAEzD,oFAAoF;AACpF,eAAO,MAAM,+BAA+B,8CAA8C,CAAC;AAE3F,eAAO,MAAM,2BAA2B,yBAAyB,CAAC;AAClE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AAEtE,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAE5F;AAED,uDAAuD;AACvD,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,gBAAgB,EAAE,OAAO,GACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB;IAAE,GAAG,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAoBpD"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { g as generateUUID,
|
|
2
|
-
import { B, E, N, R, U, m } from "./analytics-
|
|
1
|
+
import { g as generateUUID, r as recordInAppItemTouch, e as ensureFbc, l as logger, A as Aegis } from "./analytics-CM31xECy.mjs";
|
|
2
|
+
import { B, E, N, R, U, m } from "./analytics-CM31xECy.mjs";
|
|
3
|
+
import { S as Storage, r as redactUrl, i as isPreviewPage } from "./storage-D5jp9bO-.mjs";
|
|
4
|
+
import { r as readAnonIdFromStorage$1, m as markReturningVisitor, a as activeRequestKey, c as cartKeyPartOf, K as KNOWN_SURFACES, b as buildActiveRequest, t as takeActiveBoot, d as fetchWithAbort, f as fetchWithAbortRetry, e as detectDeviceType, g as readABAssignments, h as currentPageUrl, i as isNewVisitor, j as isAbortError, S as SDK_FETCH_ABORT_MS } from "./fetch-abort-Bs-Stg-I.mjs";
|
|
3
5
|
import { a as assetIdOf } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
4
6
|
import { A } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
5
7
|
function debounce(func, wait) {
|
|
@@ -8337,6 +8339,37 @@ function stepsAsFormFields(ic, title) {
|
|
|
8337
8339
|
return options.length > 0 ? { key, label, type: "select", options, required: step.required === true } : { key, label, type: "text", required: step.required === true };
|
|
8338
8340
|
});
|
|
8339
8341
|
}
|
|
8342
|
+
const MARKETING_CONSENT_KEY = "marketing_consent";
|
|
8343
|
+
const MARKETING_CONSENT_DEFAULT_LABEL = "Send me offers on WhatsApp, SMS and email";
|
|
8344
|
+
const MARKETING_CONSENT_ROW_CLASS = "aegis-in-app-consent";
|
|
8345
|
+
const MARKETING_CONSENT_BOX_CLASS = "aegis-in-app-consent-box";
|
|
8346
|
+
function asksMarketingConsent(ic) {
|
|
8347
|
+
return !!ic && ic.ask_marketing_consent === true;
|
|
8348
|
+
}
|
|
8349
|
+
function marketingConsentLabel() {
|
|
8350
|
+
return MARKETING_CONSENT_DEFAULT_LABEL;
|
|
8351
|
+
}
|
|
8352
|
+
function formPayload(fields, marketingConsent) {
|
|
8353
|
+
return marketingConsent ? { fields, [MARKETING_CONSENT_KEY]: true } : { fields };
|
|
8354
|
+
}
|
|
8355
|
+
function renderMarketingConsentRow(label, text, campaignId) {
|
|
8356
|
+
const row = document.createElement("label");
|
|
8357
|
+
row.className = MARKETING_CONSENT_ROW_CLASS;
|
|
8358
|
+
row.style.cssText = `display: flex; align-items: flex-start; gap: 8px; font-size: 12px; opacity: 0.85; color: ${text}; cursor: pointer; line-height: 1.35;`;
|
|
8359
|
+
const input = document.createElement("input");
|
|
8360
|
+
input.type = "checkbox";
|
|
8361
|
+
input.name = MARKETING_CONSENT_KEY;
|
|
8362
|
+
input.id = `aegis-consent-${campaignId}`;
|
|
8363
|
+
input.className = `aegis-field ${MARKETING_CONSENT_BOX_CLASS}`;
|
|
8364
|
+
input.checked = false;
|
|
8365
|
+
input.style.cssText = `margin: 1px 0 0; width: 16px; height: 16px; flex: 0 0 16px; accent-color: ${text}; cursor: pointer;`;
|
|
8366
|
+
row.htmlFor = input.id;
|
|
8367
|
+
const words = document.createElement("span");
|
|
8368
|
+
words.textContent = label;
|
|
8369
|
+
row.appendChild(input);
|
|
8370
|
+
row.appendChild(words);
|
|
8371
|
+
return { row, input };
|
|
8372
|
+
}
|
|
8340
8373
|
const SECTION_SPOT_SELECTOR_PREFIX = "[data-aegis-section-spot=";
|
|
8341
8374
|
function isSectionSpotSelector(selector) {
|
|
8342
8375
|
return typeof selector === "string" && selector.trim().startsWith(SECTION_SPOT_SELECTOR_PREFIX);
|
|
@@ -8667,54 +8700,6 @@ function drawSlotShells(ctx, doc = document) {
|
|
|
8667
8700
|
});
|
|
8668
8701
|
return drawn;
|
|
8669
8702
|
}
|
|
8670
|
-
const RETURNING_MARKER_KEY = "aegis_returning_user";
|
|
8671
|
-
const SESSION_VERDICT_KEY = "aegis_new_visitor_session";
|
|
8672
|
-
let cachedVerdict = null;
|
|
8673
|
-
function readSessionVerdict() {
|
|
8674
|
-
try {
|
|
8675
|
-
if (typeof sessionStorage === "undefined") return null;
|
|
8676
|
-
const stored = sessionStorage.getItem(SESSION_VERDICT_KEY);
|
|
8677
|
-
if (stored === "1") return true;
|
|
8678
|
-
if (stored === "0") return false;
|
|
8679
|
-
return null;
|
|
8680
|
-
} catch {
|
|
8681
|
-
return null;
|
|
8682
|
-
}
|
|
8683
|
-
}
|
|
8684
|
-
function writeSessionVerdict(verdict) {
|
|
8685
|
-
try {
|
|
8686
|
-
if (typeof sessionStorage === "undefined") return;
|
|
8687
|
-
sessionStorage.setItem(SESSION_VERDICT_KEY, verdict ? "1" : "0");
|
|
8688
|
-
} catch {
|
|
8689
|
-
}
|
|
8690
|
-
}
|
|
8691
|
-
function readMarkerVerdict() {
|
|
8692
|
-
try {
|
|
8693
|
-
if (typeof localStorage === "undefined") return false;
|
|
8694
|
-
return localStorage.getItem(RETURNING_MARKER_KEY) === null;
|
|
8695
|
-
} catch {
|
|
8696
|
-
return false;
|
|
8697
|
-
}
|
|
8698
|
-
}
|
|
8699
|
-
function isNewVisitor() {
|
|
8700
|
-
if (cachedVerdict !== null) return cachedVerdict;
|
|
8701
|
-
const sessionVerdict = readSessionVerdict();
|
|
8702
|
-
if (sessionVerdict !== null) {
|
|
8703
|
-
cachedVerdict = sessionVerdict;
|
|
8704
|
-
return cachedVerdict;
|
|
8705
|
-
}
|
|
8706
|
-
cachedVerdict = readMarkerVerdict();
|
|
8707
|
-
writeSessionVerdict(cachedVerdict);
|
|
8708
|
-
return cachedVerdict;
|
|
8709
|
-
}
|
|
8710
|
-
function markReturningVisitor() {
|
|
8711
|
-
isNewVisitor();
|
|
8712
|
-
try {
|
|
8713
|
-
if (typeof localStorage === "undefined") return;
|
|
8714
|
-
localStorage.setItem(RETURNING_MARKER_KEY, "1");
|
|
8715
|
-
} catch {
|
|
8716
|
-
}
|
|
8717
|
-
}
|
|
8718
8703
|
const DEFAULT_SCROLL_DEPTH_PERCENT = 50;
|
|
8719
8704
|
const DEFAULT_TIME_ON_PAGE_SECONDS = 30;
|
|
8720
8705
|
const DEFAULT_IDLE_SECONDS = 30;
|
|
@@ -8779,27 +8764,6 @@ function armBehaviouralTriggers(engine, triggers, armed, fire, isMobile) {
|
|
|
8779
8764
|
}
|
|
8780
8765
|
return newlyArmed;
|
|
8781
8766
|
}
|
|
8782
|
-
const SDK_FETCH_ABORT_MS = 800;
|
|
8783
|
-
function fetchWithAbort(input, init = {}, timeoutMs = SDK_FETCH_ABORT_MS) {
|
|
8784
|
-
const budget = Math.min(timeoutMs, SDK_FETCH_ABORT_MS);
|
|
8785
|
-
if (typeof AbortController === "undefined") {
|
|
8786
|
-
return fetch(input, init);
|
|
8787
|
-
}
|
|
8788
|
-
const controller = new AbortController();
|
|
8789
|
-
const outer = init.signal;
|
|
8790
|
-
if (outer) {
|
|
8791
|
-
if (outer.aborted) controller.abort();
|
|
8792
|
-
else outer.addEventListener("abort", () => controller.abort(), { once: true });
|
|
8793
|
-
}
|
|
8794
|
-
const timer = setTimeout(() => controller.abort(), budget);
|
|
8795
|
-
return fetch(input, { ...init, signal: controller.signal }).catch((err) => {
|
|
8796
|
-
clearTimeout(timer);
|
|
8797
|
-
throw err;
|
|
8798
|
-
});
|
|
8799
|
-
}
|
|
8800
|
-
function isAbortError(err) {
|
|
8801
|
-
return !!err && typeof err === "object" && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
8802
|
-
}
|
|
8803
8767
|
const LAST_GOOD_PREFIX = "aegis_rail_lastgood:v1:";
|
|
8804
8768
|
const LAST_GOOD_SPECIFIC_PREFIX = "aegis_rail_lastgood_specific:v1:";
|
|
8805
8769
|
const POPULAR_PREFIX = "aegis_rail_popular:v1:";
|
|
@@ -8938,15 +8902,6 @@ function readRailFallback(ctx, now = Date.now(), audience = {}) {
|
|
|
8938
8902
|
if (popular.length > 0) return { tier: "popular", campaigns: popular };
|
|
8939
8903
|
return { tier: "hidden", campaigns: [] };
|
|
8940
8904
|
}
|
|
8941
|
-
function readAnonIdFromStorage$1() {
|
|
8942
|
-
if (typeof document === "undefined") return void 0;
|
|
8943
|
-
try {
|
|
8944
|
-
const storage = new Storage();
|
|
8945
|
-
return storage.get("anon_id") ?? void 0;
|
|
8946
|
-
} catch {
|
|
8947
|
-
return void 0;
|
|
8948
|
-
}
|
|
8949
|
-
}
|
|
8950
8905
|
function readAdClickIdsFromStorage() {
|
|
8951
8906
|
const out = {};
|
|
8952
8907
|
if (typeof document === "undefined") return out;
|
|
@@ -9061,6 +9016,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9061
9016
|
this.pendingAnchorRender = false;
|
|
9062
9017
|
this.slotsTornDown = false;
|
|
9063
9018
|
this.campaignsLoaded = false;
|
|
9019
|
+
this.activeETag = null;
|
|
9020
|
+
this.activeETagKey = void 0;
|
|
9064
9021
|
this.shellTimeout = null;
|
|
9065
9022
|
this.lifecycleGen = 0;
|
|
9066
9023
|
this.slotUnfilledBeaconed = /* @__PURE__ */ new Set();
|
|
@@ -9321,8 +9278,25 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9321
9278
|
}
|
|
9322
9279
|
/** The page context a `/v1/in-app/active` request is built from now. */
|
|
9323
9280
|
activeRequestKey() {
|
|
9324
|
-
|
|
9325
|
-
|
|
9281
|
+
return activeRequestKey(this.requestContext());
|
|
9282
|
+
}
|
|
9283
|
+
/** Everything the shared /active builder needs (inapp/active-request.ts):
|
|
9284
|
+
* the ONE place this manager's request is described. */
|
|
9285
|
+
requestContext() {
|
|
9286
|
+
return {
|
|
9287
|
+
apiHost: this.apiHost,
|
|
9288
|
+
writeKey: this.writeKey,
|
|
9289
|
+
userId: this.userId,
|
|
9290
|
+
contactId: this.contactId,
|
|
9291
|
+
contactToken: this.contactToken,
|
|
9292
|
+
organizationId: this.organizationId,
|
|
9293
|
+
propertyId: this.propertyId,
|
|
9294
|
+
surface: this.currentSurface,
|
|
9295
|
+
screen: this.currentScreen,
|
|
9296
|
+
locationId: this.currentLocationId,
|
|
9297
|
+
cartProductIds: this.currentCartProductIds,
|
|
9298
|
+
previewOnly: this.previewOnly
|
|
9299
|
+
};
|
|
9326
9300
|
}
|
|
9327
9301
|
/** The cart ids as a request-key part: sorted + deduped so a reorder is not a
|
|
9328
9302
|
* change; `-` = no cart known, distinct from `` = an empty cart. */
|
|
@@ -9345,7 +9319,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9345
9319
|
return out;
|
|
9346
9320
|
}
|
|
9347
9321
|
cartKeyPartOf(ids) {
|
|
9348
|
-
return ids
|
|
9322
|
+
return cartKeyPartOf(ids);
|
|
9349
9323
|
}
|
|
9350
9324
|
/**
|
|
9351
9325
|
* Qualifying-event refresh — schedule a debounced `refreshCampaigns()`
|
|
@@ -9668,75 +9642,57 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9668
9642
|
}
|
|
9669
9643
|
}, delay);
|
|
9670
9644
|
}
|
|
9671
|
-
|
|
9645
|
+
refreshCampaigns() {
|
|
9646
|
+
const key = this.activeRequestKey();
|
|
9647
|
+
if (this.inflightActive && this.inflightActive.key === key) {
|
|
9648
|
+
this.log("refreshCampaigns() — joining the in-flight /active for this page context");
|
|
9649
|
+
return this.inflightActive.promise;
|
|
9650
|
+
}
|
|
9651
|
+
const entry = { key, promise: Promise.resolve() };
|
|
9652
|
+
entry.promise = this.refreshCampaignsNow().finally(() => {
|
|
9653
|
+
if (this.inflightActive === entry) this.inflightActive = void 0;
|
|
9654
|
+
});
|
|
9655
|
+
this.inflightActive = entry;
|
|
9656
|
+
return entry.promise;
|
|
9657
|
+
}
|
|
9658
|
+
async refreshCampaignsNow() {
|
|
9672
9659
|
const gen = this.lifecycleGen;
|
|
9673
9660
|
let requestKey;
|
|
9674
9661
|
try {
|
|
9675
|
-
const
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
// `*placed=1*` / `*?step=cart*` rule still matches.
|
|
9679
|
-
page_url: typeof window !== "undefined" ? redactUrl(window.location.pathname + window.location.search) : "/"
|
|
9680
|
-
});
|
|
9681
|
-
context.set("is_new_user", isNewVisitor() ? "true" : "false");
|
|
9682
|
-
if (this.currentSurface) {
|
|
9683
|
-
context.set("current_surface", this.currentSurface);
|
|
9684
|
-
}
|
|
9685
|
-
if (this.currentScreen) {
|
|
9686
|
-
context.set("current_screen", this.currentScreen);
|
|
9687
|
-
}
|
|
9688
|
-
if (this.currentLocationId) {
|
|
9689
|
-
context.set("location_id", this.currentLocationId);
|
|
9690
|
-
}
|
|
9691
|
-
if (this.currentCartProductIds !== null) {
|
|
9692
|
-
context.set("cart_product_ids", this.currentCartProductIds.join(","));
|
|
9693
|
-
}
|
|
9694
|
-
const previewAsOf = previewAsOfToken();
|
|
9695
|
-
if (previewAsOf) {
|
|
9696
|
-
context.set("preview_as_of", previewAsOf);
|
|
9697
|
-
}
|
|
9698
|
-
if (this.previewOnly) {
|
|
9699
|
-
context.set("preview", "1");
|
|
9700
|
-
}
|
|
9701
|
-
const url = `${this.apiHost}/v1/in-app/active?${context.toString()}`;
|
|
9702
|
-
requestKey = this.activeRequestKey();
|
|
9662
|
+
const req = buildActiveRequest(this.requestContext());
|
|
9663
|
+
const url = req.url;
|
|
9664
|
+
requestKey = req.key;
|
|
9703
9665
|
this.lastActiveRequestKey = requestKey;
|
|
9704
9666
|
const shellCtx = this.shellContext();
|
|
9705
9667
|
const railAudience = this.railAudience();
|
|
9706
|
-
const
|
|
9707
|
-
|
|
9708
|
-
"
|
|
9709
|
-
}
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
}
|
|
9716
|
-
if (this.contactId && this.contactToken) {
|
|
9717
|
-
headers["X-Contact-Token"] = this.contactToken;
|
|
9718
|
-
}
|
|
9719
|
-
if (this.organizationId) {
|
|
9720
|
-
headers["X-Organization-ID"] = this.organizationId;
|
|
9721
|
-
}
|
|
9722
|
-
if (this.propertyId) {
|
|
9723
|
-
headers["X-Property-Id"] = this.propertyId;
|
|
9724
|
-
}
|
|
9725
|
-
const abAssignments = this.getABAssignments();
|
|
9726
|
-
if (Object.keys(abAssignments).length > 0) {
|
|
9727
|
-
headers["X-AB-Assignments"] = btoa(JSON.stringify(abAssignments));
|
|
9728
|
-
}
|
|
9729
|
-
const response = await fetchWithAbort(url, {
|
|
9668
|
+
const conditional = this.campaignsLoaded && this.activeETag !== null && this.activeETagKey === requestKey;
|
|
9669
|
+
if (conditional && this.activeETag) {
|
|
9670
|
+
req.headers["If-None-Match"] = this.activeETag;
|
|
9671
|
+
}
|
|
9672
|
+
const boot = takeActiveBoot(req);
|
|
9673
|
+
const adopted = this.campaignsLoaded ? null : boot;
|
|
9674
|
+
if (adopted) this.log("Adopting the early-boot /active read for this page");
|
|
9675
|
+
const fetchActive = this.campaignsLoaded ? fetchWithAbort : fetchWithAbortRetry;
|
|
9676
|
+
const response = adopted ? await adopted : await fetchActive(url, {
|
|
9730
9677
|
method: "GET",
|
|
9731
|
-
headers,
|
|
9678
|
+
headers: req.headers,
|
|
9732
9679
|
credentials: "include"
|
|
9733
9680
|
});
|
|
9734
9681
|
if (gen !== this.lifecycleGen) return;
|
|
9735
|
-
|
|
9736
|
-
|
|
9682
|
+
let payload;
|
|
9683
|
+
if (response.status === 304 && conditional) {
|
|
9684
|
+
this.log("Active campaigns unchanged (304)");
|
|
9685
|
+
payload = this.campaigns;
|
|
9686
|
+
} else {
|
|
9687
|
+
if (!response.ok) {
|
|
9688
|
+
throw new Error(`Failed to fetch campaigns: ${response.status}`);
|
|
9689
|
+
}
|
|
9690
|
+
payload = await response.json();
|
|
9691
|
+
if (gen !== this.lifecycleGen) return;
|
|
9692
|
+
const tag = response.headers && typeof response.headers.get === "function" ? response.headers.get("ETag") : null;
|
|
9693
|
+
this.activeETag = tag;
|
|
9694
|
+
this.activeETagKey = tag ? requestKey : void 0;
|
|
9737
9695
|
}
|
|
9738
|
-
const payload = await response.json();
|
|
9739
|
-
if (gen !== this.lifecycleGen) return;
|
|
9740
9696
|
this.campaigns = Array.isArray(payload) ? payload : [];
|
|
9741
9697
|
this.campaignsLoaded = true;
|
|
9742
9698
|
this.railFallbackTier = null;
|
|
@@ -9789,22 +9745,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9789
9745
|
}
|
|
9790
9746
|
// --- Client Context Helpers (Critical Fix B) ---
|
|
9791
9747
|
detectDeviceType() {
|
|
9792
|
-
|
|
9793
|
-
const ua = navigator.userAgent;
|
|
9794
|
-
if (/Mobi|Android/i.test(ua)) return "mobile";
|
|
9795
|
-
if (/iPad|Tablet/i.test(ua)) return "tablet";
|
|
9796
|
-
return "desktop";
|
|
9748
|
+
return detectDeviceType();
|
|
9797
9749
|
}
|
|
9798
9750
|
// --- A/B Assignment Persistence (Critical Fix C) ---
|
|
9799
9751
|
// Both A/B helpers sit on the campaign-fetch path, so blocked storage
|
|
9800
9752
|
// (where even `typeof localStorage` throws) must not abort the fetch.
|
|
9801
9753
|
getABAssignments() {
|
|
9802
|
-
|
|
9803
|
-
if (typeof localStorage === "undefined") return {};
|
|
9804
|
-
return JSON.parse(localStorage.getItem("aegis_ab_assignments") || "{}");
|
|
9805
|
-
} catch {
|
|
9806
|
-
return {};
|
|
9807
|
-
}
|
|
9754
|
+
return readABAssignments();
|
|
9808
9755
|
}
|
|
9809
9756
|
processABAssignments(campaigns) {
|
|
9810
9757
|
const stored = this.getABAssignments();
|
|
@@ -9934,8 +9881,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9934
9881
|
* as `page_url` (pathname + search, credential values redacted). Null off
|
|
9935
9882
|
* the browser — no page, no filter (the server's rule too). */
|
|
9936
9883
|
currentPageUrl() {
|
|
9937
|
-
|
|
9938
|
-
return redactUrl((window.location.pathname || "") + (window.location.search || ""));
|
|
9884
|
+
return currentPageUrl();
|
|
9939
9885
|
}
|
|
9940
9886
|
/** The full client placement gate: screen/surface tier AND page rules, both
|
|
9941
9887
|
* mirroring `/v1/in-app/active`, applied to CACHED campaigns (the page may
|
|
@@ -10905,6 +10851,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10905
10851
|
/**
|
|
10906
10852
|
* §7.13.I — embedded profile FORM. Renders one input per `form_fields` entry
|
|
10907
10853
|
* and, on submit, POSTs `{response_type:'form', payload:{fields:{key:value}}}`
|
|
10854
|
+
* (plus `marketing_consent: true` when the Q5 permission box was ticked)
|
|
10908
10855
|
* to `/in-app/responses` — the cell-plane enrichment writes the mapped answers
|
|
10909
10856
|
* back onto the contact. Keyed by each field's `key` so it matches the
|
|
10910
10857
|
* campaign's field→contact map.
|
|
@@ -11004,6 +10951,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11004
10951
|
wrap.appendChild(ctrl);
|
|
11005
10952
|
body.appendChild(wrap);
|
|
11006
10953
|
}
|
|
10954
|
+
const consentIc = campaign.interactive_config;
|
|
10955
|
+
let consentBox = null;
|
|
10956
|
+
if (asksMarketingConsent(consentIc)) {
|
|
10957
|
+
const consent = renderMarketingConsentRow(marketingConsentLabel(), text, campaign.id);
|
|
10958
|
+
consentBox = consent.input;
|
|
10959
|
+
body.appendChild(consent.row);
|
|
10960
|
+
}
|
|
11007
10961
|
const submit = document.createElement("button");
|
|
11008
10962
|
const _cAny = campaign;
|
|
11009
10963
|
submit.textContent = typeof _cAny.button_text === "string" && _cAny.button_text || "Save";
|
|
@@ -11021,7 +10975,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11021
10975
|
if (v) collected[key] = v;
|
|
11022
10976
|
}
|
|
11023
10977
|
if (!ok || Object.keys(collected).length === 0) return;
|
|
11024
|
-
void this.submitFormResponse(campaign, collected);
|
|
10978
|
+
void this.submitFormResponse(campaign, collected, (consentBox == null ? void 0 : consentBox.checked) === true);
|
|
11025
10979
|
void this.trackEvent(campaign.id, "clicked", { meta: { fields: Object.keys(collected) } });
|
|
11026
10980
|
while (body.firstChild) body.removeChild(body.firstChild);
|
|
11027
10981
|
const modalEl = body.parentElement;
|
|
@@ -11047,7 +11001,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11047
11001
|
}
|
|
11048
11002
|
/** POST a form response to /in-app/responses (gateway → cell-plane). The
|
|
11049
11003
|
* cell-plane enriches the contact from the campaign's field-map. Best-effort. */
|
|
11050
|
-
async submitFormResponse(campaign, fields) {
|
|
11004
|
+
async submitFormResponse(campaign, fields, marketingConsent = false) {
|
|
11051
11005
|
if (this.previewOnly) return;
|
|
11052
11006
|
if (!this.organizationId) {
|
|
11053
11007
|
this.log("submitFormResponse: no organizationId — cannot submit", "warn");
|
|
@@ -11077,7 +11031,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11077
11031
|
variant_id: variantId,
|
|
11078
11032
|
platform: "web",
|
|
11079
11033
|
ad_click_ids: readAdClickIdsFromStorage(),
|
|
11080
|
-
|
|
11034
|
+
// `{fields}` + `marketing_consent: true` only when the Q5 box was
|
|
11035
|
+
// ticked (marketing-consent.ts); unticked sends no key.
|
|
11036
|
+
payload: formPayload(fields, marketingConsent)
|
|
11081
11037
|
})
|
|
11082
11038
|
});
|
|
11083
11039
|
if (!res.ok) this.log(`submitFormResponse failed (${res.status})`, "warn");
|
|
@@ -15584,6 +15540,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
15584
15540
|
this.removeShells({ sdkOnly: true });
|
|
15585
15541
|
this.campaignsLoaded = false;
|
|
15586
15542
|
this.campaignsRequestKey = void 0;
|
|
15543
|
+
this.inflightActive = void 0;
|
|
15544
|
+
this.activeETag = null;
|
|
15545
|
+
this.activeETagKey = void 0;
|
|
15587
15546
|
if (typeof document !== "undefined") {
|
|
15588
15547
|
document.querySelectorAll(
|
|
15589
15548
|
".aegis-in-app-banner, .aegis-in-app-modal-overlay, .aegis-in-app-fullscreen-overlay, .aegis-in-app-half-interstitial-overlay, .aegis-in-app-alert-overlay, .aegis-in-app-pip, .aegis-in-app-nps-overlay, .aegis-in-app-countdown-overlay, .aegis-in-app-rating-overlay, .aegis-in-app-poll-overlay, .aegis-in-app-quiz-overlay, .aegis-in-app-rating-card, .aegis-in-app-nps-card"
|
|
@@ -15606,19 +15565,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
15606
15565
|
};
|
|
15607
15566
|
_AegisInAppManager.CONVERSION_STORAGE_PREFIX = "aegis_conv_";
|
|
15608
15567
|
_AegisInAppManager.REFRESH_DEBOUNCE_MS = 300;
|
|
15609
|
-
_AegisInAppManager.KNOWN_SURFACES =
|
|
15610
|
-
"bill",
|
|
15611
|
-
"storefront_catalog",
|
|
15612
|
-
"storefront_rewards",
|
|
15613
|
-
"storefront_feedback",
|
|
15614
|
-
"storefront_reviews",
|
|
15615
|
-
"storefront_members",
|
|
15616
|
-
"storefront_orders",
|
|
15617
|
-
"storefront_account",
|
|
15618
|
-
"storefront_referrals",
|
|
15619
|
-
"external_website",
|
|
15620
|
-
"external_mobile_screen"
|
|
15621
|
-
]);
|
|
15568
|
+
_AegisInAppManager.KNOWN_SURFACES = KNOWN_SURFACES;
|
|
15622
15569
|
_AegisInAppManager.SERVED_DEDUP_PREFIX = "aegis_served_fired:";
|
|
15623
15570
|
_AegisInAppManager.SHELL_TIMEOUT_MS = 1e4;
|
|
15624
15571
|
_AegisInAppManager.JOURNEY_ACK_RETRY_MS = 2e3;
|
|
@@ -16384,7 +16331,8 @@ class PrefetchBundleClient {
|
|
|
16384
16331
|
}
|
|
16385
16332
|
let response;
|
|
16386
16333
|
try {
|
|
16387
|
-
|
|
16334
|
+
const fetchBundle = this.currentBundle ? fetchWithAbort : fetchWithAbortRetry;
|
|
16335
|
+
response = await fetchBundle(url, { method: "GET", headers, cache: "no-cache" });
|
|
16388
16336
|
} catch (err) {
|
|
16389
16337
|
logger.warn("prefetch-bundle fetch network error:", err);
|
|
16390
16338
|
return this.currentBundle;
|
|
@@ -16766,6 +16714,8 @@ class AegisWidgetManager {
|
|
|
16766
16714
|
this.isInitialized = false;
|
|
16767
16715
|
this.isDestroyed = false;
|
|
16768
16716
|
this.prefetchWidgetConfigs = {};
|
|
16717
|
+
this.widgetsLoaded = false;
|
|
16718
|
+
this.prefetchConfigsLoaded = false;
|
|
16769
16719
|
this.writeKey = config.writeKey;
|
|
16770
16720
|
this.apiHost = config.apiHost || "https://api.aegis.ai";
|
|
16771
16721
|
this.userId = config.userId ?? readAnonIdFromStorage();
|
|
@@ -16992,11 +16942,13 @@ class AegisWidgetManager {
|
|
|
16992
16942
|
if (this.contactId) headers["X-Contact-ID"] = this.contactId;
|
|
16993
16943
|
if (this.contactId && this.contactToken) headers["X-Contact-Token"] = this.contactToken;
|
|
16994
16944
|
if (this.organizationId) headers["X-Organization-ID"] = this.organizationId;
|
|
16995
|
-
const
|
|
16945
|
+
const fetchConfigs = this.prefetchConfigsLoaded ? fetchWithAbort : fetchWithAbortRetry;
|
|
16946
|
+
const response = await fetchConfigs(url, { headers, credentials: "include" });
|
|
16996
16947
|
if (!response.ok) {
|
|
16997
16948
|
throw new Error(`Failed to fetch prefetch configs: ${response.status}`);
|
|
16998
16949
|
}
|
|
16999
16950
|
this.prefetchWidgetConfigs = await response.json();
|
|
16951
|
+
this.prefetchConfigsLoaded = true;
|
|
17000
16952
|
const elapsed = performance.now() - startTime;
|
|
17001
16953
|
this.log(`Fetched prefetch widget configs in ${elapsed.toFixed(2)}ms`);
|
|
17002
16954
|
} catch (error) {
|
|
@@ -17016,11 +16968,13 @@ class AegisWidgetManager {
|
|
|
17016
16968
|
if (this.contactId && this.contactToken) headers["X-Contact-Token"] = this.contactToken;
|
|
17017
16969
|
if (this.organizationId) headers["X-Organization-ID"] = this.organizationId;
|
|
17018
16970
|
if (this.sourcePlatform) headers["X-Source-Platform"] = this.sourcePlatform;
|
|
17019
|
-
const
|
|
16971
|
+
const fetchConfig = this.widgetsLoaded ? fetchWithAbort : fetchWithAbortRetry;
|
|
16972
|
+
const response = await fetchConfig(url, { headers, credentials: "include" });
|
|
17020
16973
|
if (!response.ok) {
|
|
17021
16974
|
throw new Error(`Failed to fetch widgets: ${response.status}`);
|
|
17022
16975
|
}
|
|
17023
16976
|
this.widgets = await response.json();
|
|
16977
|
+
this.widgetsLoaded = true;
|
|
17024
16978
|
this.log(`Fetched ${this.widgets.length} widgets`);
|
|
17025
16979
|
} catch (error) {
|
|
17026
16980
|
this.log(`Error fetching widgets: ${error}`, true);
|
|
@@ -17146,7 +17100,10 @@ class AegisWidgetManager {
|
|
|
17146
17100
|
return;
|
|
17147
17101
|
}
|
|
17148
17102
|
const beaconData = {
|
|
17149
|
-
|
|
17103
|
+
// PL-9 (2026-11-20): never a 'default' tenant. The cell takes the WRITE
|
|
17104
|
+
// KEY's org and refuses (403) a body org that differs, so the field is
|
|
17105
|
+
// sent only when the SDK was configured with its org.
|
|
17106
|
+
...this.organizationId ? { organization_id: this.organizationId } : {},
|
|
17150
17107
|
contact_id: this.contactId,
|
|
17151
17108
|
cart_id: this.cartData.cart_id,
|
|
17152
17109
|
cart_total: this.cartData.cart_total,
|
|
@@ -18242,7 +18199,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
18242
18199
|
this.initialized = false;
|
|
18243
18200
|
this.armedInAppTriggers = /* @__PURE__ */ new Set();
|
|
18244
18201
|
{
|
|
18245
|
-
const v = "1.
|
|
18202
|
+
const v = "1.54.0";
|
|
18246
18203
|
try {
|
|
18247
18204
|
globalThis.__AEGIS_SDK_VERSION__ = v;
|
|
18248
18205
|
} catch {
|
|
@@ -18674,7 +18631,7 @@ async function bootstrap(apiHost, req) {
|
|
|
18674
18631
|
const url = `${apiHost.replace(/\/$/, "")}/v1/sdk/bootstrap`;
|
|
18675
18632
|
const doFetch = async () => {
|
|
18676
18633
|
try {
|
|
18677
|
-
return await
|
|
18634
|
+
return await fetchWithAbortRetry(url, {
|
|
18678
18635
|
method: "POST",
|
|
18679
18636
|
headers: { "Content-Type": "application/json" },
|
|
18680
18637
|
body: JSON.stringify(body),
|
|
@@ -18687,13 +18644,7 @@ async function bootstrap(apiHost, req) {
|
|
|
18687
18644
|
throw err;
|
|
18688
18645
|
}
|
|
18689
18646
|
};
|
|
18690
|
-
let resp;
|
|
18691
|
-
try {
|
|
18692
|
-
resp = await doFetch();
|
|
18693
|
-
} catch (err) {
|
|
18694
|
-
if (!(err instanceof BootstrapError) || err.status !== 0) throw err;
|
|
18695
|
-
resp = await doFetch();
|
|
18696
|
-
}
|
|
18647
|
+
let resp = await doFetch();
|
|
18697
18648
|
if (resp.status >= 500) {
|
|
18698
18649
|
await new Promise((r) => setTimeout(r, 750));
|
|
18699
18650
|
resp = await doFetch();
|