@qwik.dev/core
Version:
An open source framework for building instant loading web apps at any scale, without the extra effort.
73 lines (72 loc) • 2.92 kB
JavaScript
import { sync$ as k, component$ as L, isDev as R } from "@qwik.dev/core";
import { jsx as $ } from "@qwik.dev/core/jsx-runtime";
const Q = k(
() => ((o, i, S, c, g, l, b) => {
var y = __QI_KEY__, h = __QI_URL__, w = i.querySelector("[q\\:version]")?.getAttribute("q:version") || "unknown", d = i.querySelector("[q\\:manifest-hash]")?.getAttribute("q:manifest-hash") || "dev", s = [], f = /* @__PURE__ */ new Set(), r = 0, q = 0, a, v = g.now(), m = i.querySelector("[q\\:route]"), p = () => {
if (a = void 0, s.length > r) {
var t = {
qVersion: w,
publicApiKey: y,
manifestHash: d,
previousSymbol: r == 0 ? void 0 : s[r - 1].symbol,
symbols: s.slice(r)
};
c.sendBeacon(h, b(t)), r = s.length;
}
}, T = () => {
a != null && clearTimeout(a), a = setTimeout(p, 1e3);
};
o.qSymbolTracker = {
symbols: s,
publicApiKey: y
}, m && new MutationObserver((t) => {
var e = t.find((n) => n.attributeName === "q:route");
e && (v = g.now());
}).observe(m, { attributes: !0 }), i.addEventListener("visibilitychange", () => i.visibilityState === "hidden" && p()), i.addEventListener("qsymbol", (t) => {
var e = t, n = e.detail, u = n.reqTime, I = e.timeStamp, _ = n.symbol;
if (!f.has(_)) {
f.add(_);
var E = m?.getAttribute("q:route") || "/";
s.push({
symbol: _,
route: E,
delay: l(0 - q + u),
latency: l(I - u),
timeline: l(0 - v + u),
interaction: !!n.element
}), q = I, T();
}
}), o.addEventListener("error", (t) => {
var e = t.error;
if (e && typeof e == "object") {
var n = {
url: `${S}`,
manifestHash: d,
timestamp: (/* @__PURE__ */ new Date()).getTime(),
source: t.filename,
line: t.lineno,
column: t.colno,
message: t.message,
error: "message" in e ? e.message : `${e}`,
stack: "stack" in e && e.stack || ""
};
c.sendBeacon(`${h}error/`, b(n));
}
});
})(window, document, location, navigator, performance, Math.round, JSON.stringify)
), N = L(() => {
if (!__EXPERIMENTAL__.insights)
throw new Error(
'Insights is experimental and must be enabled with `experimental: ["insights"]` in the `qwikVite` plugin.'
);
const o = globalThis.__QI_KEY__, i = globalThis.__QI_URL__;
return !o || !i ? (R || console.warn("<Insights />: no config from qwikInsights plugin, skipping..."), null) : /* @__PURE__ */ $("script", {
"document:onQInit$": Q,
// We must pass the vite injected variables via window because sync$ code doesn't get replaced by the vite plugin
dangerouslySetInnerHTML: `__QI_KEY__=${JSON.stringify(o)};__QI_URL__=${JSON.stringify(i)}`
});
});
export {
N as Insights,
Q as insightsPing
};