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

utils.js « code_quality_walkthrough « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 894ec9a171da0a91064f2c7ff24a208d92cbaec3 (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
36
37
38
39
import { TRACKING_CONTEXT_SCHEMA } from '~/experimentation/constants';
import { getExperimentData } from '~/experimentation/utils';
import { setCookie, getCookie } from '~/lib/utils/common_utils';
import { getParameterByName } from '~/lib/utils/url_utility';
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 });
  }
}