@sprig-technologies/sprig-browser
Version:
npm package for the sprig web sdk
773 lines • 63.5 kB
JavaScript
var qt = Object.defineProperty;
var Ft = (r, e, i) => e in r ? qt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[e] = i;
var N = (r, e, i) => Ft(r, typeof e != "symbol" ? e + "" : e, i);
import { l as z, g as O, s as ut, e as g, S as u, v as gt, m as I, b as P, h as ht, E as se, a as Q, D as C, c as Ht, r as G, i as zt, j as Vt, k as Wt, n as Ye, o as Xe, d as Nt, p as yt, q as bt } from "./metricsReporter-CVAZgxNJ.js";
const fr = 360, vr = "ul-app", wr = "#e6e6e6", Lr = "#d66464", Ur = 1030, Ze = () => {
try {
return window.parent.Intercom;
} catch {
return null;
}
}, et = [Object.freeze(Object.defineProperty({ __proto__: null, disable: () => {
const r = Ze();
r && (r.ul_wasVisible = !!document.querySelector("iframe.intercom-launcher-frame"), r.ul_wasVisible && r("update", { hide_default_launcher: !0 }));
}, enable: () => {
const r = Ze();
r && (r.ul_wasVisible && r("update", { hide_default_launcher: !1 }), delete r.ul_wasVisible);
} }, Symbol.toStringTag, { value: "Module" }))];
class Bt {
static disable() {
et.forEach((e) => e.disable());
}
static enable() {
et.forEach((e) => e.enable());
}
}
const tt = "ul-view-sdk-script", $t = /* @__PURE__ */ new Set(["ios", "android"]), F = "visitors", H = "environments";
async function D(r, e) {
var s, n, o;
const { shouldDropOnRateLimit: i, ...a } = e;
a.headers = Object.assign(O(window.UserLeap), a.headers);
const t = await ut(r, { ...a, shouldDropOnRateLimit: i });
if (t.ok) {
const l = (s = t.headers) == null ? void 0 : s.get("Authorization"), c = l ? l.split(" ") : void 0, d = c && c.length === 2 ? c[1] : void 0, p = (n = t.headers) == null ? void 0 : n.get("x-ul-visitor-id");
if (window.UserLeap.userId && p === window.UserLeap.visitorId) {
const y = z.getItemObject("sprig.anon.env.vid.map");
y && y[window.UserLeap.envId] === p && (delete y[window.UserLeap.envId], z.setItemObject("sprig.anon.env.vid.map", y));
}
d && p && (p !== window.UserLeap.visitorId || window.UserLeap.token !== d) && (E("token", d), E("vid", p), g.emit(u.VisitorIDUpdated, { visitorId: p }), window.UserLeap.token = d, window.UserLeap.visitorId = p);
}
return (o = t.json) != null && o.logMessage && console.warn(`[Sprig] ${t.json.logMessage}`), t;
}
function E(r, e) {
const i = z.getItemObject("userleap.ids");
let a = i[window.UserLeap.envId];
a ? a[r] = e : a = { [r]: e }, i[window.UserLeap.envId] = a, z.setItemObject("userleap.ids", i);
}
function je() {
return window.previewMode ? "0" : window.UserLeap.visitorId ?? "";
}
function x(r, e, i) {
const a = [window.UserLeap._API_URL, "sdk", r];
return e && e.forEach((t) => {
a.push(t), t === H ? a.push(window.UserLeap.envId) : t === F && a.push(je());
}), i && a.push(i), a.join("/");
}
const ee = async (r, e, i) => {
var $e, Ge, Ke, Qe;
const { context: a, delay: t, avatars: s, experimentFlags: n, forceBrandedLogo: o, endCard: l, isFeedback: c = !1, heatmap: d, locale: p, layout: y, previewMode: b, productConfig: h, quotaMessages: v, providerPersona: k, quotas: f, questions: w, responseGroupUid: U, surveyId: S, uuid: M, vid: L, sessionReplay: _, showProviderPersona: j, useBranding: oe, studyType: ne, surveyVisitorAttributes: Pt } = r, V = O(window.UserLeap), Mt = ae(V), Se = Ue(V);
if (_) if (Mt) g.emit(u.ReplayCapture, { responseGroupUid: U, hasQuestions: !!(w != null && w.length), surveyId: S, uploadId: _.uploadId, replayType: _.replayDurationType ?? "before", seconds: _.replayDurationSeconds, generateVideoUploadUrlPayload: { mediaRecordingUid: gt(), mediaType: "screen", questionId: 1, responseGroupUid: U, surveyId: S, updatedAt: (/* @__PURE__ */ new Date()).toISOString(), visitorId: window.UserLeap.visitorId, isReplay: !0 } });
else {
if (!I.replay) return window.UserLeap.reportError("displayQuestions", new Error("Replay module not registered")), { success: !1, message: "Replay module not registered", surveyState: "no survey" };
I.replay.scheduleOrCaptureReplay({ responseGroupId: U, surveyId: S, visitorId: L, replayParams: _, completeUploadHeaders: V, apiUrl: window.UserLeap._API_URL, triggerTimestamp: Date.now(), isStandalone: w.length === 0 });
}
if (d) {
if (!I.replay) return window.UserLeap.reportError("displayQuestions", new Error("Replay module not registered")), { success: !1, message: "Replay module not registered", surveyState: "no survey" };
const { eventId: T, replayParams: W, responseGroupUid: ke, surveyId: Ee } = d;
await I.replay.initializeReplay({ maxReplayDurationSeconds: 300, maxInflightRequests: window.UserLeap.maxInflightReplayRequests, teardownAfter: !0, apiUrl: window.UserLeap._API_URL, replaySettings: i }), I.replay.tryReplayAction(() => {
var Je;
return (Je = I.replay) == null ? void 0 : Je.scheduleCapture({ apiUrl: window.UserLeap._API_URL, completeUploadHeaders: V, eventId: T, isHeatmap: !0, replayParams: W, responseGroupId: ke, surveyId: Ee, triggerTimestamp: Date.now(), visitorId: L });
}, "Error in scheduling/capturing replay");
}
if (L == null || !(w != null && w.length)) return P.info("CannotDisplaySurvey", { vid: L }), { success: !1, message: "[Sprig] no survey found", surveyState: window.UserLeap.container ? "previous survey ready" : "no survey" };
if (window.UserLeap.container) {
P.info("AlreadyDisplayingSurvey");
const T = "[Sprig] (ERR-409) Found an existing Survey container, aborting rendering of this survey";
return console.warn(T), { success: !1, message: T, surveyState: "previous survey ready" };
}
if (L !== window.UserLeap.visitorId && M !== window.UserLeap.visitorId && !window.previewMode) {
const T = "Attempted to display survey to a different visitor";
return window.UserLeap.reportError("DisplaySurvey", new Error(T)), { success: !1, message: T, surveyState: "no survey" };
}
P.info("ShowingSurvey", { surveyId: S }), ($e = I.replay) == null || $e.RecordSurveyShown({ id: S, userAgent: window.navigator.userAgent }), Bt.disable(), g.emit(u.SurveyWillPresent, { name: u.SurveyWillPresent, "survey.id": S, layout: y });
let le, Y, R, de, ce = document.createElement("div");
const Ve = (T) => {
const { "view.version": W } = T;
W !== V["x-ul-sdk-version"] && ft(), g.removeListener("verify.view.version", Ve);
};
g.on("verify.view.version", Ve), window.UserLeap.useMobileStyling = Se, ht(V) ? (le = "ul-direct-embeded-frame", Y = document.head, R = window, de = !1, (() => {
const T = O(window.UserLeap), W = ae(T), ke = window.UserLeap.forceDirectEmbed, Ee = T["userleap-platform"] === "web";
return W || ke && Ee;
})() && (mt(S, c), ce.id = le, window.UserLeap.container.appendChild(ce), vt(), g.emit(u.SurveyLifeCycle, { state: "presented" }), g.emit(u.SurveyPresented, { name: u.SurveyPresented, "survey.id": S }))) : { frameId: le, contentWinDocHead: Y, contentWindow: R, hasOverlay: de, iframe: ce } = Qt({ productConfig: h, useMobileStyling: Se, surveyId: S, isFeedback: c, enableCspTrustedTypes: (Ge = window.UserLeap._config) == null ? void 0 : Ge.enableCspTrustedTypes }), window.UserLeap.frameId = le;
const K = { apiURL: window.UserLeap._API_URL, avatars: s, cards: w, configureExitOnOverlayClick: (T) => {
g.once(u.CloseSurveyOnOverlayClick, T);
}, context: a, endCard: l, envId: window.UserLeap.envId, eventEmitFn: g.emit.bind(g), experimentFlags: n, fontFamily: window.UserLeap.fontFamily, fontFamilyURL: window.UserLeap.fontFamilyURL, forceBrandedLogo: o, frame: ce, headers: V, layout: y, locale: p, mobileSDKVersion: window.UserLeap.mobileSDKVersion, previewKey: Q.getItem("sprig.previewKey"), previewMode: b || !!window.previewMode, productConfig: { framePosition: h == null ? void 0 : h.framePosition, desktopDisplay: h == null ? void 0 : h.desktopDisplay, placement: h == null ? void 0 : h.placement }, quotaMessages: v, providerPersona: k, quotas: f, responseGroupUid: U, showProviderPersona: j, useBranding: oe ?? !0, startingQuestionIdx: (Ke = window.UserLeap.config) == null ? void 0 : Ke.startingQuestionIdx, studyType: ne, styleNonce: window.UserLeap.styleNonce, surveyId: S, tabTitle: document.title, trackPageViewUrl: e, ulEvents: se, upchunkLibraryURL: window.UserLeap.upchunkLibraryURL, useMobileStyling: Se, userId: M, viewDocument: R == null ? void 0 : R.document, viewWindow: R, visitorAttributes: { externalUserId: window.UserLeap.userId, email: window.UserLeap.email }, surveyVisitorAttributes: Pt || {}, ...window.UserLeap._config };
(Qe = window.UserLeap._config) != null && Qe.startingQuestionIdx && (window.UserLeap._config = { ...window.UserLeap._config, startingQuestionIdx: null });
const jt = (c ? window.UserLeap.feedbackCustomStyles : window.UserLeap.customStyles) ?? h.customStyles;
K.customStyles = jt, R && (R.__cfg = K);
const Te = window.UserLeap.viewSDKURL ? window.UserLeap.viewSDKURL : K.path, We = document.getElementById(tt);
We && We.remove();
const Ie = function() {
const T = document.createElement("script");
return window.UserLeap.isMobileSDK || T.setAttribute("type", "module"), window.UserLeap.nonce && T.setAttribute("nonce", window.UserLeap.nonce), T.id = tt, T;
}(), Ne = () => {
window.UserLeap.container && Object.assign(window.UserLeap.container.style, { display: "flex" });
};
if (K.installationMethod === "web-npm" || K.installationMethod === "web-npm-bundled") {
const { default: T } = await import("./view-CvoT_Cd7.js").then((W) => W.H);
T.configure(K), de && window.UserLeap.container && Ne();
} else Te && (Ie.src = `${Te}${window.UserLeap.isMobileSDK ? "" : `?t=${Date.now()}`}`, de && Ie.addEventListener("load", () => {
window.UserLeap.container && Ne();
}), R == null || R.addEventListener("error", (T) => {
T.target instanceof HTMLScriptElement && T.target.src === Te && window.UserLeap.reportError("loadFrameScript", new Error("Frame script failed to load"));
}, { capture: !0, once: !0 }));
Y == null || Y.appendChild(Ie);
const Be = { success: !0, surveyState: "ready", surveyId: S, responseGroupUid: U };
return window.UserLeap.isMobileSDK && t && (Be.delay = t), Be;
};
function Ue(r) {
var i;
if (window.UserLeap.useMobileStyling !== void 0) return window.UserLeap.useMobileStyling;
const e = ((i = window.UserLeap.windowDimensions) == null ? void 0 : i.width) ?? document.body.clientWidth;
return ae(r) || e > 10 && e < 500;
}
function ae(r) {
return $t.has(r["userleap-platform"]);
}
const rt = /* @__PURE__ */ new WeakMap(), Gt = (r, e) => {
try {
return ((a) => {
var n, o;
const t = rt.get(a);
if (t) return t;
if (!((n = a.trustedTypes) != null && n.createPolicy)) throw new Error("Trusted types not supported");
const s = (o = a.trustedTypes) == null ? void 0 : o.createPolicy("sprig-sdk", { createHTML: (l) => l, createScript: (l) => l, createScriptURL: (l) => l });
return rt.set(a, s), s;
})(e).createHTML(r);
} catch (i) {
return console.warn("Could not create TrustedHTML object", i), r;
}
}, qe = (r, e, i = window) => {
var a;
return e && ((a = i.trustedTypes) != null && a.createPolicy) ? Gt(r, i) : r;
}, Fe = "ul-frame";
globalThis.UserLeap && globalThis.Sprig && (globalThis.Sprig._gtm ? globalThis.Sprig = globalThis.UserLeap : globalThis.UserLeap = globalThis.Sprig), globalThis.UserLeap || (globalThis.UserLeap = globalThis.Sprig), globalThis.Sprig || (globalThis.Sprig = globalThis.UserLeap);
const _e = "0px", mt = (r, e, i) => {
globalThis.UserLeap.container = document.createElement("div"), globalThis.UserLeap.container.className = "ul-container" + (e ? " ul-container-feedback" : ""), r && (globalThis.UserLeap.container.dataset.studyId = r.toString());
const a = Lt();
i && a && !globalThis.UserLeap.useMobileStyling ? a.appendChild(globalThis.UserLeap.container) : document.body.appendChild(globalThis.UserLeap.container);
}, ft = (r, e) => {
var a;
Yt();
const i = globalThis.UserLeap.container;
if (i) try {
(a = i.parentNode) == null || a.removeChild(i), globalThis.UserLeap.container = null, E("trackStartUrl", null), g.emit(u.SurveyLifeCycle, { state: "dismissed" }), g.emit(u.SurveyClosed, { name: u.SurveyClosed, initiator: r, "survey.id": parseInt(i.dataset.studyId), ...e && { studyType: e } });
} catch (t) {
console.warn(`[Sprig] (ERR-412) Error removing UserLeap container by ${r} ` + i), t instanceof Error && globalThis.UserLeap.reportError("dismissActiveSurvey", t);
}
}, vt = () => {
g.once(u.SurveyWillClose, ({ initiator: r, studyType: e }) => {
g.removeAllListeners(u.CloseSurveyOnOverlayClick), ft(r, e);
});
}, Kt = (r, e, i, a) => {
var d, p;
const t = { position: "fixed", bottom: "0px", right: _e, border: 0, backgroundColor: "rgba(0,0,0,0)", zIndex: 2147483646, transition: "width 0.2s ease-in-out, height 0.2s ease-in-out", maxWidth: "100%" }, s = Object.assign({}, e, globalThis.UserLeap), { desktopDisplay: n } = e || {}, o = n === "center-modal";
let l;
o && (s.framePosition = "center");
let c = !1;
if (i) (d = globalThis.UserLeap.windowDimensions) != null && d.width ? t.width = `${globalThis.UserLeap.windowDimensions.width}px` : t.width = "100%", (p = globalThis.UserLeap.windowDimensions) != null && p.height ? t.maxHeight = globalThis.UserLeap.windowDimensions.height - 20 + "px" : globalThis.UserLeap.maxHeight ? t.maxHeight = globalThis.UserLeap.maxHeight : t.maxHeight = document.body.clientHeight - 20 + "px", ["light", "dark"].includes(s.overlayStyleMobile) && (c = !0);
else {
t.width = "360px", t.maxHeight = globalThis.UserLeap.maxHeight || "66vh";
const y = () => {
c = !0, l = { margin: "auto", position: "static" };
};
if (a) o ? y() : l = { position: "relative", height: "300px" };
else switch (s.framePosition) {
case "bottomLeft":
l = { left: _e };
break;
case "topLeft":
l = { left: _e, top: 0 };
break;
case "topRight":
l = { top: 0 };
break;
case "center":
y();
}
}
return c && ((y, b) => {
const h = { position: "fixed", overflow: "auto", top: "0px", left: "0px", display: "none", height: "100%", width: "100%", transition: "background-color 0.3s ease-out", zIndex: 2147483646 }, v = b ? y.overlayStyleMobile : y.overlayStyle;
h["background-color"] = v === "light" ? "rgba(255,255,255, 0.95)" : "rgba(0,0,0,0.9)", b || (h.margin = "auto"), globalThis.UserLeap.container && Object.assign(globalThis.UserLeap.container.style, h);
})(s, i), Object.assign(r.style, t, l), c;
}, Qt = ({ productConfig: r, useMobileStyling: e, surveyId: i, isFeedback: a, enableCspTrustedTypes: t }) => {
var b, h;
const s = Fe, n = a && r.desktopDisplay === "slider";
mt(i, a, n), Jt();
const o = document.createElement("iframe");
o.id = s, o.setAttribute("title", "Sprig User Feedback Dialog");
const l = Kt(o, r, e, a);
vt();
let c = !1;
o.setHeight = (v) => {
parseInt(o.style.height) == v && c || (c = !0, o.style.height = `${v}px`, g.emit(u.SurveyHeight, { name: u.SurveyHeight, contentFrameHeight: v, "survey.id": i }));
};
let d = !1;
o.setWidth = (v) => {
parseInt(o.style.width) == v && d || (d = !0, o.style.width = `${v}px`, g.emit(u.SurveyWidth, { name: u.SurveyWidth, contentFrameWidth: v, "survey.id": i }));
}, (b = globalThis.UserLeap.container) == null || b.appendChild(o), r && (e ? r.exitOnOverlayClickMobile : r.exitOnOverlayClick) && globalThis.UserLeap.container && (globalThis.UserLeap.container.onclick = () => {
g.emit(u.CloseSurveyOnOverlayClick);
}), g.emit(u.SurveyLifeCycle, { state: "presented" }), g.emit(u.SurveyPresented, { name: u.SurveyPresented, "survey.id": i });
const p = (h = o.contentWindow) == null ? void 0 : h.document;
if (p && (p.open("text/html", "replace"), p.write(qe("<!doctype html><head></head><body></body></html>", t, o.contentWindow)), p.close(), !e)) {
const v = p.body;
v.style.display = "flex", v.style.alignItems = "center";
}
const y = p == null ? void 0 : p.head;
return { frameId: s, contentWinDocHead: y, contentWindow: o.contentWindow, hasOverlay: l, iframe: o };
}, wt = { [u.SurveyFadingOut]: () => {
globalThis.UserLeap.container && Object.assign(globalThis.UserLeap.container.style, { "background-color": "rgba(0,0,0,0)" });
} }, Jt = () => {
Object.entries(wt).forEach(([r, e]) => {
g.on(r, e);
});
}, Yt = () => {
Object.entries(wt).forEach(([r, e]) => {
g.off(r, e);
});
}, q = (r) => !!r && r.nodeType === Node.ELEMENT_NODE, it = (r) => r instanceof HTMLElement || r instanceof SVGElement, ge = ({ document: r, elementId: e, styleString: i, nonce: a }) => {
const t = r.getElementById(e);
if (t) return void (t.textContent = i);
const s = r.createElement("style");
a && (s.nonce = a), s.textContent = i, s.id = e, r.head.appendChild(s);
}, st = (r, e) => {
const i = e.querySelector(r);
if (!q(i)) return 0;
const a = getComputedStyle(i);
return parseFloat(a.paddingLeft) + parseFloat(a.paddingRight) + (parseFloat(a.marginLeft) + parseFloat(a.marginRight)) + (parseFloat(a.borderLeftWidth) + parseFloat(a.borderRightWidth));
}, Xt = (r, e, i) => {
const a = r.querySelector(".ul-card__container"), t = r.querySelector(".ul-app");
let s = 600, n = 360;
if (q(a) && q(t)) {
const o = a.querySelector(".ul-card--matrix_grid"), l = !o && e && i;
try {
l && (t.style.width = "360px"), s = a.scrollHeight, s += ((p) => {
const y = p.querySelector(".sprig-question-body"), b = p.querySelector(".ul-card"), h = p.querySelector(".ul-card-main-content"), v = p.querySelector(".ul-footer"), k = p.querySelector(".sprig-container");
let f = 0;
return q(b) && (f += b.scrollHeight - b.clientHeight), q(h) && (f += h.scrollHeight - h.clientHeight), q(y) && (f += y.scrollHeight - y.clientHeight), q(v) && q(k) && k.clientHeight === 0 && (f += v.clientHeight), f;
})(r);
const c = getComputedStyle(a), d = parseFloat(c.marginTop) + parseFloat(c.marginBottom);
s += d + (parseFloat(c.borderTopWidth) + parseFloat(c.borderBottomWidth)), o && (n = o.scrollWidth, n += st(".ul-card__container", r), n += st(".sprig-question-body", r));
} finally {
l && t.style.removeProperty("width");
}
}
return [s + 2, n];
}, Sr = (r) => {
const e = r.querySelector(".ul-card__container");
e && (e.scrollTop = 0);
}, Lt = () => m, J = () => document.getElementById("sprig-feedback-container"), Ae = () => document.getElementById("sprig-feedback-loading-animation"), Ut = () => !!document.getElementById(Fe);
let at = !1, m = null, A = null, He = !1, te = null, B = null;
const Zt = ["bottom-left", "bottom-right", "center-left", "center-right"], he = () => {
var e;
const r = window.UserLeap.container;
return ((e = r == null ? void 0 : r.parentElement) == null ? void 0 : e.id) === "sprig-feedback-loading-container";
}, St = () => document.getElementById("sprig-feedback-error-container"), Tt = () => {
if (!m) return 0;
const r = m == null ? void 0 : m.clientWidth, e = window.getComputedStyle(m);
return r + parseInt(e.borderRightWidth || "0") + parseInt(e.borderLeftWidth || "0");
}, ye = (r) => {
const e = J();
e && (B != null && B.endsWith("right") ? e.style.right = `${r}px` : B != null && B.endsWith("left") && (e.style.left = `${r}px`));
}, Re = () => {
if (m && (he() || St())) {
g.off(u.SurveyAppeared, Z), Oe();
const r = Tt();
return ye(-r), !0;
}
return !1;
}, Z = () => {
if (!m || !A) return;
const r = Ae();
r && r.remove(), m.style.height = "auto", m.style.width = "auto", A.disabled = !1, He = !1;
}, Oe = () => {
if (m && !Ae()) {
const r = (() => {
var i;
if (Ae()) return;
const e = document.createElement("div");
return e.className = "ul-loading-spinner-container", e.id = "sprig-feedback-loading-animation", e.role = "progressbar", e.setAttribute("aria-live", "polite"), e.setAttribute("aria-busy", "true"), e.setAttribute("aria-label", "Processing..."), e.innerHTML = qe(`
<div class="ul-loading-spinner">
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
<div class="fourth"></div>
</div>
`, (i = window.UserLeap._config) == null ? void 0 : i.enableCspTrustedTypes), e;
})();
r && (m.style.height = "300px", m.style.width = "360px", m.appendChild(r));
}
}, ot = () => {
m && A && (ye(0), A.disabled = !0, He = !0);
}, It = async (r, e, i) => {
const { buttonTheme: a, customStyles: t, eventId: s, placement: n, desktopDisplay: o, feedbackLabel: l, surveyUuid: c, surveyId: d } = r;
window.UserLeap.feedbackCustomStyles = void 0;
let p = J();
if (p) {
if (!e && s === te) return;
p.remove(), g.off(se.SURVEY_FADING_OUT, Re);
}
te = s, ge({ document, elementId: "sprig-feedback-style", styleString: '.ul-loading-spinner-container{font-size:1.8rem;flex-grow:1;width:100%;height:100%;display:flex;align-items:center;justify-content:center}.ul-loading-spinner{display:inline-block;position:relative;width:6rem;height:6rem}.ul-loading-spinner div{box-sizing:border-box;display:block;position:absolute;width:80%;height:80%;margin:5px;border:5px solid #152e3e;border-radius:50%;animation:lds-ring 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:#152e3e transparent transparent transparent}.ul-loading-spinner .first{animation-delay:-.45s}.ul-loading-spinner .second{animation-delay:-.3s}.ul-loading-spinner .third{animation-delay:-.15s}@keyframes lds-ring{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.fade-in-transition{animation:fadeIn .4s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}#sprig-feedback-button{border-left:0;border-radius:0 8px 8px 0;display:grid;padding:8px;text-align:center;transition:all ease-in-out 1s;z-index:inherit}#sprig-feedback-button:hover{cursor:pointer}.sprig-feedback-button-label{writing-mode:vertical-lr;text-orientation:sideways}.sprig-feedback-button-right{transform:rotate(180deg)}.sprig-feedback-button-bottom{align-self:flex-end;margin-bottom:20px}.sprig-feedback-button-light{background:#efefee;color:#000;border:1px solid #e2e3e1}.sprig-feedback-button-dark{background:#000;color:#fff;border:1px solid #000000}#sprig-feedback-container{display:flex;align-items:center;position:fixed;transition:right .2s linear,left .2s linear;z-index:2147483646}.sprig-feedback-container-left{flex-flow:row-reverse}.sprig-feedback-container-center{top:50%;transform:translateY(-50%)}.sprig-feedback-container-bottom{bottom:0%;margin-bottom:15px}.sprig-feedback-loading-container{align-items:center;background-color:#fff;border:2px solid var(--feedback-border);display:flex;max-height:90vh;max-width:90vw;min-width:0px}.sprig-feedback-loading-container-left{border-left:none;border-radius:0 8px 8px 0}.sprig-feedback-loading-container-right{border-right:none;border-radius:8px 0 0 8px}#sprig-feedback-error-container{margin:auto;text-align:center;width:360px}.sprig-feedback-error-text{font-weight:400;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol}#sprig-feedback-loading-container .ul-container{position:relative;max-height:inherit}#sprig-feedback-loading-animation{position:absolute}.sprig-feedback-loading-container-previews iframe{max-height:inherit!important}', nonce: window.UserLeap.styleNonce }), ge({ document, elementId: "ul-custom-style", styleString: t ?? "", nonce: window.UserLeap.styleNonce }), at = o === "center-modal", B = n;
const [y, b] = n.split("-");
((f) => {
if (J() || !Zt.includes(f)) return;
const [w, U] = f.split("-"), S = document.createElement("div");
S.id = "sprig-feedback-container", S.classList.add(`sprig-feedback-container-${U}`, `sprig-feedback-container-${w}`), document.body.appendChild(S);
})(n), p = J(), A = document.createElement("button");
const h = document.createElement("div");
h.className = "sprig-feedback-button-label", h.innerText = l, A.appendChild(h), A.id = "sprig-feedback-button", A.classList.add(`sprig-feedback-button-${b}`, `sprig-feedback-button-${y}`, `sprig-feedback-button-${a}`, "fade-in-transition"), g.on(se.SURVEY_FADING_OUT, Re), A.addEventListener("click", async () => {
const f = document.getElementById("sprig-feedback-error-container");
if (Ut() || St()) {
if (Re()) {
g.emit(u.SurveyCloseRequested, { name: u.SurveyCloseRequested, initiator: C.FeedbackClosed, studyType: "feedbackButton", "survey.id": d }), g.emit(u.SurveyWillClose, { name: u.SurveyWillClose, initiator: C.FeedbackClosed, studyType: "feedbackButton", "survey.id": d });
const U = J();
f && U && (U.remove(), te = null, m = null);
}
return;
}
if (Ue(O(window.UserLeap)) || He || ot(), e) return m && m.classList.add("sprig-feedback-loading-container-previews"), await ee(e), void Z();
const w = await (async (U) => {
const S = await D(x("1", [F], "startFeedbackStudy"), { body: JSON.stringify({ surveyUuid: U }), method: "POST" });
return S.ok ? S.json : null;
})(c);
if (w) g.once(u.SurveyAppeared, Z), ee({ ...w, studyType: "feedbackButton" }, i);
else if (m) {
const U = er();
m.appendChild(U), Z(), m.style.height = "300px", m.style.width = "360px";
}
}), p == null || p.appendChild(A), g.emit(u.FeedbackButtonLoaded, { name: u.FeedbackButtonLoaded, "survey.id": d });
const { useMobileStyling: v, _config: { border: k } } = window.UserLeap;
if (at || v) ye(0);
else {
const f = document.createElement("div");
f.id = "sprig-feedback-loading-container", f.className = `sprig-feedback-loading-container sprig-feedback-loading-container-${b}`, f.style.setProperty("--feedback-border", k), m = f, Oe(), p == null || p.appendChild(f);
const w = Tt();
ye(-w);
}
window.UserLeap._config.isOnQuestionsTab && e && !he() && m && (ot(), Oe(), m && m.classList.add("sprig-feedback-loading-container-previews"), ee(e), Z());
}, er = () => {
var i;
const r = document.createElement("div");
r.id = "sprig-feedback-error-container", r.innerHTML = qe(`<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" fill="none">
<circle cx="20" cy="20" r="14.5" stroke="#B0B5B7" stroke-width="3"/>
<path d="M20 12L20 21.6" stroke="#B0B5B7" stroke-width="3" stroke-linecap="round"/>
<circle cx="19.9984" cy="27.6" r="1.6" fill="#B0B5B7"/>
</svg>`, (i = window.UserLeap._config) == null ? void 0 : i.enableCspTrustedTypes);
const e = document.createElement("h3");
return e.className = "sprig-feedback-error-text", e.innerText = "There was an error while loading the survey", r.appendChild(e), r;
}, Ce = new class {
constructor() {
N(this, "_ldData", {});
}
getAllLaunchDarklyVariations() {
return this._ldData;
}
setLDFlagsVariations(r) {
try {
return !(!r || typeof r != "object" || Array.isArray(r)) && (Object.keys(this._ldData).forEach((e) => {
delete this._ldData[e];
}), Object.keys(r).forEach((e) => this._ldData[`!launch_darkly_${e}`] = (r[e] ?? 0) + 1), !0);
} catch (e) {
return e instanceof Error && window.UserLeap.reportError("setAllLDFlagsVariations", e), console.warn("[Sprig] An issue had occured when setting LaunchDarkly flags and variations."), !1;
}
}
}();
Object.freeze(Ce);
const ue = new class {
constructor() {
N(this, "_optimizelyData", {});
}
setOptimizelyExperiment(r, e = !0) {
if (!r || typeof r != "object") return !1;
const { experiments: i } = r;
try {
return e && Object.keys(this._optimizelyData).map((a) => {
delete this._optimizelyData[a];
}), i && i.map((a) => {
const { id: t, variation: s } = a, n = this.transformExperimentId(t);
s && typeof s == "string" && (this._optimizelyData[n] = s);
}), !0;
} catch (a) {
return a instanceof Error && window.UserLeap.reportError("setOptimizelyExperiment", a), !1;
}
}
getAllOptimizelyExperiments() {
return this._optimizelyData;
}
getOptimizelyVariationName(r) {
return this._optimizelyData[this.transformExperimentId(r)];
}
transformExperimentId(r) {
return "!optimizely_experiments_" + r;
}
getAndSetWebOptimizelyExperiments() {
var r;
try {
if (window && window.optimizely && typeof window.optimizely.get == "function") {
const e = (r = window.optimizely.get("state")) == null ? void 0 : r.getExperimentStates({ isActive: !0 });
if (e) {
const i = Object.keys(e).map((a) => {
var t, s;
return (t = e[a].variation) != null && t.name ? { id: a, variation: (s = e[a].variation) == null ? void 0 : s.name } : { id: a, variation: "Original" };
});
return this.setOptimizelyExperiment({ experiments: i }, !1), !0;
}
return !1;
}
return !1;
} catch (e) {
return e instanceof Error && window.UserLeap.reportError("getAndSetWebOptimizely", e), !1;
}
}
}();
Object.freeze(ue);
class tr {
constructor(e, i) {
N(this, "paused");
N(this, "queue");
N(this, "ul");
this.ul = e, this.paused = !1, this.queue = [], this.flush(i);
}
flush(e) {
const i = e.length;
if (i) for (let a = 0; a < i; a++) this.push(e[a]);
}
isPaused() {
return this.paused;
}
pause() {
this.paused = !0;
}
unpause() {
this.paused = !1;
const e = this.queue.slice();
this.empty(), this.flush(e);
}
push(e) {
if (this.paused) this.queue.push(e);
else if (e instanceof Function) e();
else {
const i = Array.prototype.slice.call(e, 1), a = e[0], t = this.ul[a];
t instanceof Function ? t.apply(this.ul, i) : a && console.warn("[Sprig] (ERR-100) No valid UserLeap action called", a);
}
}
perform(e) {
if (this.paused) {
let i = () => {
};
const a = new Promise(function(t) {
i = function() {
t(e());
};
});
return this.queue.push(i), a;
}
return e();
}
empty() {
this.queue.length = 0;
}
}
let kt, Et;
const Pe = (r) => {
let e = 0, i = r.firstElementChild;
for (; i; ) e += Pe(i), i.shadowRoot && (e += Pe(i.shadowRoot)), i = i.nextElementSibling, e++;
return e;
}, nt = () => {
kt.report(Pe(document.body)), Et.report(document.documentElement.innerHTML.toString().length);
}, Me = (r, e) => {
const i = performance.now();
document.hidden ? setTimeout(() => Me(r, e), r) : setTimeout(() => {
const a = performance.now() - i;
e.report(a / 1e3), setTimeout(() => Me(r, e), r);
}, 0);
};
let be, me, fe, ve, lt, $ = {};
const pe = (r, e = 1) => {
const { name: i } = r;
$[i] = ($[i] || 0) + e;
}, _t = (r) => {
let e = 1;
return r.childNodes.forEach((i) => {
e += _t(i);
}), e;
}, dt = (r) => {
let e = 0;
return r.forEach((i) => {
e += _t(i);
}), e;
}, rr = (r) => {
switch (r.type) {
case "childList":
return pe(be, dt(r.addedNodes)), void pe(me, dt(r.removedNodes));
case "attributes":
return void pe(fe);
case "characterData":
return void pe(ve);
}
}, ir = (r) => r.forEach(rr), sr = () => {
be.report($[be.name] || 0), me.report($[me.name] || 0), fe.report($[fe.name] || 0), ve.report($[ve.name] || 0), $ = {};
}, ar = (r = 1e3) => {
be = G("sdk_mutations_nodes_added"), me = G("sdk_mutations_nodes_removed"), fe = G("sdk_mutations_attributes_changed"), ve = G("sdk_mutations_character_data"), lt = new MutationObserver(ir), lt.observe(document, { attributes: !0, attributeOldValue: !0, characterData: !0, characterDataOldValue: !0, childList: !0, subtree: !0 }), setInterval(sr, r);
}, or = ({ isWeb: r, reportingIntervalSeconds: e, thresholds: i, postMetrics: a }) => {
zt(i, (t, s) => {
var n, o;
if ((n = I.replay) != null && n.isReplayRecording()) {
const l = `Value: ${t} on ${s.metric} violated threshold of ${s.type} ${s.value}`;
(o = I.replay) == null || o.disableRecording("Threshold violated", new Error(l), { reportError: !1 }), window.UserLeap.reportError("Sdk Performance Metric threshold violated", new Error("Sdk Performance Metric threshold violated"), { metricName: s.metric, type: s.type, value: s.value }, { metricName: s.metric }), Wt();
}
}), Vt({ reportingIntervalSeconds: e, postMetrics: a }), r && (((t = 1e3) => {
const s = G("sdk_event_queue_latency_seconds");
Me(t, s);
})(), ((t = 1e4) => {
kt = G("sdk_dom_nodes_count"), Et = G("sdk_page_html_characters"), nt(), setInterval(nt, t);
})(), ar());
}, nr = "test", lr = ["popState", "pushState", "replaceState"];
let ze, re;
const we = {}, X = "!email", Rt = "pageUrl";
var pt;
let xe = ((pt = globalThis.location) == null ? void 0 : pt.href) || "";
function ie(r) {
var o, l;
const { pageUrlEvents: e, interactiveEvents: i, dismissOnPageChange: a, platform: t } = globalThis.UserLeap._config;
if (t && t !== "web") return;
xe !== globalThis.location.href && P.navigation("LocationChange", { from: xe, to: globalThis.location.href }), xe = globalThis.location.href;
const s = At().trackStartUrl, n = s ? String(s) : null;
e && Ct(globalThis.location.href), i && (Dt(), dr()), Lt() && (() => {
if (he()) return;
const c = J();
c && (Ht(te) || (c.remove(), te = null, m = null));
})(), Q.getItem("sprig.isCapturingHeatmap") && ((l = (o = I.replay) == null ? void 0 : o.checkPendingHeatmapsUrl()) == null || l.then((c) => {
var d;
c && ((d = I.replay) == null || d.uploadReadyPendingCaptures(!0));
})), !he() && a && n && n !== globalThis.location.href && r && lr.includes(r.type) && globalThis.UserLeap("dismissActiveSurvey", C.PageChange);
}
const xt = { capture: !0 }, dr = () => {
const r = globalThis.UserLeap._config.interactiveEvents.filter((i) => yt(i, globalThis.location.href)).map((i) => {
const { name: a, properties: t } = i, { selector: s, innerText: n } = t;
return s ? (o) => {
if (it(o.target)) try {
o.target.closest(s) && globalThis.UserLeap("track", a);
} catch {
}
return !1;
} : (o) => (it(o.target) && o.target.innerText === n && globalThis.UserLeap("track", a), !1);
}), e = (i) => r.forEach((a) => a(i));
globalThis.UserLeap._config.interactiveEventsHandler = e, globalThis.addEventListener("click", e, xt);
}, Dt = () => {
globalThis.UserLeap._config.interactiveEventsHandler && globalThis.removeEventListener("click", globalThis.UserLeap._config.interactiveEventsHandler, xt), delete globalThis.UserLeap._config.interactiveEventsHandler;
};
function At() {
const r = z.getItemObject("userleap.ids");
return (r == null ? void 0 : r[globalThis.UserLeap.envId]) || {};
}
function Ot() {
if (globalThis.previewMode) return;
const r = z.getItemObject("sprig.anon.env.vid.map") || {}, e = r[globalThis.UserLeap.envId];
globalThis.UserLeap.visitorId = e || gt(), P.info("NewVid", { vid: globalThis.UserLeap.visitorId }), E("vid", globalThis.UserLeap.visitorId), e || (r[globalThis.UserLeap.envId] = globalThis.UserLeap.visitorId, z.setItemObject("sprig.anon.env.vid.map", r)), g.emit(u.VisitorIDUpdated, { visitorId: globalThis.UserLeap.visitorId });
}
function Ct(r, e, i, a) {
var t, s;
try {
if (r.endsWith("mock_snippet.html")) return;
P.info("PageView", { url: r });
const n = (t = document == null ? void 0 : document.querySelector('meta[name="description"]')) == null ? void 0 : t.getAttribute("content");
(s = I.replay) == null || s.RecordPageView({ ...n && { description: n }, url: r, referrer: document.referrer, pageTitle: document.title });
const o = globalThis.UserLeap._config.pageUrlEvents;
let l = !1;
if (o && o.length) for (let d = 0; d < o.length && (l = yt(o[d], r), !l); d++) ;
if (!l) return;
globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig trackPageView", r);
const c = { url: r };
a && (c.trackPageView = !0), globalThis.UserLeap._queue.push(["track", Rt, e, c, i]);
} catch (n) {
n instanceof Error && (n.stack = r, globalThis.UserLeap.reportError("trackPageView", n)), console.warn("[Sprig] (ERR-428) Failed to track page view", n);
}
}
function cr() {
var e;
const r = ((e = globalThis.Backbone) == null ? void 0 : e.history) || globalThis.history;
"pushState" in r && (r.pushState = /* @__PURE__ */ ((i) => function(...a) {
const t = i.apply(this, a), s = new Event("pushState");
return globalThis.dispatchEvent(s), ie(s), t;
})(r.pushState)), "replaceState" in r && (r.replaceState = /* @__PURE__ */ ((i) => function(...a) {
const t = i.apply(this, a), s = new Event("replaceState");
return globalThis.dispatchEvent(s), ie(s), t;
})(r.replaceState)), ["hashchange", "popstate"].forEach((i) => globalThis.addEventListener(i, ie, !0));
}
async function De(r, e) {
const i = je();
r && !e && (globalThis.UserLeap._config.mode = nr);
const a = Ue(O(globalThis.UserLeap)), t = await D(function(s) {
const n = new URL(x("1", [H], "questions"));
return Object.entries(s || {}).forEach(([o, l]) => {
l && n.searchParams.append(o, String(l));
}), n.toString();
}({ desktopDisplay: globalThis.UserLeap._config.desktopDisplay, isMobile: a, previewLanguage: globalThis.UserLeap._config.previewLanguage, surveyid: r == null ? void 0 : r.surveyId, surveytemplateid: r == null ? void 0 : r.surveyTemplateId, vid: i }), { shouldDropOnRateLimit: !0 });
if (!t.ok) return t.reportError && t.error && (console.warn("[Sprig] (ERR-414) Failed to request questions from the server", t.error), globalThis.UserLeap.reportError("getQuestions", t.error)), { success: !1, surveyState: "no survey" };
if (t.json.delay && await bt(t.json.delay), !t.json.isFeedback) return ee(t.json, re, ze);
{
const { feedbackLabel: s, productConfig: n, surveyUuid: o, feedbackCustomStyles: l } = t.json, { buttonTheme: c, placement: d, desktopDisplay: p } = n;
It({ customStyles: l, buttonTheme: c, desktopDisplay: p, eventId: 0, feedbackLabel: s, placement: d, surveyUuid: o, surveyId: r == null ? void 0 : r.surveyId }, t.json);
}
}
function pr(r) {
if (!r) return;
globalThis.UserLeap._config = r, r.mute && globalThis.UserLeap._queue.pause();
const { interactiveEvents: e, pageUrlEvents: i, dismissOnPageChange: a } = r;
e && function(t) {
let s = t.length;
for (; s; ) {
const n = Math.floor(Math.random() * s);
s -= 1;
const o = t[s];
t[s] = t[n], t[n] = o;
}
}(e), (e || i || a) && (cr(), ie());
}
const ur = function(r) {
if (!globalThis.UserLeap) return;
const e = async (t = {}) => {
var f, w, U, S, M;
const { userId: s, anonymousId: n, metadata: o = {}, properties: l, showSurveyCallback: c } = t;
let { eventName: d } = t;
if (globalThis.UserLeap.debugMode && d !== Rt && console.info("[DEBUG] Sprig track", t), r.mode === "test") return;
const p = Q.getItem("sprig.previewKey") ?? void 0;
if (r.requireUserIdForTracking && !globalThis.UserLeap.userId && !s) {
const L = "[Sprig] - Skipping tracking without userId";
return console.warn(L), { success: !1, message: L, surveyState: "no survey" };
}
if (!d || d.trim().length === 0) {
d = d ? String(d) : "";
const L = "[Sprig] - Invalid event name " + d;
return console.warn(L), { success: !1, message: L, surveyState: "no survey" };
}
const y = re ?? globalThis.location.href;
o.url || (o.url = y), E("trackStartUrl", y), (w = (f = globalThis.UserLeap) == null ? void 0 : f._config) != null && w.optimizelyEnabled && (ae(O(globalThis.UserLeap)) || ue.getAndSetWebOptimizelyExperiments(), o.optimizelyExperiments = Object.assign({}, ue.getAllOptimizelyExperiments())), (S = (U = globalThis.UserLeap) == null ? void 0 : U._config) != null && S.launchDarklyEnabled && (o.launchDarklyFlags = Ce.getAllLaunchDarklyVariations()), s && (globalThis.UserLeap.userId = s), n && (globalThis.UserLeap.partnerAnonymousId = n), l && (o.eventProperties = l), (M = I.replay) == null || M.RecordEvent({ name: d, url: o.url }), P.info("TrackEvent", { eventName: d });
const b = globalThis.UserLeap.delayingSurvey || Ut() ? await D(x("1", [F], "events/batch"), { body: JSON.stringify({ events: [{ event: d, metadata: o }], previewKey: p }), method: "POST", shouldDropOnRateLimit: !0 }) : await D(x("1", [F], "events"), { body: JSON.stringify({ event: d, metadata: o, previewKey: p }), method: "POST", shouldDropOnRateLimit: !0 });
if (!b.ok) {
const L = "[Sprig] (ERR-421) Failed to track event";
return b.reportError && (console.warn(L, b.error), b.error && globalThis.UserLeap.reportError("track", b.error)), { success: !1, message: L, error: b.error, surveyState: "no survey" };
}
s && E("uid", s), n && E("aid", n);
const h = b.json;
h.invalidPreviewKey && Q.removeItem("sprig.previewKey");
const v = o.trackPageView ? o.url : void 0;
return h != null && h.feedbackButton && It(h.feedbackButton, void 0, v), await async function(L, _) {
var oe, ne;
let j = !0;
return !(_ && ((oe = L == null ? void 0 : L.json) != null && oe.surveyId) && (globalThis.UserLeap.delayingSurvey = !0, j = await _(L.json.surveyId), globalThis.UserLeap.delayingSurvey = !1, !j)) && ((ne = L == null ? void 0 : L.json) != null && ne.delay && !globalThis.UserLeap.isMobileSDK && (globalThis.UserLeap.delayingSurvey = !0, await bt(L.json.delay), globalThis.UserLeap.delayingSurvey = !1), j);
}(b, c) ? function(L) {
if (!globalThis.UserLeap._config.dismissOnPageChange) return !0;
const _ = new URL(L), j = new URL(re ?? globalThis.location.href);
return _.hostname === j.hostname && _.pathname === j.pathname;
}(y) ? ee(h, v, ze) : { success: !1, message: "Study should not be displayed after page navigation", surveyState: "no survey" } : { success: !1, message: "[Sprig] Callback returned false, aborting rendering of survey", surveyState: "no survey" };
}, i = (t, s) => {
var o;
const n = (o = t == null ? void 0 : t.querySelector(`[id="${Fe}"]`)) == null ? void 0 : o.contentDocument;
n && ge({ document: n, elementId: "ul-custom-style", styleString: s });
}, a = { displaySurvey: async (t) => (console.warn("[Sprig] displaySurvey should only be used to debug your studies; not intended for production usage."), globalThis.UserLeap("dismissActiveSurvey", C.Override), De({ surveyId: t }, !0)), _previewSurvey(t) {
globalThis.UserLeap("dismissActiveSurvey", C.Override), De({ surveyTemplateId: t }, !1);
}, _reviewSurvey(t) {
globalThis.UserLeap("dismissActiveSurvey", C.Override), De({ surveyId: t }, !1);
}, previewSurvey(t) {
a._previewSurvey(t);
}, reviewSurvey(t) {
a._reviewSurvey(t);
}, mute() {
globalThis.UserLeap._queue.pause();
}, unmute() {
globalThis.UserLeap._queue.unpause();
}, setVisitorToken() {
console.warn("[Sprig] setVisitorToken is deprecated.");
}, dismissActiveSurvey(t = C.API) {
globalThis.UserLeap.container && (t === C.Closed && globalThis.Sprig.trackHistory && globalThis.Sprig.trackHistory({ event: "closed" }), g.emit(u.SurveyCloseRequested, { name: u.SurveyCloseRequested, initiator: t, "survey.id": parseInt(globalThis.UserLeap.container.dataset.studyId) }), g.emit(u.SurveyWillClose, { name: u.SurveyWillClose, initiator: t, "survey.id": parseInt(globalThis.UserLeap.container.dataset.studyId) }));
}, async setAttribute(t, s) {
if (!t || !s && s !== 0 && s !== !1) {
const n = "[Sprig] - Disregarding empty attribute / value provided";
return console.warn(n), { success: !1, message: n };
}
return this.setAttributes({ [t]: s });
}, async setAttributes(t) {
if (t == null || Object.keys(t).length === 0) {
const s = "[Sprig] - Disregarding empty attributes provided";
return console.warn(s), { success: !1, message: s };
}
return this.identifyAndSetAttributes({ attributes: t });
}, async identifyAndSetAttributes(t) {
if (globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig identifyAndSetAttributes", t), r.mode === "test") return;
if (t === null || typeof t != "object" || !(t.userId || t.anonymousId || t.attributes)) {
const d = "[Sprig] - Disregarding empty payload provided";
return console.warn(d), { success: !1, message: d };
}
const { userId: s, anonymousId: n, attributes: o } = t;
if (r.requireUserIdForTracking && !globalThis.UserLeap.userId && !s) {
const d = "[Sprig] - Skipping tracking without userId";
return console.warn(d), { success: !1, message: d };
}
if (o) {
o.email && !o[X] && (o[X] = o.email, delete o.email);
const d = Object.keys(o);
for (const p of d) o[p] === we[p] && delete o[p];
}
if (!(o && Object.keys(o).length !== 0 || s && globalThis.UserLeap.userId !== s || n && globalThis.UserLeap.partnerAnonymousId !== n)) return { success: !0 };
const l = {};
let c;
return s && (l.userId = globalThis.UserLeap.userId = s), n && (l.partnerAnonymousId = globalThis.UserLeap.partnerAnonymousId = n), o && Object.keys(o).length > 0 ? (c = await D(x("1", [H, F], "attributes"), { body: JSON.stringify(o), method: "PUT" }), c.ok ? Object.assign(we, o) : c.reportError && (console.warn("[Sprig] (ERR-432) identifyAndSetAttributes failed", c.error), c.error && globalThis.UserLeap.reportError("identifyAndSetAttributes", c.error))) : c = await D(x("1", [H, F]), { body: JSON.stringify(l), method: "PUT" }), o && o[X] && (globalThis.UserLeap.email = o[X]), c.ok && (s && E("uid", s), n && E("aid", n)), { success: !!c.ok };
}, async removeAttributes(t) {
if (globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig removeAttributes", t), r.mode === "test") return;
if (t == null || t.length === 0) {
const n = "[Sprig] - Disregarding empty attributes provided";
return console.warn(n), { success: !1, message: n };
}
if (r.requireUserIdForTracking && !globalThis.UserLeap.userId) {
const n = "[Sprig] - Skipping tracking without userId";
return console.warn(n), { success: !1, message: n };
}
const s = await D(x("1", [H, F], "attributes"), { body: JSON.stringify({ delete: t }), method: "DELETE" });
return !s.ok && s.reportError && (console.warn("[Sprig] (ERR-433) Remove attributes failed", s.error), s.error && globalThis.UserLeap.reportError("removeAttributes", s.error)), { success: !!s.ok };
}, async addSurveyListener(t) {
g.on(u.SurveyLifeCycle, t);
}, async removeSurveyListener(t) {
g.removeListener(u.SurveyLifeCycle, t);
}, async addListener(t, s) {
g.on(t, s);
}, async removeListener(t, s) {
g.removeListener(t, s);
}, async removeAllListeners() {
g.removeAllListeners();
}, setPreviewKey(t) {
t && typeof t == "string" && Q.isStorageAvailable && t && Q.setItem("sprig.previewKey", t);
}, async setUserId(t) {
var o;
if (globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig setUserId", t), t == null) {
const l = `[Sprig] - Invalid userId ${t}`;
return console.warn(l), { success: !1, message: l };
}
if (r.mode === "test" || t === globalThis.UserLeap.userId) return;
globalThis.UserLeap.userId = t;
const s = globalThis.UserLeap.visitorId, n = await D(x("1", [H, F]), { body: JSON.stringify({ userId: t }), method: "PUT" });
n.ok ? (s !== globalThis.UserLeap.visitorId && ((o = I.replay) == null || o.clearUserReplayData()), E("uid", t)) : n.reportError && (console.warn("[Sprig] (ERR-420) Failed to set user id", n.error), n.error && globalThis.UserLeap.reportError("setUserId", n.error));
}, async setPartnerAnonymousId(t) {
if (globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig setPartnerAnonymousId", t), t == null) {
const s = `[Sprig] - Invalid partnerAnonymousId ${t}`;
return console.warn(s), { success: !1, message: s };
}
return globalThis.UserLeap.partnerAnonymousId = t, E("aid", t), { success: !0 };
}, track: async (t, s, n = {}, o = void 0) => e({ eventName: t, properties: s, metadata: n, showSurveyCallback: o }), identifyAndTrack: async (t) => await e(t), trackPageView(t, s = void 0, n = void 0, o = !0) {
re = t, Ct(t, s, n, o);
}, applyFeedbackStyles({ button: t = "", view: s = "" }) {
globalThis.UserLeap.feedbackCustomStyles = s, document.getElementById("sprig-feedback-style") && ge({ document, elementId: "ul-custom-style", styleString: t, nonce: globalThis.UserLeap.styleNonce }), i(document.querySelector(".ul-container-feedback"), s);
}, applyStyles(t) {
globalThis.UserLeap.customStyles = t, i(globalThis.UserLeap.container, t);
}, setWindowDimensions(t, s) {
var y, b;
const n = typeof t == "string" ? parseInt(t, 10) : t, o = typeof s == "string" ? parseInt(s, 10) : s;
isNaN(n) || isNaN(o) || (globalThis.UserLeap.windowDimensions = { width: n, height: o });
const l = O(globalThis.UserLeap), c = Ue(l), d = l["userleap-platform"] === "web";
if (!globalThis.UserLeap.frameId) return;
const p = document.getElementById(globalThis.UserLeap.frameId);
p && (globalThis.UserLeap.useMobileStyling && ((y = globalThis.UserLeap.windowDimensions) != null && y.width && (p.style.width = `${globalThis.UserLeap.windowDimensions.width}px`), (b = globalThis.UserLeap.windowDimensions) != null && b.height && (p.style.maxHeight = globalThis.UserLeap.windowDimensions.height - 20 + "px"), p.contentDocument && (p.style.height = String(Xt(p.contentDocument, d && !c, ht(l))[0]) + "px")), g.emit(u.SurveyDimensions, { name: u.SurveyDimensions, contentFrameWidth: p.clientWidth, contentFrameHeight: p.clientHeight, "survey.id": parseInt(globalThis.UserLeap.container.dataset.studyId) }));
}, logoutUser() {
var t;
globalThis.UserLeap.debugMode && console.info("[DEBUG] Sprig logout"), P.info("LogOut", { vid: globalThis.UserLeap.visitorId, userId: globalThis.UserLeap.userId }), globalThis.UserLeap