overleaf-cep/services/web/frontend/js/infrastructure/tracking-propensity.ts
Antoine Clausse bb5b9afd0e [web] Define loadPropensityScript before use (#26813)
This prevents the bug "ReferenceError: Cannot access uninitialized variable" for users who don't have `window.requestIdleCallback`.

Fixes https://overleaf.sentry.io/issues/6724866295

GitOrigin-RevId: 129dcb72f24dc901ad600253bab7c58673e44321
2025-07-07 08:05:32 +00:00

23 lines
579 B
TypeScript

import getMeta from '@/utils/meta'
import {
createTrackingLoader,
insertScript,
} from '@/infrastructure/tracking-loader'
const { propensityId } = getMeta('ol-ExposedSettings')
const loadPropensityScript = (id: string) => {
insertScript({
src: 'https://cdn.propensity.com/propensity/propensity_analytics.js',
crossorigin: 'anonymous',
onload: () => {
if (typeof window.propensity !== 'undefined') {
window.propensity(id)
}
},
})
}
if (propensityId) {
createTrackingLoader(() => loadPropensityScript(propensityId), 'Propensity')
}