Files
overleaf-cep/services/web/frontend/js/infrastructure/hotjar.ts
T
roo hutton 551428ee37 Merge pull request #28013 from overleaf/rh-editor-hotjar
Support user limits on split test variants, add Hotjar editor support

GitOrigin-RevId: c5df831436c2b7d7e242cf4d3ff00899aba77886
2025-10-23 08:05:20 +00:00

36 lines
996 B
TypeScript

import getMeta from '@/utils/meta'
import { debugConsole } from '@/utils/debugging'
import { initializeHotjar } from '@/infrastructure/hotjar-snippet'
import { createTrackingLoader } from '@/infrastructure/tracking-loader'
import grammarlyExtensionPresent from '@/shared/utils/grammarly'
const { hotjarId, hotjarVersion } = getMeta('ol-ExposedSettings')
const shouldLoadHotjar = getMeta('ol-shouldLoadHotjar')
function attemptHotjarLoad() {
if (!hotjarId || !hotjarVersion) {
return
}
if (!/^\d+$/.test(hotjarId) || !/^\d+$/.test(hotjarVersion)) {
debugConsole.error('Invalid Hotjar id or version')
return
}
if (grammarlyExtensionPresent()) {
return
}
createTrackingLoader(
() => initializeHotjar(hotjarId, hotjarVersion),
'Hotjar'
)
}
if (hotjarId && hotjarVersion && shouldLoadHotjar) {
document.addEventListener('DOMContentLoaded', () => {
// add delay to allow extensions to inject shadow DOM
setTimeout(attemptHotjarLoad, 1000)
})
}