diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/assets/javascripts/experimentation | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/assets/javascripts/experimentation')
-rw-r--r-- | app/assets/javascripts/experimentation/constants.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/experimentation/experiment_tracking.js | 24 | ||||
-rw-r--r-- | app/assets/javascripts/experimentation/utils.js | 10 |
3 files changed, 35 insertions, 0 deletions
diff --git a/app/assets/javascripts/experimentation/constants.js b/app/assets/javascripts/experimentation/constants.js new file mode 100644 index 00000000000..b7e61d43b11 --- /dev/null +++ b/app/assets/javascripts/experimentation/constants.js @@ -0,0 +1 @@ +export const TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0'; diff --git a/app/assets/javascripts/experimentation/experiment_tracking.js b/app/assets/javascripts/experimentation/experiment_tracking.js new file mode 100644 index 00000000000..c721828036e --- /dev/null +++ b/app/assets/javascripts/experimentation/experiment_tracking.js @@ -0,0 +1,24 @@ +import Tracking from '~/tracking'; +import { TRACKING_CONTEXT_SCHEMA } from './constants'; +import { getExperimentData } from './utils'; + +export default class ExperimentTracking { + constructor(experimentName, trackingArgs = {}) { + this.trackingArgs = trackingArgs; + this.data = getExperimentData(experimentName); + } + + event(action) { + if (!this.data) { + return false; + } + + return Tracking.event(document.body.dataset.page, action, { + ...this.trackingArgs, + context: { + schema: TRACKING_CONTEXT_SCHEMA, + data: this.data, + }, + }); + } +} diff --git a/app/assets/javascripts/experimentation/utils.js b/app/assets/javascripts/experimentation/utils.js new file mode 100644 index 00000000000..d3e7800f643 --- /dev/null +++ b/app/assets/javascripts/experimentation/utils.js @@ -0,0 +1,10 @@ +// This file only applies to use of experiments through https://gitlab.com/gitlab-org/gitlab-experiment +import { get } from 'lodash'; + +export function getExperimentData(experimentName) { + return get(window, ['gon', 'experiment', experimentName]); +} + +export function isExperimentVariant(experimentName, variantName) { + return getExperimentData(experimentName)?.variant === variantName; +} |