diff --git a/services/web/frontend/js/features/event-tracking/document-first-change-event.js b/services/web/frontend/js/features/event-tracking/document-first-change-event.js index b32f0a4664..53d138aa04 100644 --- a/services/web/frontend/js/features/event-tracking/document-first-change-event.js +++ b/services/web/frontend/js/features/event-tracking/document-first-change-event.js @@ -1,12 +1,10 @@ -import { isSmallDevice, sendMB } from '@/infrastructure/event-tracking' +import { + isSmallDevice, + sendMBOncePerPageLoad, +} from '@/infrastructure/event-tracking' import getMeta from '@/utils/meta' -// record once per page load -let recorded = false - export function recordDocumentFirstChangeEvent() { - if (recorded) return - recorded = true const projectId = getMeta('ol-project_id') - sendMB('document-first-change', { projectId, isSmallDevice }) + sendMBOncePerPageLoad('document-first-change', { projectId, isSmallDevice }) } diff --git a/services/web/frontend/js/infrastructure/event-tracking.js b/services/web/frontend/js/infrastructure/event-tracking.js index 330405030f..972ec23ddf 100644 --- a/services/web/frontend/js/infrastructure/event-tracking.js +++ b/services/web/frontend/js/infrastructure/event-tracking.js @@ -51,6 +51,14 @@ export function sendMBSampled(key, body = {}, rate = 0.01) { } } +const sentOncePerPageLoad = new Set() + +export function sendMBOncePerPageLoad(key, segmentation = {}) { + if (sentOncePerPageLoad.has(key)) return + sendMB(key, segmentation) + sentOncePerPageLoad.add(key) +} + // Use breakpoint @screen-xs-max from less: // @screen-xs-max: (@screen-sm-min - 1); // @screen-sm-min: @screen-sm;