@active-reach/web-sdk 1.35.0 → 1.35.2
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/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-CCDZCnut.mjs → analytics-ZwrwqCTJ.mjs} +2 -2
- package/dist/{analytics-CCDZCnut.mjs.map → analytics-ZwrwqCTJ.mjs.map} +1 -1
- package/dist/core/analytics.d.ts +1 -1
- package/dist/inapp/AegisInAppManager.d.ts +0 -5
- package/dist/inapp/AegisInAppManager.d.ts.map +1 -1
- package/dist/inapp/renderers/card-template.d.ts +22 -1
- package/dist/inapp/renderers/card-template.d.ts.map +1 -1
- package/dist/inapp/renderers/index.d.ts +0 -2
- package/dist/inapp/renderers/index.d.ts.map +1 -1
- package/dist/inapp/renderers/types.d.ts +15 -0
- package/dist/inapp/renderers/types.d.ts.map +1 -1
- package/dist/index.js +367 -247
- package/dist/index.js.map +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/inapp/renderers/product-rating.d.ts +0 -40
- package/dist/inapp/renderers/product-rating.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Storage, l as logger, A as Aegis } from "./analytics-
|
|
2
|
-
import { B, E, N, R, U, m } from "./analytics-
|
|
1
|
+
import { S as Storage, l as logger, A as Aegis } from "./analytics-ZwrwqCTJ.mjs";
|
|
2
|
+
import { B, E, N, R, U, m } from "./analytics-ZwrwqCTJ.mjs";
|
|
3
3
|
import { AegisWebPush } from "./push/AegisWebPush.js";
|
|
4
4
|
function debounce(func, wait) {
|
|
5
5
|
let timeoutId = null;
|
|
@@ -753,6 +753,296 @@ function buildRatingInputElement(el2, ctx, fg) {
|
|
|
753
753
|
wrap.appendChild(row);
|
|
754
754
|
return wrap;
|
|
755
755
|
}
|
|
756
|
+
function starRow(scale, onPick) {
|
|
757
|
+
const row = document.createElement("div");
|
|
758
|
+
row.style.cssText = "display:flex;gap:2px;flex-shrink:0;";
|
|
759
|
+
const stars2 = [];
|
|
760
|
+
let picked = 0;
|
|
761
|
+
const paint = (upto) => {
|
|
762
|
+
stars2.forEach((s, idx) => {
|
|
763
|
+
const on = idx < upto;
|
|
764
|
+
s.setAttribute("stroke", on ? "#f59e0b" : "#d1d5db");
|
|
765
|
+
s.setAttribute("fill", on ? "#f59e0b" : "none");
|
|
766
|
+
});
|
|
767
|
+
};
|
|
768
|
+
for (let i = 1; i <= scale; i++) {
|
|
769
|
+
const btn = document.createElement("button");
|
|
770
|
+
btn.type = "button";
|
|
771
|
+
btn.setAttribute("aria-label", `${i} star${i > 1 ? "s" : ""}`);
|
|
772
|
+
btn.style.cssText = "cursor:pointer;border:none;background:none;padding:1px;line-height:0;";
|
|
773
|
+
const svg = lucideSvgEl("star", { size: 22, color: "#d1d5db" });
|
|
774
|
+
if (svg) {
|
|
775
|
+
btn.appendChild(svg);
|
|
776
|
+
stars2.push(svg);
|
|
777
|
+
}
|
|
778
|
+
btn.addEventListener("mouseenter", () => paint(i));
|
|
779
|
+
btn.addEventListener("mouseleave", () => paint(picked));
|
|
780
|
+
btn.addEventListener("click", () => {
|
|
781
|
+
picked = i;
|
|
782
|
+
paint(i);
|
|
783
|
+
onPick(i);
|
|
784
|
+
});
|
|
785
|
+
row.appendChild(btn);
|
|
786
|
+
}
|
|
787
|
+
return row;
|
|
788
|
+
}
|
|
789
|
+
function ratingThumb(it, accent) {
|
|
790
|
+
const box = document.createElement("div");
|
|
791
|
+
box.style.cssText = `width:40px;height:40px;flex-shrink:0;border-radius:8px;overflow:hidden;background:${accent}1f;display:flex;align-items:center;justify-content:center;`;
|
|
792
|
+
if (it.image_url) {
|
|
793
|
+
const img = document.createElement("img");
|
|
794
|
+
img.src = it.image_url;
|
|
795
|
+
img.alt = it.name || "";
|
|
796
|
+
img.loading = "lazy";
|
|
797
|
+
img.style.cssText = "width:100%;height:100%;object-fit:cover;";
|
|
798
|
+
box.appendChild(img);
|
|
799
|
+
} else {
|
|
800
|
+
const mono = document.createElement("span");
|
|
801
|
+
mono.textContent = (it.name || "?").slice(0, 1).toUpperCase();
|
|
802
|
+
mono.style.cssText = `font-size:16px;font-weight:700;color:${accent};`;
|
|
803
|
+
box.appendChild(mono);
|
|
804
|
+
}
|
|
805
|
+
return box;
|
|
806
|
+
}
|
|
807
|
+
function buildProductRatingListElement(el2, ctx, fg) {
|
|
808
|
+
const wrap = document.createElement("div");
|
|
809
|
+
wrap.style.cssText = "display:flex;flex-direction:column;gap:10px;margin:2px 0;";
|
|
810
|
+
const slot = ctx.slotEl;
|
|
811
|
+
if (!slot) return wrap;
|
|
812
|
+
const accent = ctx.sanitizeColor(
|
|
813
|
+
slot.getAttribute("data-accent") || ctx.campaign.background_color || "#4169e1"
|
|
814
|
+
);
|
|
815
|
+
const orderId = slot.getAttribute("data-order-id");
|
|
816
|
+
const billCode = slot.getAttribute("data-bill-code");
|
|
817
|
+
const token = slot.getAttribute("data-token");
|
|
818
|
+
const reviewsUrl = slot.getAttribute("data-reviews-url") || el2.rating_high_url || null;
|
|
819
|
+
const scale = typeof el2.rating_scale === "number" && el2.rating_scale >= 2 && el2.rating_scale <= 10 ? Math.floor(el2.rating_scale) : 5;
|
|
820
|
+
const showThumb = el2.show_thumbnail !== false && el2.rating_layout !== "compact";
|
|
821
|
+
const scores = {};
|
|
822
|
+
const allowText = el2.allow_review_text === true;
|
|
823
|
+
const canUpload = !!(ctx.apiHost && ctx.writeKey && ctx.organizationId);
|
|
824
|
+
const allowMedia = el2.allow_review_media === true && canUpload;
|
|
825
|
+
let reviewText = "";
|
|
826
|
+
const mediaUrls = [];
|
|
827
|
+
const fileToB64 = (file) => new Promise((resolve, reject) => {
|
|
828
|
+
const r = new FileReader();
|
|
829
|
+
r.onload = () => {
|
|
830
|
+
const s = String(r.result || "");
|
|
831
|
+
resolve(s.includes(",") ? s.split(",")[1] : s);
|
|
832
|
+
};
|
|
833
|
+
r.onerror = () => reject(r.error);
|
|
834
|
+
r.readAsDataURL(file);
|
|
835
|
+
});
|
|
836
|
+
const uploadOne = async (file) => {
|
|
837
|
+
if (!ctx.apiHost || !ctx.writeKey || !ctx.organizationId) return null;
|
|
838
|
+
try {
|
|
839
|
+
const data = await fileToB64(file);
|
|
840
|
+
const res = await fetch(`${ctx.apiHost}/v1/in-app/review-media`, {
|
|
841
|
+
method: "POST",
|
|
842
|
+
headers: {
|
|
843
|
+
"Content-Type": "application/json",
|
|
844
|
+
"X-Aegis-Write-Key": ctx.writeKey,
|
|
845
|
+
"X-Organization-ID": ctx.organizationId
|
|
846
|
+
},
|
|
847
|
+
body: JSON.stringify({ data, content_type: file.type })
|
|
848
|
+
});
|
|
849
|
+
if (!res.ok) return null;
|
|
850
|
+
const j = await res.json();
|
|
851
|
+
return j.url ? { url: j.url, type: j.type === "video" ? "video" : "image" } : null;
|
|
852
|
+
} catch {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
const buildComposer = () => {
|
|
857
|
+
const box = document.createElement("div");
|
|
858
|
+
box.style.cssText = "display:flex;flex-direction:column;gap:8px;margin-top:2px;";
|
|
859
|
+
const toggle = document.createElement("button");
|
|
860
|
+
toggle.type = "button";
|
|
861
|
+
toggle.textContent = allowMedia ? "+ Add a written review & photos" : "+ Add a written review";
|
|
862
|
+
toggle.style.cssText = `align-self:flex-start;border:none;background:none;cursor:pointer;color:${accent};font-size:13px;font-weight:700;padding:2px 0;`;
|
|
863
|
+
const panel = document.createElement("div");
|
|
864
|
+
panel.style.cssText = "display:none;flex-direction:column;gap:8px;";
|
|
865
|
+
toggle.addEventListener("click", () => {
|
|
866
|
+
panel.style.display = "flex";
|
|
867
|
+
toggle.style.display = "none";
|
|
868
|
+
});
|
|
869
|
+
if (typeof el2.review_earn_hint === "string" && el2.review_earn_hint.trim()) {
|
|
870
|
+
const hint = document.createElement("div");
|
|
871
|
+
hint.textContent = el2.review_earn_hint.trim();
|
|
872
|
+
hint.style.cssText = `font-size:11px;color:${fg};opacity:.65;`;
|
|
873
|
+
panel.appendChild(hint);
|
|
874
|
+
}
|
|
875
|
+
if (allowText) {
|
|
876
|
+
const ta = document.createElement("textarea");
|
|
877
|
+
ta.placeholder = "Tell us more (optional)";
|
|
878
|
+
ta.rows = 3;
|
|
879
|
+
ta.style.cssText = `width:100%;box-sizing:border-box;border:1px solid #e5e7eb;border-radius:10px;padding:8px 10px;font-size:13px;color:${fg};font-family:inherit;resize:vertical;`;
|
|
880
|
+
ta.addEventListener("input", () => {
|
|
881
|
+
reviewText = ta.value;
|
|
882
|
+
});
|
|
883
|
+
panel.appendChild(ta);
|
|
884
|
+
}
|
|
885
|
+
if (allowMedia) {
|
|
886
|
+
const strip = document.createElement("div");
|
|
887
|
+
strip.style.cssText = "display:flex;gap:8px;flex-wrap:wrap;align-items:center;";
|
|
888
|
+
const input = document.createElement("input");
|
|
889
|
+
input.type = "file";
|
|
890
|
+
input.accept = "image/*,video/*";
|
|
891
|
+
input.multiple = true;
|
|
892
|
+
input.style.cssText = "display:none;";
|
|
893
|
+
const addTile = document.createElement("button");
|
|
894
|
+
addTile.type = "button";
|
|
895
|
+
addTile.setAttribute("aria-label", "Add photo or video");
|
|
896
|
+
addTile.style.cssText = `width:48px;height:48px;flex-shrink:0;border:1px dashed ${accent};border-radius:10px;background:${accent}14;color:${accent};cursor:pointer;display:flex;align-items:center;justify-content:center;`;
|
|
897
|
+
const plus = lucideSvgEl("plus", { size: 22, color: accent });
|
|
898
|
+
if (plus) addTile.appendChild(plus);
|
|
899
|
+
addTile.addEventListener("click", () => input.click());
|
|
900
|
+
input.addEventListener("change", () => {
|
|
901
|
+
const files = Array.from(input.files || []);
|
|
902
|
+
input.value = "";
|
|
903
|
+
files.forEach((f) => {
|
|
904
|
+
if (mediaUrls.length >= 6) return;
|
|
905
|
+
const thumb = document.createElement("div");
|
|
906
|
+
thumb.style.cssText = "width:48px;height:48px;flex-shrink:0;border-radius:10px;background:#f3f4f6;display:flex;align-items:center;justify-content:center;overflow:hidden;font-size:11px;color:#9ca3af;";
|
|
907
|
+
thumb.textContent = "…";
|
|
908
|
+
strip.insertBefore(thumb, addTile);
|
|
909
|
+
void uploadOne(f).then((up) => {
|
|
910
|
+
if (!up) {
|
|
911
|
+
thumb.textContent = "!";
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
mediaUrls.push(up);
|
|
915
|
+
thumb.textContent = "";
|
|
916
|
+
if (up.type === "video") {
|
|
917
|
+
const vid = lucideSvgEl("play", { size: 20, color: "#6b7280" });
|
|
918
|
+
if (vid) thumb.appendChild(vid);
|
|
919
|
+
} else {
|
|
920
|
+
const img = document.createElement("img");
|
|
921
|
+
img.src = up.url;
|
|
922
|
+
img.style.cssText = "width:100%;height:100%;object-fit:cover;";
|
|
923
|
+
thumb.appendChild(img);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
strip.appendChild(addTile);
|
|
929
|
+
strip.appendChild(input);
|
|
930
|
+
panel.appendChild(strip);
|
|
931
|
+
}
|
|
932
|
+
box.appendChild(toggle);
|
|
933
|
+
box.appendChild(panel);
|
|
934
|
+
return box;
|
|
935
|
+
};
|
|
936
|
+
const submitBtn = document.createElement("button");
|
|
937
|
+
submitBtn.type = "button";
|
|
938
|
+
submitBtn.textContent = "Submit ratings";
|
|
939
|
+
submitBtn.style.cssText = `margin-top:2px;width:100%;border:0;border-radius:999px;background:${accent};color:#fff;font-size:14px;font-weight:700;padding:10px 16px;cursor:pointer;opacity:.5;pointer-events:none;`;
|
|
940
|
+
const refreshSubmit = () => {
|
|
941
|
+
const has = Object.keys(scores).length > 0;
|
|
942
|
+
submitBtn.style.opacity = has ? "1" : ".5";
|
|
943
|
+
submitBtn.style.pointerEvents = has ? "auto" : "none";
|
|
944
|
+
};
|
|
945
|
+
const done = (branch) => {
|
|
946
|
+
var _a;
|
|
947
|
+
wrap.innerHTML = "";
|
|
948
|
+
const ack = document.createElement("div");
|
|
949
|
+
ack.style.cssText = "text-align:center;padding:8px 0;";
|
|
950
|
+
const t = document.createElement("p");
|
|
951
|
+
t.textContent = typeof el2.thanks_text === "string" && el2.thanks_text.trim() ? el2.thanks_text : "Thanks for rating your items!";
|
|
952
|
+
t.style.cssText = `margin:0;font-size:14px;font-weight:700;color:${fg};`;
|
|
953
|
+
ack.appendChild(t);
|
|
954
|
+
if (branch === "positive" && reviewsUrl) {
|
|
955
|
+
const a = document.createElement("a");
|
|
956
|
+
a.href = ctx.sanitizeUrl(reviewsUrl) || "#";
|
|
957
|
+
a.textContent = el2.rating_high_cta || "Share a review";
|
|
958
|
+
a.style.cssText = `display:inline-block;margin-top:6px;font-size:12px;font-weight:700;color:${accent};text-decoration:none;`;
|
|
959
|
+
ack.appendChild(a);
|
|
960
|
+
}
|
|
961
|
+
wrap.appendChild(ack);
|
|
962
|
+
(_a = ctx.playReaction) == null ? void 0 : _a.call(ctx, wrap, branch === "positive" ? "affirm" : "acknowledge");
|
|
963
|
+
};
|
|
964
|
+
let submitting = false;
|
|
965
|
+
submitBtn.addEventListener("click", () => {
|
|
966
|
+
var _a;
|
|
967
|
+
const rated = Object.keys(scores);
|
|
968
|
+
if (submitting || rated.length === 0) return;
|
|
969
|
+
submitting = true;
|
|
970
|
+
submitBtn.disabled = true;
|
|
971
|
+
submitBtn.style.opacity = ".6";
|
|
972
|
+
submitBtn.textContent = "Saving…";
|
|
973
|
+
ctx.trackEvent(ctx.campaign.id, "clicked", { meta: { element: "product_rating_list", items: rated.length } });
|
|
974
|
+
Promise.resolve(
|
|
975
|
+
(_a = ctx.submitResponse) == null ? void 0 : _a.call(ctx, "rating", {
|
|
976
|
+
items: rated.map((pid) => ({ product_id: pid, score: scores[pid] })),
|
|
977
|
+
order_id: orderId,
|
|
978
|
+
bill_code: billCode,
|
|
979
|
+
token,
|
|
980
|
+
...reviewText.trim() ? { review_text: reviewText.trim() } : {},
|
|
981
|
+
...mediaUrls.length ? { media_urls: mediaUrls } : {}
|
|
982
|
+
})
|
|
983
|
+
).then((res) => {
|
|
984
|
+
var _a2;
|
|
985
|
+
const branch = ((_a2 = res == null ? void 0 : res.rating_result) == null ? void 0 : _a2.branch) || "positive";
|
|
986
|
+
done(branch);
|
|
987
|
+
}).catch(() => {
|
|
988
|
+
submitting = false;
|
|
989
|
+
submitBtn.disabled = false;
|
|
990
|
+
submitBtn.style.opacity = "1";
|
|
991
|
+
submitBtn.textContent = "Submit ratings";
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
const render = (items) => {
|
|
995
|
+
wrap.innerHTML = "";
|
|
996
|
+
const clean = (items || []).filter((it) => it && it.product_id);
|
|
997
|
+
if (clean.length === 0) return;
|
|
998
|
+
const list = document.createElement("div");
|
|
999
|
+
list.style.cssText = "display:flex;flex-direction:column;gap:10px;";
|
|
1000
|
+
clean.forEach((it) => {
|
|
1001
|
+
const rowEl = document.createElement("div");
|
|
1002
|
+
rowEl.style.cssText = "display:flex;align-items:center;gap:10px;";
|
|
1003
|
+
if (showThumb) rowEl.appendChild(ratingThumb(it, accent));
|
|
1004
|
+
const nameEl = document.createElement("span");
|
|
1005
|
+
nameEl.textContent = it.name || it.product_id;
|
|
1006
|
+
nameEl.style.cssText = `flex:1;min-width:0;font-size:13px;color:${fg};overflow:hidden;text-overflow:ellipsis;white-space:nowrap;`;
|
|
1007
|
+
rowEl.appendChild(nameEl);
|
|
1008
|
+
rowEl.appendChild(starRow(scale, (n) => {
|
|
1009
|
+
scores[it.product_id] = n;
|
|
1010
|
+
refreshSubmit();
|
|
1011
|
+
}));
|
|
1012
|
+
list.appendChild(rowEl);
|
|
1013
|
+
});
|
|
1014
|
+
wrap.appendChild(list);
|
|
1015
|
+
if (allowText || allowMedia) wrap.appendChild(buildComposer());
|
|
1016
|
+
wrap.appendChild(submitBtn);
|
|
1017
|
+
};
|
|
1018
|
+
const rawAttr = slot.getAttribute("data-rateable-items");
|
|
1019
|
+
if (rawAttr) {
|
|
1020
|
+
try {
|
|
1021
|
+
const parsed = JSON.parse(rawAttr);
|
|
1022
|
+
render(Array.isArray(parsed) ? parsed : []);
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1025
|
+
} else if (token && ctx.apiHost && ctx.writeKey) {
|
|
1026
|
+
const loader = document.createElement("div");
|
|
1027
|
+
loader.textContent = "Loading your items…";
|
|
1028
|
+
loader.style.cssText = `font-size:13px;color:${fg};opacity:.6;padding:6px 0;`;
|
|
1029
|
+
wrap.appendChild(loader);
|
|
1030
|
+
const url = `${ctx.apiHost}/v1/in-app/rateable-items?token=${encodeURIComponent(token)}`;
|
|
1031
|
+
const ac = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
1032
|
+
if (ac) setTimeout(() => {
|
|
1033
|
+
try {
|
|
1034
|
+
ac.abort();
|
|
1035
|
+
} catch {
|
|
1036
|
+
}
|
|
1037
|
+
}, 6e3);
|
|
1038
|
+
fetch(url, { headers: { "X-Aegis-Write-Key": ctx.writeKey }, signal: ac == null ? void 0 : ac.signal }).then((r) => r.ok ? r.json() : null).then((data) => {
|
|
1039
|
+
render(Array.isArray(data == null ? void 0 : data.items) ? data.items : []);
|
|
1040
|
+
}).catch(() => {
|
|
1041
|
+
wrap.innerHTML = "";
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
return wrap;
|
|
1045
|
+
}
|
|
756
1046
|
function appendThanks(wrap, el2, fg, fallback) {
|
|
757
1047
|
const msg = typeof el2.thanks_text === "string" && el2.thanks_text.trim() ? el2.thanks_text : fallback;
|
|
758
1048
|
if (!msg) return;
|
|
@@ -1233,6 +1523,10 @@ function renderCardFromTemplate(card, opts) {
|
|
|
1233
1523
|
container.appendChild(buildNpsElement(el2, ctx, fg, brand, muted));
|
|
1234
1524
|
break;
|
|
1235
1525
|
}
|
|
1526
|
+
case "product_rating_list": {
|
|
1527
|
+
container.appendChild(buildProductRatingListElement(el2, ctx, fg));
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1236
1530
|
case "group": {
|
|
1237
1531
|
const g = document.createElement("div");
|
|
1238
1532
|
const gdir = el2.layout === "row" ? "row" : "column";
|
|
@@ -5027,7 +5321,7 @@ function disposeActiveWebChat() {
|
|
|
5027
5321
|
activeInstance = null;
|
|
5028
5322
|
}
|
|
5029
5323
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
5030
|
-
function el
|
|
5324
|
+
function el(tag, css, text) {
|
|
5031
5325
|
const e = document.createElement(tag);
|
|
5032
5326
|
if (css) e.style.cssText = css;
|
|
5033
5327
|
if (text != null) e.textContent = text;
|
|
@@ -5048,13 +5342,13 @@ function star(filled, size) {
|
|
|
5048
5342
|
return svg;
|
|
5049
5343
|
}
|
|
5050
5344
|
function stars(rating, size = 15) {
|
|
5051
|
-
const wrap = el
|
|
5345
|
+
const wrap = el("span", "display:inline-flex;gap:2px;vertical-align:middle;");
|
|
5052
5346
|
wrap.setAttribute("aria-label", `${rating} out of 5`);
|
|
5053
5347
|
for (let i = 1; i <= 5; i++) wrap.appendChild(star(i <= rating, size));
|
|
5054
5348
|
return wrap;
|
|
5055
5349
|
}
|
|
5056
5350
|
function verifiedBadge() {
|
|
5057
|
-
const b = el
|
|
5351
|
+
const b = el(
|
|
5058
5352
|
"span",
|
|
5059
5353
|
"display:inline-flex;align-items:center;gap:3px;font-size:12px;font-weight:600;color:#059669;"
|
|
5060
5354
|
);
|
|
@@ -5071,12 +5365,12 @@ function verifiedBadge() {
|
|
|
5071
5365
|
p.setAttribute("stroke-linejoin", "round");
|
|
5072
5366
|
svg.appendChild(p);
|
|
5073
5367
|
b.appendChild(svg);
|
|
5074
|
-
b.appendChild(el
|
|
5368
|
+
b.appendChild(el("span", "", "Verified purchase"));
|
|
5075
5369
|
return b;
|
|
5076
5370
|
}
|
|
5077
5371
|
function avatar(name, accent) {
|
|
5078
5372
|
const initial = (name.trim()[0] || "?").toUpperCase();
|
|
5079
|
-
const a = el
|
|
5373
|
+
const a = el(
|
|
5080
5374
|
"span",
|
|
5081
5375
|
`flex:0 0 auto;width:34px;height:34px;border-radius:999px;display:inline-flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:${accent};background:${accent}1a;`,
|
|
5082
5376
|
initial
|
|
@@ -5084,7 +5378,7 @@ function avatar(name, accent) {
|
|
|
5084
5378
|
return a;
|
|
5085
5379
|
}
|
|
5086
5380
|
function thumbBtn(up, count, reviewId, creds) {
|
|
5087
|
-
const btn = el
|
|
5381
|
+
const btn = el(
|
|
5088
5382
|
"button",
|
|
5089
5383
|
"display:inline-flex;align-items:center;gap:5px;font-size:13px;color:#6b7280;background:none;border:none;cursor:pointer;padding:4px 6px;border-radius:8px;font-family:inherit;"
|
|
5090
5384
|
);
|
|
@@ -5101,7 +5395,7 @@ function thumbBtn(up, count, reviewId, creds) {
|
|
|
5101
5395
|
p.setAttribute("fill", "currentColor");
|
|
5102
5396
|
svg.appendChild(p);
|
|
5103
5397
|
btn.appendChild(svg);
|
|
5104
|
-
const c = el
|
|
5398
|
+
const c = el("span", "", String(count));
|
|
5105
5399
|
btn.appendChild(c);
|
|
5106
5400
|
const key = `aegis_rv_voted_${reviewId}`;
|
|
5107
5401
|
let voted = false;
|
|
@@ -5179,7 +5473,7 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5179
5473
|
const productId = cfg.getAttribute("data-product-id") || ctx.campaign.product_id || null;
|
|
5180
5474
|
const state = { sort: "recent", withPhotos: false };
|
|
5181
5475
|
target.innerHTML = "";
|
|
5182
|
-
target.appendChild(el
|
|
5476
|
+
target.appendChild(el("div", `font-family:${IN_APP_FONT_STACK};font-size:13px;color:#9ca3af;padding:10px 0;`, "Loading reviews…"));
|
|
5183
5477
|
function buildUrl() {
|
|
5184
5478
|
const url = new URL("/v1/reviews/public", creds.apiHost);
|
|
5185
5479
|
if (productId) url.searchParams.set("product_id", productId);
|
|
@@ -5194,12 +5488,12 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5194
5488
|
let listContainer = null;
|
|
5195
5489
|
function reviewCard(r) {
|
|
5196
5490
|
var _a, _b, _c;
|
|
5197
|
-
const li = el
|
|
5198
|
-
const head = el
|
|
5491
|
+
const li = el("li", "padding:22px 0;border-top:1px solid #f0f1f3;");
|
|
5492
|
+
const head = el("div", "display:flex;align-items:center;gap:10px;");
|
|
5199
5493
|
head.appendChild(avatar(((_a = r.reviewer_snapshot) == null ? void 0 : _a.name) ?? "Customer", accent));
|
|
5200
|
-
const idn = el
|
|
5201
|
-
const nameRow = el
|
|
5202
|
-
nameRow.appendChild(el
|
|
5494
|
+
const idn = el("div", "display:flex;flex-direction:column;gap:2px;min-width:0;");
|
|
5495
|
+
const nameRow = el("div", "display:flex;flex-wrap:wrap;align-items:center;gap:8px;");
|
|
5496
|
+
nameRow.appendChild(el("span", "font-size:15px;font-weight:700;color:#111827;", ((_b = r.reviewer_snapshot) == null ? void 0 : _b.name) ?? "Customer"));
|
|
5203
5497
|
if (r.verified_purchase) nameRow.appendChild(verifiedBadge());
|
|
5204
5498
|
idn.appendChild(nameRow);
|
|
5205
5499
|
idn.appendChild(stars(r.rating ?? 0, 14));
|
|
@@ -5207,7 +5501,7 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5207
5501
|
if (r.created_at) {
|
|
5208
5502
|
const d = new Date(r.created_at);
|
|
5209
5503
|
if (!Number.isNaN(d.getTime())) {
|
|
5210
|
-
head.appendChild(el
|
|
5504
|
+
head.appendChild(el(
|
|
5211
5505
|
"span",
|
|
5212
5506
|
"margin-left:auto;font-size:12px;color:#9ca3af;white-space:nowrap;",
|
|
5213
5507
|
d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" })
|
|
@@ -5216,10 +5510,10 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5216
5510
|
}
|
|
5217
5511
|
li.appendChild(head);
|
|
5218
5512
|
if (r.review_text) {
|
|
5219
|
-
li.appendChild(el
|
|
5513
|
+
li.appendChild(el("p", "margin:12px 0 0;font-size:15px;line-height:1.6;color:#374151;", r.review_text));
|
|
5220
5514
|
}
|
|
5221
5515
|
if (r.media && r.media.length > 0) {
|
|
5222
|
-
const gallery = el
|
|
5516
|
+
const gallery = el("div", "display:flex;flex-wrap:wrap;gap:8px;margin-top:12px;");
|
|
5223
5517
|
for (const m2 of r.media.slice(0, 6)) {
|
|
5224
5518
|
const safe = ctx.sanitizeUrl(m2.url);
|
|
5225
5519
|
if (!safe) continue;
|
|
@@ -5232,22 +5526,22 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5232
5526
|
}
|
|
5233
5527
|
if (gallery.childElementCount) li.appendChild(gallery);
|
|
5234
5528
|
}
|
|
5235
|
-
const foot = el
|
|
5236
|
-
foot.appendChild(el
|
|
5529
|
+
const foot = el("div", "display:flex;align-items:center;gap:6px;margin-top:12px;");
|
|
5530
|
+
foot.appendChild(el("span", "font-size:13px;color:#9ca3af;margin-right:2px;", "Was this helpful?"));
|
|
5237
5531
|
foot.appendChild(thumbBtn(true, r.helpful_count ?? 0, r.id, creds));
|
|
5238
5532
|
foot.appendChild(thumbBtn(false, r.not_helpful_count ?? 0, r.id, creds));
|
|
5239
5533
|
li.appendChild(foot);
|
|
5240
5534
|
if ((_c = r.operator_reply) == null ? void 0 : _c.text) {
|
|
5241
|
-
const reply = el
|
|
5535
|
+
const reply = el(
|
|
5242
5536
|
"div",
|
|
5243
5537
|
`margin-top:14px;margin-left:44px;border-left:3px solid ${accent};background:${accent}0d;border-radius:0 12px 12px 0;padding:12px 14px;`
|
|
5244
5538
|
);
|
|
5245
|
-
const rlabel = el
|
|
5246
|
-
rlabel.appendChild(el
|
|
5247
|
-
rlabel.appendChild(el
|
|
5248
|
-
rlabel.appendChild(el
|
|
5539
|
+
const rlabel = el("div", "display:flex;align-items:center;gap:6px;margin-bottom:5px;");
|
|
5540
|
+
rlabel.appendChild(el("span", `width:7px;height:7px;border-radius:999px;background:${accent};display:inline-block;`));
|
|
5541
|
+
rlabel.appendChild(el("span", `font-size:12px;font-weight:700;color:${accent};`, brand));
|
|
5542
|
+
rlabel.appendChild(el("span", "font-size:12px;color:#9ca3af;", "· replied"));
|
|
5249
5543
|
reply.appendChild(rlabel);
|
|
5250
|
-
reply.appendChild(el
|
|
5544
|
+
reply.appendChild(el("p", "margin:0;font-size:14px;line-height:1.55;color:#4b5563;", r.operator_reply.text));
|
|
5251
5545
|
li.appendChild(reply);
|
|
5252
5546
|
}
|
|
5253
5547
|
return li;
|
|
@@ -5256,15 +5550,15 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5256
5550
|
if (!listContainer) return;
|
|
5257
5551
|
listContainer.innerHTML = "";
|
|
5258
5552
|
if (items.length === 0) {
|
|
5259
|
-
listContainer.appendChild(el
|
|
5553
|
+
listContainer.appendChild(el("p", "padding:20px 0;font-size:14px;color:#9ca3af;text-align:center;", "No reviews match this filter."));
|
|
5260
5554
|
return;
|
|
5261
5555
|
}
|
|
5262
|
-
const ul = el
|
|
5556
|
+
const ul = el("ul", "list-style:none;margin:0;padding:0;");
|
|
5263
5557
|
for (const r of items) ul.appendChild(reviewCard(r));
|
|
5264
5558
|
listContainer.appendChild(ul);
|
|
5265
5559
|
}
|
|
5266
5560
|
function pill(label, active, onClick) {
|
|
5267
|
-
const b = el
|
|
5561
|
+
const b = el(
|
|
5268
5562
|
"button",
|
|
5269
5563
|
`font-size:13px;font-weight:600;padding:7px 16px;border-radius:999px;cursor:pointer;font-family:inherit;` + (active ? `background:${accent};color:#fff;border:1px solid ${accent};` : "background:#fff;color:#374151;border:1px solid #e5e7eb;"),
|
|
5270
5564
|
label
|
|
@@ -5273,7 +5567,7 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5273
5567
|
return b;
|
|
5274
5568
|
}
|
|
5275
5569
|
function controls(rerender) {
|
|
5276
|
-
const bar = el
|
|
5570
|
+
const bar = el("div", "display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:18px 0 4px;");
|
|
5277
5571
|
const sel = document.createElement("select");
|
|
5278
5572
|
sel.style.cssText = `font-size:13px;font-weight:600;padding:7px 30px 7px 14px;border:1px solid #e5e7eb;border-radius:999px;background:#fff;color:#374151;cursor:pointer;font-family:inherit;appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;`;
|
|
5279
5573
|
for (const s of SORTS) {
|
|
@@ -5300,29 +5594,29 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5300
5594
|
return bar;
|
|
5301
5595
|
}
|
|
5302
5596
|
function distributionPanel(dist, total) {
|
|
5303
|
-
const box = el
|
|
5597
|
+
const box = el("div", "flex:0 1 300px;width:300px;max-width:100%;display:flex;flex-direction:column;gap:7px;");
|
|
5304
5598
|
for (let r = 5; r >= 1; r--) {
|
|
5305
5599
|
const n = dist[String(r)] ?? 0;
|
|
5306
5600
|
const pct = total > 0 ? Math.round(n / total * 100) : 0;
|
|
5307
|
-
const row = el
|
|
5308
|
-
const lbl = el
|
|
5601
|
+
const row = el("div", "display:flex;align-items:center;gap:10px;font-size:13px;color:#6b7280;");
|
|
5602
|
+
const lbl = el("span", "width:30px;display:inline-flex;align-items:center;gap:3px;color:#374151;font-weight:600;", String(r));
|
|
5309
5603
|
lbl.appendChild(star(true, 11));
|
|
5310
5604
|
row.appendChild(lbl);
|
|
5311
|
-
const track = el
|
|
5312
|
-
track.appendChild(el
|
|
5605
|
+
const track = el("div", "flex:1;height:8px;background:#f0f1f3;border-radius:999px;overflow:hidden;");
|
|
5606
|
+
track.appendChild(el("div", `width:${pct}%;height:100%;background:${accent};border-radius:999px;`));
|
|
5313
5607
|
row.appendChild(track);
|
|
5314
|
-
row.appendChild(el
|
|
5608
|
+
row.appendChild(el("span", "width:24px;text-align:right;font-variant-numeric:tabular-nums;", String(n)));
|
|
5315
5609
|
box.appendChild(row);
|
|
5316
5610
|
}
|
|
5317
5611
|
return box;
|
|
5318
5612
|
}
|
|
5319
5613
|
function aiSummaryCard(summary) {
|
|
5320
|
-
const card = el
|
|
5614
|
+
const card = el(
|
|
5321
5615
|
"div",
|
|
5322
5616
|
"position:relative;border-radius:18px;padding:18px 20px;margin-bottom:24px;background:linear-gradient(135deg,#faf5ff 0%,#f5f3ff 100%);border:1px solid #ede9fe;"
|
|
5323
5617
|
);
|
|
5324
|
-
const head = el
|
|
5325
|
-
const left = el
|
|
5618
|
+
const head = el("div", "display:flex;align-items:center;justify-content:space-between;margin-bottom:8px;");
|
|
5619
|
+
const left = el("div", "display:flex;align-items:center;gap:7px;");
|
|
5326
5620
|
const sp = document.createElementNS(SVG_NS, "svg");
|
|
5327
5621
|
sp.setAttribute("viewBox", "0 0 24 24");
|
|
5328
5622
|
sp.setAttribute("width", "16");
|
|
@@ -5332,17 +5626,17 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5332
5626
|
spp.setAttribute("fill", "#7c3aed");
|
|
5333
5627
|
sp.appendChild(spp);
|
|
5334
5628
|
left.appendChild(sp);
|
|
5335
|
-
left.appendChild(el
|
|
5629
|
+
left.appendChild(el("span", "font-size:12px;font-weight:800;letter-spacing:.07em;color:#6d28d9;text-transform:uppercase;", "What customers say"));
|
|
5336
5630
|
head.appendChild(left);
|
|
5337
|
-
head.appendChild(el
|
|
5631
|
+
head.appendChild(el("span", "font-size:11px;font-weight:600;color:#a78bda;", "AI-generated"));
|
|
5338
5632
|
card.appendChild(head);
|
|
5339
|
-
card.appendChild(el
|
|
5340
|
-
card.appendChild(el
|
|
5633
|
+
card.appendChild(el("p", "margin:0;font-size:15px;line-height:1.6;color:#3b2a63;", summary.text));
|
|
5634
|
+
card.appendChild(el("p", "margin:8px 0 0;font-size:12px;color:#a78bda;text-align:right;", `from ${summary.review_count} reviews`));
|
|
5341
5635
|
return card;
|
|
5342
5636
|
}
|
|
5343
5637
|
function renderWall(data) {
|
|
5344
5638
|
target.innerHTML = "";
|
|
5345
|
-
const root = el
|
|
5639
|
+
const root = el(
|
|
5346
5640
|
"section",
|
|
5347
5641
|
`font-family:${IN_APP_FONT_STACK};color:#111827;max-width:860px;margin:0 auto;-webkit-font-smoothing:antialiased;`
|
|
5348
5642
|
);
|
|
@@ -5350,25 +5644,25 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5350
5644
|
const summary = data.aggregate.ai_summary;
|
|
5351
5645
|
if (summary && summary.text) root.appendChild(aiSummaryCard(summary));
|
|
5352
5646
|
if (data.aggregate.count === 0) {
|
|
5353
|
-
root.appendChild(el
|
|
5647
|
+
root.appendChild(el("p", "font-size:15px;color:#9ca3af;padding:6px 0;", "No reviews yet — be the first to share your experience."));
|
|
5354
5648
|
target.appendChild(root);
|
|
5355
5649
|
return;
|
|
5356
5650
|
}
|
|
5357
|
-
const header = el
|
|
5358
|
-
const ratingBlock = el
|
|
5359
|
-
const topRow = el
|
|
5651
|
+
const header = el("div", "display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:24px 40px;padding-bottom:4px;");
|
|
5652
|
+
const ratingBlock = el("div", "display:flex;flex-direction:column;gap:4px;");
|
|
5653
|
+
const topRow = el("div", "display:flex;align-items:center;gap:12px;");
|
|
5360
5654
|
const avg = data.aggregate.avg_rating ?? 0;
|
|
5361
5655
|
topRow.appendChild(stars(Math.round(avg), 20));
|
|
5362
|
-
topRow.appendChild(el
|
|
5656
|
+
topRow.appendChild(el("span", "font-size:32px;font-weight:800;line-height:1;letter-spacing:-0.02em;", avg ? avg.toFixed(1) : "—"));
|
|
5363
5657
|
ratingBlock.appendChild(topRow);
|
|
5364
|
-
ratingBlock.appendChild(el
|
|
5658
|
+
ratingBlock.appendChild(el("span", "font-size:13px;color:#6b7280;", `${data.aggregate.count} review${data.aggregate.count === 1 ? "" : "s"} · 100% verified`));
|
|
5365
5659
|
header.appendChild(ratingBlock);
|
|
5366
5660
|
header.appendChild(distributionPanel(data.aggregate.distribution, data.aggregate.count));
|
|
5367
5661
|
root.appendChild(header);
|
|
5368
5662
|
root.appendChild(controls(() => {
|
|
5369
5663
|
void fetchReviews().then((d) => renderList((d == null ? void 0 : d.items) ?? []));
|
|
5370
5664
|
}));
|
|
5371
|
-
listContainer = el
|
|
5665
|
+
listContainer = el("div", "margin-top:2px;");
|
|
5372
5666
|
root.appendChild(listContainer);
|
|
5373
5667
|
renderList(data.items);
|
|
5374
5668
|
target.appendChild(root);
|
|
@@ -5380,23 +5674,23 @@ function renderReviewsInline(ctx, target, creds) {
|
|
|
5380
5674
|
var _a;
|
|
5381
5675
|
target.innerHTML = "";
|
|
5382
5676
|
if (data.aggregate.count === 0) return;
|
|
5383
|
-
const root = el
|
|
5677
|
+
const root = el(
|
|
5384
5678
|
"section",
|
|
5385
5679
|
`font-family:${IN_APP_FONT_STACK};color:#111827;max-width:860px;margin:0 auto;border:1px solid #f0f1f3;border-radius:16px;padding:16px 18px;`
|
|
5386
5680
|
);
|
|
5387
|
-
const line = el
|
|
5681
|
+
const line = el("div", "display:flex;align-items:center;gap:8px;");
|
|
5388
5682
|
const avg = data.aggregate.avg_rating ?? 0;
|
|
5389
5683
|
line.appendChild(stars(Math.round(avg), 16));
|
|
5390
|
-
line.appendChild(el
|
|
5391
|
-
line.appendChild(el
|
|
5684
|
+
line.appendChild(el("span", "font-size:16px;font-weight:700;", avg ? avg.toFixed(1) : "—"));
|
|
5685
|
+
line.appendChild(el("span", "font-size:13px;color:#6b7280;", `(${data.aggregate.count})`));
|
|
5392
5686
|
line.appendChild(verifiedBadge());
|
|
5393
5687
|
root.appendChild(line);
|
|
5394
5688
|
const top = data.items.find((i) => i.review_text);
|
|
5395
5689
|
if (top && top.review_text) {
|
|
5396
|
-
root.appendChild(el
|
|
5397
|
-
root.appendChild(el
|
|
5690
|
+
root.appendChild(el("p", "margin:10px 0 0;font-size:15px;color:#374151;line-height:1.5;", `“${top.review_text}”`));
|
|
5691
|
+
root.appendChild(el("span", "font-size:13px;color:#9ca3af;", `— ${((_a = top.reviewer_snapshot) == null ? void 0 : _a.name) ?? "Customer"}`));
|
|
5398
5692
|
}
|
|
5399
|
-
const seeAll = el
|
|
5693
|
+
const seeAll = el("button", `margin-top:12px;font-size:14px;font-weight:700;color:${accent};background:none;border:none;cursor:pointer;padding:0;font-family:inherit;`, "See all reviews →");
|
|
5400
5694
|
seeAll.addEventListener("click", () => renderWall(data));
|
|
5401
5695
|
root.appendChild(seeAll);
|
|
5402
5696
|
target.appendChild(root);
|
|
@@ -5420,10 +5714,10 @@ function renderReviewsOverlay(ctx, creds) {
|
|
|
5420
5714
|
overlay.style.cssText = "position:fixed;inset:0;background:rgba(17,24,39,0.5);display:flex;align-items:flex-end;justify-content:center;z-index:99999;";
|
|
5421
5715
|
const sheet = document.createElement("div");
|
|
5422
5716
|
sheet.style.cssText = `background:#fff;color:#111827;max-width:680px;width:100%;max-height:84vh;overflow-y:auto;border-radius:24px 24px 0 0;padding:18px 18px 28px;font-family:${IN_APP_FONT_STACK};box-shadow:0 -16px 40px rgba(0,0,0,0.14);`;
|
|
5423
|
-
sheet.appendChild(el
|
|
5424
|
-
const bar = el
|
|
5425
|
-
bar.appendChild(el
|
|
5426
|
-
const close = el
|
|
5717
|
+
sheet.appendChild(el("div", "width:38px;height:4px;border-radius:999px;background:#e5e7eb;margin:0 auto 14px;"));
|
|
5718
|
+
const bar = el("div", "display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;");
|
|
5719
|
+
bar.appendChild(el("div", "font-weight:800;font-size:17px;", ctx.campaign.title || "Customer reviews"));
|
|
5720
|
+
const close = el("button", "background:none;border:none;cursor:pointer;padding:4px 8px;color:#6b7280;");
|
|
5427
5721
|
const x = document.createElementNS(SVG_NS, "svg");
|
|
5428
5722
|
x.setAttribute("viewBox", "0 0 24 24");
|
|
5429
5723
|
x.setAttribute("width", "20");
|
|
@@ -5442,7 +5736,7 @@ function renderReviewsOverlay(ctx, creds) {
|
|
|
5442
5736
|
});
|
|
5443
5737
|
bar.appendChild(close);
|
|
5444
5738
|
sheet.appendChild(bar);
|
|
5445
|
-
const body = el
|
|
5739
|
+
const body = el("div");
|
|
5446
5740
|
const pid = ctx.campaign.product_id;
|
|
5447
5741
|
if (pid) body.setAttribute("data-product-id", pid);
|
|
5448
5742
|
sheet.appendChild(body);
|
|
@@ -5456,161 +5750,6 @@ function renderReviewsOverlay(ctx, creds) {
|
|
|
5456
5750
|
document.body.appendChild(overlay);
|
|
5457
5751
|
renderReviewsInline(ctx, body, creds);
|
|
5458
5752
|
}
|
|
5459
|
-
const STAR_PATH = "M12 2L15.09 8.26 22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z";
|
|
5460
|
-
function el(tag, css, txt) {
|
|
5461
|
-
const e = document.createElement(tag);
|
|
5462
|
-
e.style.cssText = css;
|
|
5463
|
-
if (txt != null) e.textContent = txt;
|
|
5464
|
-
return e;
|
|
5465
|
-
}
|
|
5466
|
-
function starSvg(filled, accent, size = 26) {
|
|
5467
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
5468
|
-
svg.setAttribute("viewBox", "0 0 24 24");
|
|
5469
|
-
svg.setAttribute("width", String(size));
|
|
5470
|
-
svg.setAttribute("height", String(size));
|
|
5471
|
-
svg.style.cssText = "display:block;transition:transform .1s ease;";
|
|
5472
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
5473
|
-
path.setAttribute("d", STAR_PATH);
|
|
5474
|
-
path.setAttribute("fill", "#d1d5db");
|
|
5475
|
-
svg.appendChild(path);
|
|
5476
|
-
return svg;
|
|
5477
|
-
}
|
|
5478
|
-
function readContext(target) {
|
|
5479
|
-
const cfg = target.closest("[data-aegis-slot]") ?? target;
|
|
5480
|
-
let items = [];
|
|
5481
|
-
const raw = cfg.getAttribute("data-rateable-items");
|
|
5482
|
-
if (raw) {
|
|
5483
|
-
try {
|
|
5484
|
-
const parsed = JSON.parse(raw);
|
|
5485
|
-
if (Array.isArray(parsed)) {
|
|
5486
|
-
items = parsed.filter((p) => !!p && typeof p === "object" && "product_id" in p).map((p) => ({ product_id: String(p.product_id), name: p.name ?? null }));
|
|
5487
|
-
}
|
|
5488
|
-
} catch {
|
|
5489
|
-
}
|
|
5490
|
-
}
|
|
5491
|
-
return {
|
|
5492
|
-
items,
|
|
5493
|
-
orderId: cfg.getAttribute("data-order-id"),
|
|
5494
|
-
billCode: cfg.getAttribute("data-bill-code"),
|
|
5495
|
-
token: cfg.getAttribute("data-token"),
|
|
5496
|
-
accent: cfg.getAttribute("data-accent"),
|
|
5497
|
-
reviewsUrl: cfg.getAttribute("data-reviews-url"),
|
|
5498
|
-
// The bill knows its customer server-side; the SDK may still be anonymous
|
|
5499
|
-
// on a fresh visit. Prefer the slot-stamped contact so the per-item write
|
|
5500
|
-
// (contact_id NOT NULL) succeeds. On untrusted origins the server ignores
|
|
5501
|
-
// this and uses the token-resolved contact instead.
|
|
5502
|
-
contactId: cfg.getAttribute("data-contact-id")
|
|
5503
|
-
};
|
|
5504
|
-
}
|
|
5505
|
-
function renderProductRatingInline(ctx, target, creds) {
|
|
5506
|
-
if (typeof document === "undefined" || !(creds == null ? void 0 : creds.apiHost) || !(creds == null ? void 0 : creds.writeKey)) return false;
|
|
5507
|
-
ensureInAppFont();
|
|
5508
|
-
const { items, orderId, billCode, token, accent: slotAccent, reviewsUrl, contactId: slotContact } = readContext(target);
|
|
5509
|
-
if (items.length === 0 || !orderId && !billCode && !token) return false;
|
|
5510
|
-
const ic = ctx.campaign.interactive_config || {};
|
|
5511
|
-
const accent = ctx.sanitizeColor(
|
|
5512
|
-
slotAccent || ctx.campaign.background_color || "#4169e1"
|
|
5513
|
-
);
|
|
5514
|
-
const title = ic.question || "Rate your items";
|
|
5515
|
-
const scores = {};
|
|
5516
|
-
target.innerHTML = "";
|
|
5517
|
-
const card = el(
|
|
5518
|
-
"div",
|
|
5519
|
-
`font-family:${IN_APP_FONT_STACK};border:1px solid #f1f1f3;border-radius:14px;background:#fff;padding:14px 16px;`
|
|
5520
|
-
);
|
|
5521
|
-
card.appendChild(el("p", "margin:0;font-size:14px;font-weight:700;color:#111827;", title));
|
|
5522
|
-
const list = el("ul", "list-style:none;margin:10px 0 0;padding:0;display:flex;flex-direction:column;gap:10px;");
|
|
5523
|
-
for (const it of items) {
|
|
5524
|
-
const li = el("li", "display:flex;align-items:center;justify-content:space-between;gap:12px;");
|
|
5525
|
-
li.appendChild(el("span", "flex:1;min-width:0;font-size:13px;color:#374151;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;", it.name || it.product_id));
|
|
5526
|
-
const row = el("div", "display:flex;gap:2px;flex-shrink:0;");
|
|
5527
|
-
const starEls = [];
|
|
5528
|
-
for (let n = 1; n <= 5; n += 1) {
|
|
5529
|
-
const btn = el("span", "cursor:pointer;padding:1px;line-height:0;");
|
|
5530
|
-
const sv = starSvg();
|
|
5531
|
-
btn.appendChild(sv);
|
|
5532
|
-
starEls.push(sv);
|
|
5533
|
-
btn.setAttribute("role", "button");
|
|
5534
|
-
btn.setAttribute("aria-label", `Rate ${it.name || it.product_id} ${n} star${n === 1 ? "" : "s"}`);
|
|
5535
|
-
btn.addEventListener("click", () => {
|
|
5536
|
-
scores[it.product_id] = n;
|
|
5537
|
-
starEls.forEach((s, i) => {
|
|
5538
|
-
const p = s.querySelector("path");
|
|
5539
|
-
if (p) p.setAttribute("fill", i < n ? accent : "#d1d5db");
|
|
5540
|
-
});
|
|
5541
|
-
submitBtn.style.opacity = "1";
|
|
5542
|
-
submitBtn.style.pointerEvents = "auto";
|
|
5543
|
-
});
|
|
5544
|
-
row.appendChild(btn);
|
|
5545
|
-
}
|
|
5546
|
-
li.appendChild(row);
|
|
5547
|
-
list.appendChild(li);
|
|
5548
|
-
}
|
|
5549
|
-
card.appendChild(list);
|
|
5550
|
-
const submitBtn = el(
|
|
5551
|
-
"button",
|
|
5552
|
-
`margin-top:14px;width:100%;border:0;border-radius:999px;background:${accent};color:#fff;font-size:14px;font-weight:700;padding:10px 16px;cursor:pointer;opacity:.5;pointer-events:none;font-family:inherit;`,
|
|
5553
|
-
"Submit ratings"
|
|
5554
|
-
);
|
|
5555
|
-
card.appendChild(submitBtn);
|
|
5556
|
-
const done = (branch) => {
|
|
5557
|
-
target.innerHTML = "";
|
|
5558
|
-
const ack = el(
|
|
5559
|
-
"div",
|
|
5560
|
-
`font-family:${IN_APP_FONT_STACK};border:1px solid #f1f1f3;border-radius:14px;background:#fff;padding:18px 16px;text-align:center;`
|
|
5561
|
-
);
|
|
5562
|
-
ack.appendChild(el("p", "margin:0;font-size:14px;font-weight:700;color:#111827;", "Thanks for rating your items!"));
|
|
5563
|
-
const positiveUrl = reviewsUrl || ic.rating_high_url || null;
|
|
5564
|
-
if (branch === "positive" && positiveUrl) {
|
|
5565
|
-
const a = document.createElement("a");
|
|
5566
|
-
a.href = positiveUrl;
|
|
5567
|
-
a.textContent = ic.rating_high_cta || "Share a review";
|
|
5568
|
-
a.style.cssText = `display:inline-block;margin-top:8px;font-size:12px;font-weight:700;color:${accent};text-decoration:none;`;
|
|
5569
|
-
ack.appendChild(a);
|
|
5570
|
-
} else {
|
|
5571
|
-
ack.appendChild(el("p", "margin:6px 0 0;font-size:12px;color:#9ca3af;", "We'll use your feedback to improve."));
|
|
5572
|
-
}
|
|
5573
|
-
target.appendChild(ack);
|
|
5574
|
-
};
|
|
5575
|
-
submitBtn.addEventListener("click", () => {
|
|
5576
|
-
const rated = Object.keys(scores);
|
|
5577
|
-
if (rated.length === 0) return;
|
|
5578
|
-
submitBtn.disabled = true;
|
|
5579
|
-
submitBtn.style.opacity = ".6";
|
|
5580
|
-
submitBtn.textContent = "Saving…";
|
|
5581
|
-
const payload = {
|
|
5582
|
-
items: rated.map((pid) => ({ product_id: pid, score: scores[pid] })),
|
|
5583
|
-
order_id: orderId,
|
|
5584
|
-
bill_code: billCode,
|
|
5585
|
-
token
|
|
5586
|
-
};
|
|
5587
|
-
fetch(new URL("/v1/in-app/responses", creds.apiHost).toString(), {
|
|
5588
|
-
method: "POST",
|
|
5589
|
-
headers: {
|
|
5590
|
-
"Content-Type": "application/json",
|
|
5591
|
-
"X-Aegis-Write-Key": creds.writeKey,
|
|
5592
|
-
"X-Organization-ID": creds.organizationId
|
|
5593
|
-
},
|
|
5594
|
-
body: JSON.stringify({
|
|
5595
|
-
campaign_id: ctx.campaign.id,
|
|
5596
|
-
response_type: "rating",
|
|
5597
|
-
contact_id: slotContact || creds.contactId,
|
|
5598
|
-
platform: "web",
|
|
5599
|
-
payload
|
|
5600
|
-
})
|
|
5601
|
-
}).then((r) => r.ok ? r.json() : null).then((data) => {
|
|
5602
|
-
var _a;
|
|
5603
|
-
ctx.trackEvent(ctx.campaign.id, "clicked");
|
|
5604
|
-
done(((_a = data == null ? void 0 : data.rating_result) == null ? void 0 : _a.branch) || "positive");
|
|
5605
|
-
}).catch(() => {
|
|
5606
|
-
submitBtn.disabled = false;
|
|
5607
|
-
submitBtn.style.opacity = "1";
|
|
5608
|
-
submitBtn.textContent = "Submit ratings";
|
|
5609
|
-
});
|
|
5610
|
-
});
|
|
5611
|
-
target.appendChild(card);
|
|
5612
|
-
return true;
|
|
5613
|
-
}
|
|
5614
5753
|
function readAnonIdFromStorage$1() {
|
|
5615
5754
|
if (typeof document === "undefined") return void 0;
|
|
5616
5755
|
try {
|
|
@@ -6582,23 +6721,6 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
6582
6721
|
}
|
|
6583
6722
|
return;
|
|
6584
6723
|
}
|
|
6585
|
-
if (campaign.sub_type === "star_rating" && this._isPerItemRating(campaign)) {
|
|
6586
|
-
const ok = renderProductRatingInline(this.buildRenderContext(campaign), target, {
|
|
6587
|
-
apiHost: this.apiHost,
|
|
6588
|
-
writeKey: this.writeKey,
|
|
6589
|
-
organizationId: this.organizationId ?? "",
|
|
6590
|
-
contactId: this.contactId ?? null
|
|
6591
|
-
});
|
|
6592
|
-
if (!ok) {
|
|
6593
|
-
this.displayedCampaigns.delete(campaign.id);
|
|
6594
|
-
return;
|
|
6595
|
-
}
|
|
6596
|
-
if (!(options == null ? void 0 : options.deferImpression)) {
|
|
6597
|
-
this.trackEvent(campaign.id, "impression");
|
|
6598
|
-
this.emit("campaign-shown", campaign);
|
|
6599
|
-
}
|
|
6600
|
-
return;
|
|
6601
|
-
}
|
|
6602
6724
|
this._ensureSurveyTemplate(campaign);
|
|
6603
6725
|
const _isMultiCard = campaign.sub_type === "product_recommendation" || campaign.sub_type === "carousel_cards";
|
|
6604
6726
|
if (this._hasComposedTemplate(ic) && !_isMultiCard) {
|
|
@@ -6679,14 +6801,6 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
6679
6801
|
const tpl = ic.card_template;
|
|
6680
6802
|
return !!tpl && typeof tpl === "object" && Array.isArray(tpl.elements) && tpl.elements.length > 0;
|
|
6681
6803
|
}
|
|
6682
|
-
/** G5 — whether a `star_rating` campaign captures PER-SKU ratings (one row per
|
|
6683
|
-
* order line-item) vs a single order-level score. Opt-in via
|
|
6684
|
-
* `interactive_config.rating_mode='per_item'`, so the order-level star path is
|
|
6685
|
-
* untouched. The renderer reads the SKUs from the slot at mount. */
|
|
6686
|
-
_isPerItemRating(campaign) {
|
|
6687
|
-
const ic = campaign.interactive_config || {};
|
|
6688
|
-
return ic.rating_mode === "per_item";
|
|
6689
|
-
}
|
|
6690
6804
|
/**
|
|
6691
6805
|
* P6.full — flat survey → card_template adapter. A `nps_survey` / `star_rating`
|
|
6692
6806
|
* / `quick_poll` authored WITHOUT a card_template gets one synthesised in place
|
|
@@ -6756,9 +6870,11 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
6756
6870
|
};
|
|
6757
6871
|
const template = resolveGlobalTemplate(ic);
|
|
6758
6872
|
const { accent } = this._surfacePalette(campaign);
|
|
6873
|
+
const ctx = this.buildRenderContext(campaign);
|
|
6874
|
+
ctx.slotEl = target.closest("[data-aegis-slot]") ?? target;
|
|
6759
6875
|
const tile = renderCardFromTemplate(card, {
|
|
6760
6876
|
template,
|
|
6761
|
-
ctx
|
|
6877
|
+
ctx,
|
|
6762
6878
|
action: "navigate",
|
|
6763
6879
|
layoutAccent: this.sanitizeColor(campaign.background_color || accent)
|
|
6764
6880
|
});
|
|
@@ -8604,7 +8720,10 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8604
8720
|
},
|
|
8605
8721
|
sanitizeColor: (color) => this.sanitizeColor(color),
|
|
8606
8722
|
log: (msg, level) => this.log(msg, level),
|
|
8607
|
-
addAnimationStyles: () => this.addAnimationStyles()
|
|
8723
|
+
addAnimationStyles: () => this.addAnimationStyles(),
|
|
8724
|
+
apiHost: this.apiHost,
|
|
8725
|
+
writeKey: this.writeKey,
|
|
8726
|
+
organizationId: this.organizationId
|
|
8608
8727
|
};
|
|
8609
8728
|
}
|
|
8610
8729
|
/**
|
|
@@ -11088,7 +11207,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11088
11207
|
}
|
|
11089
11208
|
}
|
|
11090
11209
|
try {
|
|
11091
|
-
const url = `${this.apiHost}/v1/
|
|
11210
|
+
const url = `${this.apiHost}/v1/in-app/events`;
|
|
11092
11211
|
const externalEventId = `inapp_${campaignId}_${eventType}_${Date.now()}`;
|
|
11093
11212
|
const headers = {
|
|
11094
11213
|
"Content-Type": "application/json",
|
|
@@ -11190,6 +11309,7 @@ _AegisInAppManager.KNOWN_SURFACES = /* @__PURE__ */ new Set([
|
|
|
11190
11309
|
"storefront_feedback",
|
|
11191
11310
|
"storefront_reviews",
|
|
11192
11311
|
"storefront_members",
|
|
11312
|
+
"storefront_orders",
|
|
11193
11313
|
"external_website",
|
|
11194
11314
|
"external_mobile_screen"
|
|
11195
11315
|
]);
|
|
@@ -14417,7 +14537,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
14417
14537
|
var _a;
|
|
14418
14538
|
this.initialized = false;
|
|
14419
14539
|
{
|
|
14420
|
-
const v = "1.35.
|
|
14540
|
+
const v = "1.35.2";
|
|
14421
14541
|
try {
|
|
14422
14542
|
globalThis.__AEGIS_SDK_VERSION__ = v;
|
|
14423
14543
|
} catch {
|