Add Hotjar script to the home page (#20758)

GitOrigin-RevId: b7fdb904702d84058c2e3519b17376083ee9cad7
This commit is contained in:
Alf Eaton
2024-10-14 11:09:26 +00:00
committed by Copybot
parent b81472329e
commit 7a26d46d7c
6 changed files with 59 additions and 0 deletions
@@ -20,8 +20,10 @@ function setConsent(value) {
if (value === 'all') {
document.cookie = 'oa=1' + cookieAttributes
loadGA()
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: true }))
} else {
document.cookie = 'oa=0' + cookieAttributes
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: false }))
}
}
@@ -0,0 +1,45 @@
import getMeta from '@/utils/meta'
import { isSplitTestEnabled } from '@/utils/splitTestUtils'
import { debugConsole } from '@/utils/debugging'
const { hotjarId, hotjarVersion } = getMeta('ol-ExposedSettings')
if (hotjarId && hotjarVersion && isSplitTestEnabled('hotjar')) {
const loadHotjar = () => {
// consent needed
if (!document.cookie.split('; ').some(item => item === 'oa=1')) {
return
}
// avoid inserting twice
if (document.getElementById('hotjar')) {
return
}
debugConsole.log('Loading Hotjar')
const url = new URL(`https://static.hotjar.com/c/hotjar-${hotjarId}.js`)
url.searchParams.set('sv', hotjarVersion)
const script = document.createElement('script')
script.src = url.toString()
script.async = true
script.id = 'hotjar'
document.head.append(script)
}
// load when idle, if supported
if (typeof window.requestIdleCallback === 'function') {
window.requestIdleCallback(loadHotjar)
} else {
loadHotjar()
}
// listen for consent
window.addEventListener('cookie-consent', event => {
if ((event as CustomEvent<boolean>).detail) {
loadHotjar()
}
})
}
@@ -1,4 +1,5 @@
import '../../marketing'
import '../../infrastructure/hotjar' // set up Hotjar
function homepageAnimation(homepageAnimationEl) {
function createFrames(word, { buildTime, holdTime, breakTime }) {