/* BitAddy funnel steps: which steps a visit reaches (looked, started, made, copied, paid...), so the owner can see where people stop. Anonymous on purpose: a visit is a random tag kept in this browser tab only (sessionStorage), gone when the tab closes. No cookie, nothing about you, nothing tied to the pages or links you make. Every browser is counted the same way. Usage from app.js / page.js: baEv("step", "detail"). Calls made before this file loads wait in baEv.q. */ (function () { "use strict"; var w = window, n = navigator, waiting = (w.baEv && w.baEv.q) || []; function ss(k, v) { try { if (v === undefined) return sessionStorage.getItem(k); sessionStorage.setItem(k, v); } catch (e) { return null; } } function rand() { var a = new Uint8Array(16), s = "", c = "abcdefghijklmnopqrstuvwxyz0123456789"; (w.crypto || w.msCrypto).getRandomValues(a); for (var i = 0; i < 16; i++) s += c[a[i] % 36]; return s; } var visit = ss("ba_v"); if (!visit || !/^[a-z0-9]{16}$/.test(visit)) { visit = rand(); ss("ba_v", visit); ss("ba_t0", String(Date.now())); /* first page of this visit: remember where it came from (a campaign tag like ?src=x, or the site that linked here) */ var tag = ""; try { var u = new URL(location.href); tag = (u.searchParams.get("src") || u.searchParams.get("utm_source") || "").toLowerCase().slice(0, 40); } catch (e) {} var ref = ""; try { if (document.referrer && new URL(document.referrer).host !== location.host) ref = document.referrer.slice(0, 200); } catch (e) {} ss("ba_tag", tag); ss("ba_ref", ref); } /* keep shared addresses clean: drop the campaign tag from the address bar once it is remembered */ try { var u2 = new URL(location.href); if (u2.searchParams.has("src") || u2.searchParams.has("utm_source")) { ["src", "utm_source", "utm_medium", "utm_campaign"].forEach(function (k) { u2.searchParams.delete(k); }); history.replaceState(history.state, "", u2.pathname + u2.search + u2.hash); } } catch (e) {} var PATH = w.BA_EV_PATH || location.pathname, once = {}; function send(step, detail) { var body = JSON.stringify({ v: visit, s: step, d: detail == null ? "" : String(detail).slice(0, 80), p: PATH, tag: ss("ba_tag") || "", r: ss("ba_ref") || "", w: screen.width }); try { fetch("/_b/ev", { method: "POST", keepalive: true, credentials: "same-origin", headers: { "X-BitAddy": "1", "Content-Type": "application/json" }, body: body }).catch(function () {}); } catch (e) {} } /* baEv(step, detail, onceKey): with onceKey, the step is sent only the first time on this page */ function baEv(step, detail, onceKey) { if (onceKey) { if (once[onceKey]) return; once[onceKey] = 1; } send(step, detail); } w.baEv = baEv; waiting.forEach(function (a) { baEv.apply(null, a); }); /* when the page goes away: how long this visit has lasted so far, in seconds */ w.addEventListener("pagehide", function () { var t0 = +ss("ba_t0") || Date.now(); send("leave", Math.round((Date.now() - t0) / 1000)); }); })();