From d5a7ef8233b22b2eef789675b239f34c8ac660e6 Mon Sep 17 00:00:00 2001 From: Jeff Hale Date: Fri, 14 Jun 2024 08:45:22 -0400 Subject: [PATCH 1/2] add script.js --- docs/script.js | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 docs/script.js diff --git a/docs/script.js b/docs/script.js new file mode 100644 index 00000000..14335a4a --- /dev/null +++ b/docs/script.js @@ -0,0 +1,124 @@ +function loadScript(src, onload) { + if (typeof window === 'undefined') return + if (typeof src !== 'string') { + console.error('src must be a string') + return + } + + const script = document.createElement('script') + script.src = src + script.async = true + + if (typeof onload === 'function') { + script.addEventListener('load', onload) + } + + document.head.appendChild(script) + return script +} + +function loadCommonRoom() { + const url = 'https://cdn.cr-relay.com/v1/site/5c7cdf16-fbc0-4bb8-b39e-a8c6136687b9/signals.js' + const init = () => { + window.signals = Object.assign( + [], + ['page', 'identify', 'form'].reduce(function (acc, method) { + acc[method] = function () { + signals.push([method, arguments]) + return signals + } + return acc + }, {}) + ) + } + + loadScript(url, init) +} + +function loadAmplitude() { + // TODO: Move the key and url to an env var in mintlify + const amplitudeKey = 'c97dd2acbf306ab7bf54aca0aeb7ffa1' + const amplitudeUrl = 'https://api2.amplitude.com/2/httpapi' + + const addUrl = (event) => { + const deviceId = amplitude.getDeviceId() + const { href = '' } = event.target + const url = new URL(href) + url.searchParams.set('deviceId', deviceId) + event.target.href = url.toString() + } + + const removeUrl = (event) => { + const { href = '' } = event.target + const url = new URL(href) + url.searchParams.delete('deviceId') + event.target.href = url.toString() + } + + const urls = [ + 'https://app.prefect.cloud', + 'https://prefect.io', + ] + + const selector = urls.map((url) => `a[href^="${url}"]`).join(',') + + const addDeviceIdToAppLinks = () => { + const elements = document.querySelectorAll(selector) + + elements.forEach((element) => { + element.addEventListener('mouseenter', addUrl) + element.addEventListener('mouseleave', removeUrl) + element.addEventListener('focus', addUrl) + element.addEventListener('blur', removeUrl) + element.addEventListener('touchstart', addUrl) + element.addEventListener('touchend', removeUrl) + }) + } + + function trackPageView() { + amplitude.track( + 'Page View: Docs New', + { + 'url': window.href, + 'title': document.title, + 'referrer': document.referrer, + 'path': window.location.pathname, + 'source': 'controlflow_docs', + 'source_detail': 'controlflow_docs' + } + ) + } + + const init = () => { + amplitude.init(amplitudeKey, undefined, { + useBatch: true, + serverUrl: amplitudeUrl, + attribution: { + disabled: false, + trackNewCampaigns: true, + trackPageViews: true, + resetSessionOnNewCampaign: true, + }, + defaultTracking: { + pageViews: { + trackOn: function () { return true }, + eventType: "Page View: ControlFlow Docs", + trackHistoryChanges: "all", + }, + sessions: false, + formInteractions: true, + fileDownloads: true, + }, + }) + + setTimeout(addDeviceIdToAppLinks) + setTimeout(trackPageView) + } + + const url = 'https://cdn.amplitude.com/libs/analytics-browser-2.8.1-min.js.gz' + loadScript(url, init) +} + + +loadCommonRoom() +loadAmplitude() From f3ce5e9b81a7241bfd3445232c9e3d2482e1ade7 Mon Sep 17 00:00:00 2001 From: Jeff Hale Date: Fri, 14 Jun 2024 09:16:50 -0400 Subject: [PATCH 2/2] comment --- docs/script.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/script.js b/docs/script.js index 14335a4a..a74a182f 100644 --- a/docs/script.js +++ b/docs/script.js @@ -17,23 +17,23 @@ function loadScript(src, onload) { return script } -function loadCommonRoom() { - const url = 'https://cdn.cr-relay.com/v1/site/5c7cdf16-fbc0-4bb8-b39e-a8c6136687b9/signals.js' - const init = () => { - window.signals = Object.assign( - [], - ['page', 'identify', 'form'].reduce(function (acc, method) { - acc[method] = function () { - signals.push([method, arguments]) - return signals - } - return acc - }, {}) - ) - } - - loadScript(url, init) -} +// function loadCommonRoom() { +// const url = 'https://cdn.cr-relay.com/v1/site/5c7cdf16-fbc0-4bb8-b39e-a8c6136687b9/signals.js' +// const init = () => { +// window.signals = Object.assign( +// [], +// ['page', 'identify', 'form'].reduce(function (acc, method) { +// acc[method] = function () { +// signals.push([method, arguments]) +// return signals +// } +// return acc +// }, {}) +// ) +// } + +// loadScript(url, init) +// } function loadAmplitude() { // TODO: Move the key and url to an env var in mintlify @@ -120,5 +120,5 @@ function loadAmplitude() { } -loadCommonRoom() +// loadCommonRoom() loadAmplitude()