Repository navigation
Expand file tree
/
Copy pathfly-analytics.js
More file actions
99 lines (92 loc) · 3.77 KB
/
Copy pathfly-analytics.js
File metadata and controls
99 lines (92 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// PostHog for docs.fly.io, for logged-out visitors outside the EEA/UK.
//
// There is no consent banner here. EEA/UK visitors get nothing beyond Plausible (docs.json
// `integrations.plausible`, which sets nothing on the device). The banner lives on fly.io only.
//
// One self-contained file on purpose: Mintlify runs every .js in the content directory
// in no guaranteed order, so this loads its own PostHog bundle (the vendored
// no-external-code build that landing serves from fly.io) instead of relying on another file.
//
// docs.fly.io has no server, so it asks ui-ex's /api/consent-scope on fly.io (cross-origin,
// session cookie included; ui-ex allows exactly https://docs.fly.io) for:
// * eu_scope — did the visitor arrive via an EEA/UK edge?
// * authenticated — is the visitor logged in?
// Anything other than a clear "not EEA/UK, logged out" (including preview hosts, local
// `mint dev` and network errors) loads nothing.
(function () {
if (window.__flyAnalytics) return;
window.__flyAnalytics = true;
var POSTHOG_KEY = "phc_nuaUijb3iLWut9Kbr56bSHSP4MYdeb8CFd9BgPm3LAVY";
var POSTHOG_HOST = "https://posthog.fly.io";
var POSTHOG_SRC = "https://fly.io/static/javascripts/posthog.js";
var CONSENT_SCOPE_URL = "https://fly.io/api/consent-scope";
fetch(CONSENT_SCOPE_URL, { credentials: "include", headers: { Accept: "application/json" } })
.then(function (r) {
return r.ok ? r.json() : null;
})
.catch(function () {
return null;
})
.then(function (data) {
if (!data || data.authenticated || data.eu_scope !== false) return;
loadPosthog();
});
// Hosts we treat as "us" for referrer attribution: fly.io and any *.fly.io subdomain.
function isInternalHost(host, currentHost) {
return host === currentHost || host === "fly.io" || host.endsWith(".fly.io");
}
// Rewrite internal referrers to PostHog's "$direct" so moving between fly.io and the
// docs doesn't overwrite the real traffic source. Mirrors landing and ui-ex.
function scrubInternalReferrer(props, currentHost) {
if (!props) return;
var pairs = [
["$referring_domain", "$referrer"],
["$initial_referring_domain", "$initial_referrer"],
];
for (var i = 0; i < pairs.length; i++) {
var domain = props[pairs[i][0]];
if (typeof domain === "string" && domain !== "$direct" && isInternalHost(domain, currentHost)) {
props[pairs[i][0]] = "$direct";
props[pairs[i][1]] = "$direct";
}
}
}
function beforeSend(event) {
if (!event || !event.properties) return event;
var currentHost = window.location.hostname;
scrubInternalReferrer(event.properties, currentHost);
scrubInternalReferrer(event.properties.$set_once, currentHost);
return event;
}
function loadPosthog() {
loadScript(POSTHOG_SRC, function () {
if (typeof window.posthog === "undefined") return;
window.posthog.init(POSTHOG_KEY, {
api_host: POSTHOG_HOST,
ui_host: "https://eu.posthog.com",
disable_external_dependency_loading: true,
before_send: beforeSend,
autocapture: false,
capture_dead_clicks: false,
rageclick: false,
enable_heatmaps: false,
disable_session_recording: true,
disable_surveys: true,
capture_exceptions: false,
person_profiles: "identified_only",
// Mintlify navigates client-side, so count route changes as pageviews.
capture_pageview: "history_change",
capture_pageleave: true,
persistence: "localStorage+cookie",
advanced_disable_flags: true,
});
});
}
function loadScript(src, onload) {
var s = document.createElement("script");
s.async = true;
s.src = src;
if (onload) s.onload = onload;
document.head.appendChild(s);
}
})();