mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
568e99ad47
Use keepalive when sending analytics events GitOrigin-RevId: c4e5884483313cdc67abe98e18852680692ac229
19 lines
465 B
JavaScript
19 lines
465 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, keepalive: true }).catch(() => {
|
|
// ignore errors
|
|
})
|
|
}
|
|
|
|
export function sendMBSampled(key, body = {}, rate = 0.01) {
|
|
if (Math.random() < rate) {
|
|
sendMB(key, body)
|
|
}
|
|
}
|