overleaf/services/web/frontend/js/infrastructure/event-tracking.js
Jakob Ackermann f0b3d8a26a Merge pull request #4076 from overleaf/jpa-events-split-test
[misc] submit events and prepare roll-out for pdf caching w/ split test

GitOrigin-RevId: a7b7af65e1adf5bf003b65d96f1641a343b4b09c
2021-05-22 02:05:44 +00:00

19 lines
448 B
JavaScript

import { postJSON } from './fetch-json'
export function send(category, action, label, value) {
if (typeof window.ga === 'function') {
window.ga('send', 'event', category, action, label, value)
}
}
export function sendMB(key, body = {}) {
postJSON(`/event/${key}`, { body }).catch(() => {
// ignore errors
})
}
export function sendMBSampled(key, body = {}, rate = 0.01) {
if (Math.random() < rate) {
sendMB(key, body)
}
}