Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dispatch_snowplow_event.js « tracking « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5daeaf1d85b1c41adc0ec026cd4cfc8ae861d161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as Sentry from '@sentry/browser';
import getStandardContext from './get_standard_context';

export function dispatchSnowplowEvent(
  category = document.body.dataset.page,
  action = 'generic',
  data = {},
) {
  if (!category) {
    /* eslint-disable-next-line @gitlab/require-i18n-strings */
    throw new Error('Tracking: no category provided for tracking.');
  }

  const { label, property, extra = {} } = data;
  let { value } = data;

  const standardContext = getStandardContext({ extra });
  const contexts = [standardContext];

  if (data.context) {
    contexts.push(data.context);
  }

  if (value !== undefined) {
    value = Number(value);
  }

  try {
    window.snowplow('trackStructEvent', category, action, label, property, value, contexts);
    return true;
  } catch (error) {
    Sentry.captureException(error);
    return false;
  }
}