debian-mirror-gitlab/app/assets/javascripts/code_quality_walkthrough/utils.js
2021-06-08 01:23:25 +05:30

38 lines
975 B
JavaScript

import { TRACKING_CONTEXT_SCHEMA } from '~/experimentation/constants';
import { getExperimentData } from '~/experimentation/utils';
import { setCookie, getCookie, getParameterByName } from '~/lib/utils/common_utils';
import Tracking from '~/tracking';
import { EXPERIMENT_NAME } from './constants';
export function getExperimentSettings() {
return JSON.parse(getCookie(EXPERIMENT_NAME) || '{}');
}
export function setExperimentSettings(settings) {
setCookie(EXPERIMENT_NAME, settings);
}
export function isWalkthroughEnabled() {
return getParameterByName(EXPERIMENT_NAME);
}
export function track(action) {
const { data } = getExperimentSettings();
if (data) {
Tracking.event(EXPERIMENT_NAME, action, {
context: {
schema: TRACKING_CONTEXT_SCHEMA,
data,
},
});
}
}
export function startCodeQualityWalkthrough() {
const data = getExperimentData(EXPERIMENT_NAME);
if (data) {
setExperimentSettings({ data });
}
}