Skip to content

Commit ecabb4f

Browse files
committed
load segment initially, update ketch scripts
1 parent 23e91e0 commit ecabb4f

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/partials/head-scripts.hbs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
{{#with site.keys.segment}}
22
<script>
33
!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{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://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r);analytics._loadOptions=n};analytics._writeKey="{{this}}";;analytics.SNIPPET_VERSION="5.2.1";
4+
analytics.load("{{this}}");
45
analytics.page();
56
}}();
67
</script>
78
{{/with}}
89

9-
{{!-- {{#with site.keys.ketchSmartTagUrl}} --}}
10-
<script>!function(){window.semaphore=window.semaphore||[],window.ketch=function(){window.semaphore.push(arguments)};var e=document.createElement("script");e.type="text/javascript",e.src="https://global.ketchcdn.com/web/v3/config/datastax/website_smart_tag/boot.js",e.defer=e.async=!0,document.getElementsByTagName("head")[0].appendChild(e)}();</script>
10+
{{#with site.keys.ketchSmartTagUrl}}
11+
<script>!function(){window.semaphore=window.semaphore||[],window.ketch=function(){window.semaphore.push(arguments)};var e=document.createElement("script");e.type="text/javascript",e.src="{{this}}",e.defer=e.async=!0,document.getElementsByTagName("head")[0].appendChild(e)}();</script>
1112
<script>
12-
if (ketch) {
13-
ketch('showPreferences');
14-
15-
function saveConsent(consent) {
16-
window.ketchConsent = consent;
17-
};
18-
ketch("on", "consent", (consent) => {
19-
saveConsent(consent);
20-
// Only load Segment analytics if the user has consented to analytics
21-
if (consent?.purposes?.analytics && window.analytics) {
22-
window.analytics.load("{{../site.keys.segment}}");
23-
}
24-
});
25-
ketch("on", "userConsentUpdated", saveConsent);
26-
ketch("on", "regionInfo", regionInfo => {
27-
var customTextRegions = ["US-CA"];
28-
if (customTextRegions.includes(regionInfo)) {
29-
var preferenceCenterLinkElement = document.getElementById("preferenceCenterLink");
30-
preferenceCenterLinkElement.textContent = "Do Not Sell My Personal Information";
13+
ketch('showPreferences');
14+
</script>
15+
<script>
16+
function saveConsent(consent) {
17+
window.ketchConsent = consent;
18+
};
19+
ketch("on", "consent", (consent) => {
20+
saveConsent(consent);
21+
if (window.analytics) {
22+
window.analytics.addSourceMiddleware(({ payload, next }) => {
23+
if (window.ketchConsent) {
24+
payload.obj.context.consent = {
25+
categoryPreferences: window.ketchConsent?.purposes,
26+
};
3127
}
32-
})
33-
}
28+
next(payload);
29+
});
30+
}
31+
});
32+
ketch("on", "userConsentUpdated", saveConsent);
33+
ketch("on", "regionInfo", regionInfo => {
34+
var customTextRegions = ["US-CA"];
35+
if (customTextRegions.includes(regionInfo)) {
36+
var preferenceCenterLinkElement = document.getElementById("preferenceCenterLink");
37+
preferenceCenterLinkElement.textContent = "Do Not Sell My Personal Information";
38+
}
39+
})
3440
</script>
35-
{{!-- {{/with}} --}}
41+
{{/with}}
3642
3743
<script>var uiRootPath = '{{{uiRootPath}}}'</script>
3844

0 commit comments

Comments
 (0)