event-tracking.js 448 B

12345678910111213141516171819
  1. import { postJSON } from './fetch-json'
  2. export function send(category, action, label, value) {
  3. if (typeof window.ga === 'function') {
  4. window.ga('send', 'event', category, action, label, value)
  5. }
  6. }
  7. export function sendMB(key, body = {}) {
  8. postJSON(`/event/${key}`, { body }).catch(() => {
  9. // ignore errors
  10. })
  11. }
  12. export function sendMBSampled(key, body = {}, rate = 0.01) {
  13. if (Math.random() < rate) {
  14. sendMB(key, body)
  15. }
  16. }