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