2022-07-16 23:28:13 +05:30
|
|
|
import * as Sentry from '@sentry/browser';
|
2021-10-27 15:23:28 +05:30
|
|
|
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.');
|
|
|
|
}
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
const { label, property, extra = {} } = data;
|
|
|
|
let { value } = data;
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
const standardContext = getStandardContext({ extra });
|
|
|
|
const contexts = [standardContext];
|
|
|
|
|
|
|
|
if (data.context) {
|
|
|
|
contexts.push(data.context);
|
|
|
|
}
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
if (value !== undefined) {
|
|
|
|
value = Number(value);
|
|
|
|
}
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
try {
|
|
|
|
window.snowplow('trackStructEvent', category, action, label, property, value, contexts);
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
Sentry.captureException(error);
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-27 15:23:28 +05:30
|
|
|
}
|