Add Hotjar script to the home page (#20758)

GitOrigin-RevId: b7fdb904702d84058c2e3519b17376083ee9cad7
This commit is contained in:
Alf Eaton 2024-10-11 09:35:08 +01:00 committed by Copybot
parent b81472329e
commit 7a26d46d7c
6 changed files with 59 additions and 0 deletions

View file

@ -9,6 +9,7 @@ const SessionManager = require('../Authentication/SessionManager')
const { expressify } = require('@overleaf/promise-utils')
const logger = require('@overleaf/logger')
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
const homepageExists = fs.existsSync(
Path.join(
@ -35,6 +36,12 @@ async function home(req, res) {
page: req.path,
})
try {
await SplitTestHandler.promises.getAssignment(req, res, 'hotjar')
} catch {
// do nothing
}
res.render('external/home/website-redesign/index')
} else {
res.redirect('/login')

View file

@ -406,6 +406,8 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
sentryDsn: Settings.sentry.publicDSN,
sentryEnvironment: Settings.sentry.environment,
sentryRelease: Settings.sentry.release,
hotjarId: Settings.hotjar?.id,
hotjarVersion: Settings.hotjar?.version,
enableSubscriptions: Settings.enableSubscriptions,
gaToken:
Settings.analytics &&

View file

@ -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 }))
}
}

View file

@ -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()
}
})
}

View file

@ -1,4 +1,5 @@
import '../../marketing'
import '../../infrastructure/hotjar' // set up Hotjar
function homepageAnimation(homepageAnimationEl) {
function createFrames(word, { buildTime, holdTime, breakTime }) {

View file

@ -19,6 +19,8 @@ export type ExposedSettings = {
hasLinkedProjectOutputFileFeature: boolean
hasSamlBeta?: boolean
hasSamlFeature: boolean
hotjarId?: string
hotjarVersion?: string
ieeeBrandId: number
isOverleaf: boolean
maxEntitiesPerProject: number