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