-
Notifications
You must be signed in to change notification settings - Fork 0
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
DOC-4329: Ketch footer and Segment updates #179
Open
eric-schneider
wants to merge
21
commits into
main
Choose a base branch
from
DOC-4329-footer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9fee0e0
Add consent management link to footer
eric-schneider 35bacac
dynamic footer text and consent context added to segment calls
colegoldsmith c0dd2bc
fix consent object
colegoldsmith e00c57d
Make footer link conditional
eric-schneider bbca953
Shorten data-track attribute
eric-schneider 55e9c9f
Squash merge remove-gtm-scripts into DOC-4329-footer
colegoldsmith b5697a9
fix track events so they use consent context correctly. Only load seg…
colegoldsmith a2de33e
Merge branch 'main' into DOC-4329-footer
colegoldsmith 0cf2a0f
manual ketch url for testing purposes, revert this soon
colegoldsmith 6a7cfaf
test showing ketch preferences on load
colegoldsmith 23e91e0
fix segment object
colegoldsmith ecabb4f
load segment initially, update ketch scripts
colegoldsmith 9213d6a
hard code keys
colegoldsmith a363a1c
undo hard coded site keys
colegoldsmith 3c2eea0
add ketch logic to js file and let middleware handle context
colegoldsmith ec60950
update to latest changes from marketing without gtag scripts
colegoldsmith 89d00a4
UNDO THIS - hard coding segment and ketch site keys
colegoldsmith 0350d78
use segment prod source
colegoldsmith 459745d
force a rebuild
colegoldsmith 0663bb2
use dev segment source
colegoldsmith 2652537
add gtag script and use staging www site footer link
colegoldsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,55 @@ | ||
;(function () { | ||
'use strict' | ||
|
||
const ketchConsentContext = { | ||
context: { | ||
consent: { | ||
categoryPreferences: { | ||
...(window.ketchConsent?.purposes || { | ||
analytics: false, | ||
essential_services: false, | ||
targeted_advertising: false, | ||
}), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const trackEvent = (name, payload) => { | ||
if (window.analytics) { | ||
window.analytics.track(name, { | ||
...(payload || {}), | ||
...ketchConsentContext, | ||
}) | ||
} | ||
} | ||
|
||
const trackLinkEvent = (element, name, payload) => { | ||
if (window.analytics) { | ||
window.analytics.trackLink(element, name, { | ||
...(payload || {}), | ||
...ketchConsentContext, | ||
}) | ||
} | ||
} | ||
|
||
if (window.analytics) { | ||
const trackedLinkElements = document.querySelectorAll('a[data-track]') | ||
const trackedElements = document.querySelectorAll('[data-track]:not(a)') | ||
|
||
trackedLinkElements.forEach((element) => { | ||
window.analytics.trackLink(element, element.dataset.track) | ||
trackLinkEvent(element, element.dataset.track) | ||
}) | ||
|
||
trackedElements.forEach((element) => { | ||
element.addEventListener('click', (e) => { | ||
window.analytics.track(element.dataset.track) | ||
trackEvent(element.dataset.track) | ||
}) | ||
}) | ||
} | ||
|
||
// Expose trackEvent and trackLinkEvent to the global scope. | ||
// All tracking events should be done through these functions because they handle the Ketch consent context. | ||
window.trackEvent = trackEvent | ||
window.trackLinkEvent = trackLinkEvent | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
{{#with site.keys.ketchSmartTagUrl}} | ||
<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> | ||
{{/with}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
{{#with site.keys.segment}} | ||
<script> | ||
!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"; | ||
analytics.load("{{this}}"); | ||
analytics.page(); | ||
}}(); | ||
</script> | ||
<script> | ||
!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"; | ||
analytics.page(); | ||
}}(); | ||
</script> | ||
{{/with}} | ||
|
||
{{!-- {{#with site.keys.ketchSmartTagUrl}} --}} | ||
<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> | ||
<script> | ||
if (window.ketch) { | ||
function saveConsent(consent) { | ||
window.ketchConsent = consent; | ||
}; | ||
window.ketch("on", "consent", (consent) => { | ||
saveConsent(consent); | ||
// Only load Segment analytics if the user has consented to analytics | ||
if (consent?.purposes?.analytics && window.analytics) { | ||
window.analytics.load("{{../site.keys.segment}}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also add the following script:
This will enable the context on all the events and not only track events. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice! Will do |
||
} | ||
}); | ||
window.ketch("on", "userConsentUpdated", saveConsent); | ||
window.ketch("on", "regionInfo", regionInfo => { | ||
var customTextRegions = ["US-CA"]; | ||
if (customTextRegions.includes(regionInfo)) { | ||
var preferenceCenterLinkElement = document.getElementById("preferenceCenterLink"); | ||
preferenceCenterLinkElement.textContent = "Do Not Sell My Personal Information"; | ||
} | ||
}) | ||
} | ||
</script> | ||
{{!-- {{/with}} --}} | ||
|
||
<script>var uiRootPath = '{{{uiRootPath}}}'</script> | ||
|
||
<script> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just found that this is wrong. This sends the context as an event property and not as a context.
The correct way is to send it as a third param.
window.analytics.track(eventName, eventProperties, eventContext)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah lol yep good catch, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's updated