Commit 1b5cbbaa authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '292032-force-experiments-to-persist-in-session' into 'master'

Force multiple experiments in browser session

See merge request gitlab-org/gitlab!49373
parents fba6a41b 8bead562
......@@ -337,6 +337,27 @@ to the URL:
https://gitlab.com/<EXPERIMENT_ENTRY_URL>?force_experiment=<EXPERIMENT_KEY>
```
### A cookie-based approach to force an experiment
It's possible to force the current user to be in the experiment group for <EXPERIMENT_KEY>
during the browser session by using your browser's developer tools:
```javascript
document.cookie = "force_experiment=<EXPERIMENT_KEY>; path=/";
```
Use a comma to list more than one experiment to be forced:
```javascript
document.cookie = "force_experiment=<EXPERIMENT_KEY>,<ANOTHER_EXPERIMENT_KEY>; path=/";
```
Clear the experiments by unsetting the `force_experiment` cookie:
```javascript
document.cookie = "force_experiment=; path=/";
```
### Testing and test helpers
#### RSpec
......
......@@ -130,7 +130,10 @@ module Gitlab
end
def forced_enabled?(experiment_key)
params.has_key?(:force_experiment) && params[:force_experiment] == experiment_key.to_s
return true if params.has_key?(:force_experiment) && params[:force_experiment] == experiment_key.to_s
return false if cookies[:force_experiment].blank?
cookies[:force_experiment].to_s.split(',').any? { |experiment| experiment.strip == experiment_key.to_s }
end
def tracking_label(subject)
......
......@@ -156,6 +156,16 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
is_expected.to eq(true)
end
end
context 'Cookie parameter to force enable experiment' do
it 'returns true unconditionally' do
cookies[:force_experiment] = 'test_experiment,another_experiment'
get :index
expect(check_experiment(:test_experiment)).to eq(true)
expect(check_experiment(:another_experiment)).to eq(true)
end
end
end
describe '#track_experiment_event', :snowplow do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment