Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Make JS scripts blocking to minimize A/B test flickering #13316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
referrerpolicy="no-referrer"></script>

{{ $js := resources.Get "js/bundle.js" | fingerprint }}
<script src="{{ $js.RelPermalink }}" defer></script>
<script src="{{ $js.RelPermalink }}"></script>

<!--
Our marketing styles diverge a bit from the other parts of the website so we load
Expand Down
158 changes: 79 additions & 79 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,85 @@
{{- end }}
</script>


<!--Segment tracking-->
<script>
// Do not load Segment for these user agents.
userAgentBlacklist = [
'Mozilla/5.0 (compatible; SiteAuditBot/0.97; +http://www.semrush.com/bot.html)',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
]

!(function () {
var i = "analytics",
analytics = (window[i] = window[i] || []);
if (!analytics.initialize)
if (analytics.invoked) {
window.console && console.error && console.error("Segment snippet included twice.");
} else if (userAgentBlacklist.includes(navigator.userAgent)) {
console.log("Segment snippet not loaded for user agent: " + navigator.userAgent);
} else {
analytics.invoked = !0;
analytics.methods = [
"trackSubmit",
"trackClick",
"trackLink",
"trackForm",
"pageview",
"identify",
"reset",
"group",
"track",
"ready",
"alias",
"debug",
"page",
"screen",
"once",
"off",
"on",
"addSourceMiddleware",
"addIntegrationMiddleware",
"setAnonymousId",
"addDestinationMiddleware",
"register",
];
analytics.factory = function (e) {
return function () {
if (window[i].initialized) return window[i][e].apply(window[i], arguments);
var n = Array.prototype.slice.call(arguments);
if (["track", "screen", "alias", "group", "page", "identify"].indexOf(e) > -1) {
var c = document.querySelector("link[rel='canonical']");
n.push({ __t: "bpc", c: (c && c.getAttribute("href")) || void 0, p: location.pathname, u: location.href, s: location.search, t: document.title, r: document.referrer });
}
n.unshift(e);
analytics.push(n);
return analytics;
};
};
for (var n = 0; n < analytics.methods.length; n++) {
var key = analytics.methods[n];
analytics[key] = analytics.factory(key);
}
analytics.load = function (key, n) {
var t = document.createElement("script");
t.type = "text/javascript";
t.async = !0;
t.setAttribute("data-global-segment-analytics-key", i);
t.src = "https://evs.analytics.pulumi.com/" + snippetName;
var r = document.getElementsByTagName("script")[0];
r.parentNode.insertBefore(t, r);
analytics._loadOptions = n;
};
analytics._writeKey = segmentWriteKey;
analytics._cdn = "https://evs.analytics.pulumi.com";
analytics.SNIPPET_VERSION = "5.2.0";
analytics.load(segmentWriteKey);
analytics.page();
}
})();
</script>

<!-- Our CSS and JS bundles. -->
{{ partial "assets" . }}

Expand Down Expand Up @@ -250,85 +329,6 @@

<script async defer src="https://buttons.github.io/buttons.js"></script>


<!--Segment tracking-->
<script>
// Do not load Segment for these user agents.
userAgentBlacklist = [
'Mozilla/5.0 (compatible; SiteAuditBot/0.97; +http://www.semrush.com/bot.html)',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
]

!(function () {
var i = "analytics",
analytics = (window[i] = window[i] || []);
if (!analytics.initialize)
if (analytics.invoked) {
window.console && console.error && console.error("Segment snippet included twice.");
} else if (userAgentBlacklist.includes(navigator.userAgent)) {
console.log("Segment snippet not loaded for user agent: " + navigator.userAgent);
} else {
analytics.invoked = !0;
analytics.methods = [
"trackSubmit",
"trackClick",
"trackLink",
"trackForm",
"pageview",
"identify",
"reset",
"group",
"track",
"ready",
"alias",
"debug",
"page",
"screen",
"once",
"off",
"on",
"addSourceMiddleware",
"addIntegrationMiddleware",
"setAnonymousId",
"addDestinationMiddleware",
"register",
];
analytics.factory = function (e) {
return function () {
if (window[i].initialized) return window[i][e].apply(window[i], arguments);
var n = Array.prototype.slice.call(arguments);
if (["track", "screen", "alias", "group", "page", "identify"].indexOf(e) > -1) {
var c = document.querySelector("link[rel='canonical']");
n.push({ __t: "bpc", c: (c && c.getAttribute("href")) || void 0, p: location.pathname, u: location.href, s: location.search, t: document.title, r: document.referrer });
}
n.unshift(e);
analytics.push(n);
return analytics;
};
};
for (var n = 0; n < analytics.methods.length; n++) {
var key = analytics.methods[n];
analytics[key] = analytics.factory(key);
}
analytics.load = function (key, n) {
var t = document.createElement("script");
t.type = "text/javascript";
t.async = !0;
t.setAttribute("data-global-segment-analytics-key", i);
t.src = "https://evs.analytics.pulumi.com/" + snippetName;
var r = document.getElementsByTagName("script")[0];
r.parentNode.insertBefore(t, r);
analytics._loadOptions = n;
};
analytics._writeKey = segmentWriteKey;
analytics._cdn = "https://evs.analytics.pulumi.com";
analytics.SNIPPET_VERSION = "5.2.0";
analytics.load(segmentWriteKey);
analytics.page();
}
})();
</script>

<!-- Segment Consent Manager -->
<script>
window.consentManagerConfig = function(exports) {
Expand Down
1 change: 1 addition & 0 deletions theme/stencil/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as uuid from "uuid";
import { GrowthBook } from "@growthbook/growthbook";

// Initialize GrowthBook

export const gb = new GrowthBook({
apiHost: "https://cdn.growthbook.io",
clientKey: (window as any).growthbook_sdk_key,
Expand Down
Loading