diff --git a/web/public/scripts/ua_latest.js b/web/public/scripts/ua_latest.js new file mode 100644 index 0000000000..a5de407f28 --- /dev/null +++ b/web/public/scripts/ua_latest.js @@ -0,0 +1,152 @@ +!function() { + "use strict"; + (t => { + const { + screen: { width: e, height: a }, + navigator: { language: r }, + location: n, + localStorage: i, + document: c, + history: o + } = t; + const { hostname: s, href: u } = n; + const { currentScript: l, referrer: d } = c; + + if (!l) return; + + const m = "data-", + f = l.getAttribute.bind(l), + h = f(m + "website-id"), + p = f(m + "host-url"), + g = f(m + "tag"), + y = "false" !== f(m + "auto-track"), + b = "true" === f(m + "exclude-search"), + v = f(m + "domains") || "", + w = v.split(",").map(t => t.trim()), + S = `${(p || "https://api-gateway.umami.dev" || l.src.split("/").slice(0, -1).join("/")).replace(/\/$/, "")}/api/send`, + N = `${e}x${a}`, + T = /data-umami-event-([\w-_]+)/, + A = m + "umami-event", + x = 300; + + const O = t => { + if (t) { + try { + const e = decodeURI(t); + if (e !== t) return e; + } catch (e) { + return t; + } + return encodeURI(t); + } + }; + + const U = t => { + try { + const { pathname: e, search: a } = new URL(t); + t = e + a; + } catch (t) { } + return b ? t.split("?")[0] : t; + }; + + const j = () => ({ + website: h, + hostname: s, + screen: N, + language: r, + title: O(q), + url: O(D), + referrer: O(_), + tag: g || void 0 + }); + + const k = (t, e, a) => { + a && (_ = D, D = U(a.toString()), D !== _ && setTimeout(I, x)); + }; + + const E = () => !h || i && i.getItem("umami.disabled") || v && !w.includes(s); + + const L = async (t, e = "event") => { + if (E()) return; + const a = { "Content-Type": "application/json" }; + void 0 !== R && (a["x-umami-cache"] = R); + try { + const r = await fetch(S, { + method: "POST", + body: JSON.stringify({ type: e, payload: t }), + headers: a + }); + const n = await r.text(); + return R = n; + } catch (t) { } + }; + + const $ = () => { + B || ( + I(), + (() => { + const t = (t, e, a) => { + const r = t[e]; + return (...e) => (a.apply(null, e), r.apply(t, e)); + }; + o.pushState = t(o, "pushState", k); + o.replaceState = t(o, "replaceState", k); + })(), + (() => { + const t = new MutationObserver(([t]) => { + q = t && t.target ? t.target.text : void 0; + }); + const e = c.querySelector("head > title"); + e && t.observe(e, { subtree: !0, characterData: !0, childList: !0 }); + })(), + c.addEventListener("click", async t => { + const e = t => ["BUTTON", "A"].includes(t), + a = async t => { + const e = t.getAttribute.bind(t), + a = e(A); + if (a) { + const r = {}; + return t.getAttributeNames().forEach(t => { + const a = t.match(T); + a && (r[a[1]] = e(t)); + }), I(a, r); + } + }, + r = t.target, + i = e(r.tagName) ? r : ((t, a) => { + let r = t; + for (let t = 0; t < a; t++) { + if (e(r.tagName)) return r; + if (r = r.parentElement, !r) return null; + } + })(r, 10); + if (!i) return a(r); + { + const { href: e, target: r } = i, + c = i.getAttribute(A); + if (c) + if ("A" === i.tagName) { + const o = "_blank" === r || t.ctrlKey || t.shiftKey || t.metaKey || t.button && 1 === t.button; + if (c && e) return o || t.preventDefault(), a(i).then(() => { + o || (n.href = e); + }); + } else if ("BUTTON" === i.tagName) return a(i); + } + }, !0), + B = !0 + ); + }; + + const I = (t, e) => L( + "string" == typeof t ? { ...j(), name: t, data: "object" == typeof e ? e : void 0 } : "object" == typeof t ? t : "function" == typeof t ? t(j()) : j() + ); + + const K = t => L({ ...j(), data: t }, "identify"); + + t.umami || (t.umami = { track: I, identify: K }); + + let R, B, D = U(u), _ = d !== s ? d : "", q = c.title; + + y && !E() && ("complete" === c.readyState ? $() : c.addEventListener("readystatechange", $, !0)); + })(window); +}(); diff --git a/web/src/components/clickTracker.astro b/web/src/components/clickTracker.astro new file mode 100644 index 0000000000..b7a8755582 --- /dev/null +++ b/web/src/components/clickTracker.astro @@ -0,0 +1,34 @@ +--- +// Track if div clicked, then send umami event once per page view +interface Props { + div_id: string; + eventLabel: string; +} + +const { div_id, eventLabel }: Props = Astro.props; +--- + + diff --git a/web/src/components/code.astro b/web/src/components/code.astro index 36c92fdad0..c7e8e69c23 100644 --- a/web/src/components/code.astro +++ b/web/src/components/code.astro @@ -12,7 +12,7 @@ import "prismjs/plugins/line-highlight/prism-line-highlight.js"; import 'prismjs/plugins/line-numbers/prism-line-numbers.js' import 'prismjs/plugins/line-numbers/prism-line-numbers.css' - +import ClickTracker from './clickTracker.astro'; import GoogleColab from '../images/google_colab.svg.png' const gh_branch = import.meta.env.PUBLIC_GH_BRANCH; @@ -791,7 +791,8 @@ const frameworks = [ --- -
+ +
diff --git a/web/src/components/gettingStarted.astro b/web/src/components/gettingStarted.astro index 1738f9a651..632c7b7854 100644 --- a/web/src/components/gettingStarted.astro +++ b/web/src/components/gettingStarted.astro @@ -1,4 +1,6 @@ --- +import ClickTracker from './clickTracker.astro'; + const gh_branch = import.meta.env.PUBLIC_GH_BRANCH; const walkthrough = [ @@ -93,7 +95,8 @@ const series = [ ] --- -
+ +

diff --git a/web/src/components/hero.astro b/web/src/components/hero.astro index e55fd687cd..e9bbb93e07 100644 --- a/web/src/components/hero.astro +++ b/web/src/components/hero.astro @@ -1,11 +1,13 @@ --- import NvidiaLogo from '../images/nvidia_eye.png' import NvflareAnimation from '../images/nvflare_graphic_animation.mp4' +import ClickTracker from './clickTracker.astro'; const gh_branch = import.meta.env.PUBLIC_GH_BRANCH; const base_url = import.meta.env.BASE_URL; --- -
+ +
diff --git a/web/src/components/learnMore.astro b/web/src/components/learnMore.astro index a0e6e22597..9e931e7f48 100644 --- a/web/src/components/learnMore.astro +++ b/web/src/components/learnMore.astro @@ -1,4 +1,5 @@ --- +import ClickTracker from './clickTracker.astro'; const learnMore = [ { @@ -22,7 +23,8 @@ const learnMore = [ ]; --- -
+ +

diff --git a/web/src/components/overview.astro b/web/src/components/overview.astro index 582791c3c3..01064d04c2 100644 --- a/web/src/components/overview.astro +++ b/web/src/components/overview.astro @@ -1,4 +1,6 @@ --- +import ClickTracker from './clickTracker.astro'; + const features = [ { id: "research", @@ -70,7 +72,8 @@ const features = [ --- -
+ +

diff --git a/web/src/components/series.astro b/web/src/components/series.astro index 2e83dd5a00..f325eafa6d 100644 --- a/web/src/components/series.astro +++ b/web/src/components/series.astro @@ -1,4 +1,6 @@ --- +import ClickTracker from './clickTracker.astro'; + const gh_branch = import.meta.env.PUBLIC_GH_BRANCH; const series_100 = { @@ -304,7 +306,8 @@ const series_list = [ --- -
+ +

diff --git a/web/src/components/tutorials.astro b/web/src/components/tutorials.astro index b3a0ea51f3..1434fcf348 100644 --- a/web/src/components/tutorials.astro +++ b/web/src/components/tutorials.astro @@ -1,5 +1,6 @@ --- import GoogleColab from '../images/google_colab.svg.png' +import ClickTracker from './clickTracker.astro'; const gh_branch = import.meta.env.PUBLIC_GH_BRANCH; const base_url = import.meta.env.BASE_URL; @@ -517,7 +518,8 @@ const tag_list = [ --- -