Skip to content

Commit

Permalink
Added One Trust code
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnyder committed Sep 30, 2021
1 parent e5b8878 commit 662a64b
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ <h1>Update Juncture site</h1>

const ENV = window.location.hostname === 'localhost' || window.location.hostname.indexOf('gitpod') > 0 || window.location.hostname.indexOf('githubpreview') > 0 ? 'DEV' : 'PROD'
let isJuncture = window.location.hostname.indexOf('juncture-digital.org') === 0 || ENV === 'DEV'
const junctureVersion = 'v0.4.28'
const junctureVersion = 'v0.5.0'
let junctureVersionHash

const referrerUrl = document.referrer
Expand Down Expand Up @@ -434,6 +434,13 @@ <h1>Update Juncture site</h1>
}
})

if (siteConfig.enableOneTrust && siteConfig.oneTrustSiteKey) {
let el = document.createElement('script')
el.src = 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'
el.setAttribute('data-domain-script', siteConfig.oneTrustSiteKey)
document.querySelector('body').appendChild(el)
}

new Vue({
el: '#app',
data: () => ({
Expand Down Expand Up @@ -1535,5 +1542,52 @@ <h1>Update Juncture site</h1>
})(window ,document,'script','https://www.google-analytics.com/analytics.js','ga')
</script>

<script>
function disablePerformanceGroup() {
// disable google analytics
if (gaPropertyID) window[`ga-disable-${gaPropertyID}`] = true
}

function handleOneTrustCookieGroups(oneTrustCookie) {
const STRICTLY_NECESSARY_GROUP_ID = "C0001"
const PERFORMANCE_GROUP_ID = "C0002"
const FUNCTIONAL_GROUP_ID = "C0003"
const ADVERTISING_GROUP_ID = "C0004"
const SOCIAL_MEDIA_GROUP_ID = "C0005"

const splitCookieValue = oneTrustCookie.split('=')
const cookieValues = new URLSearchParams(splitCookieValue.slice(1).join('='))
const cookieGroups = cookieValues.get('groups')
const disabledCookieGroups = cookieGroups && cookieGroups.split(',')
.map(cookie => cookie.split(':'))
.filter(([groupName, enabled]) => enabled == 0)

disabledCookieGroups && disabledCookieGroups.forEach(([group]) => {
if (group === PERFORMANCE_GROUP_ID) {
disablePerformanceGroup()
}
})
}

function findOneTrustCookie() {
const oneTrustCookie = document.cookie
.split(';')
.map(cookie => cookie.trim())
.find(cookie => {
const [cookieName] = cookie.split('=')
console.log(cookieName)
return cookieName === 'OptanonConsent'
})

return oneTrustCookie
}

function OptanonWrapper() {
const oneTrustCookie = findOneTrustCookie()
if (oneTrustCookie) {
handleOneTrustCookieGroups(oneTrustCookie)
}
}
</script>
</body>
</html>

0 comments on commit 662a64b

Please sign in to comment.