Commit efb63a88 authored by Alessio Caiazza's avatar Alessio Caiazza

Merge branch 'nicolasdular/experiment-additional-tracking-data' into 'master'

Add ability to add data to tracking events

See merge request gitlab-org/gitlab!23248
parents e7fbbc67 19bcf992
...@@ -53,14 +53,14 @@ module Gitlab ...@@ -53,14 +53,14 @@ module Gitlab
Experimentation.enabled_for_user?(experiment_key, experimentation_subject_index) || forced_enabled?(experiment_key) Experimentation.enabled_for_user?(experiment_key, experimentation_subject_index) || forced_enabled?(experiment_key)
end end
def track_experiment_event(experiment_key, action) def track_experiment_event(experiment_key, action, value = nil)
track_experiment_event_for(experiment_key, action) do |tracking_data| track_experiment_event_for(experiment_key, action, value) do |tracking_data|
::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), tracking_data) ::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), tracking_data)
end end
end end
def frontend_experimentation_tracking_data(experiment_key, action) def frontend_experimentation_tracking_data(experiment_key, action, value = nil)
track_experiment_event_for(experiment_key, action) do |tracking_data| track_experiment_event_for(experiment_key, action, value) do |tracking_data|
gon.push(tracking_data: tracking_data) gon.push(tracking_data: tracking_data)
end end
end end
...@@ -77,19 +77,20 @@ module Gitlab ...@@ -77,19 +77,20 @@ module Gitlab
experimentation_subject_id.delete('-').hex % 100 experimentation_subject_id.delete('-').hex % 100
end end
def track_experiment_event_for(experiment_key, action) def track_experiment_event_for(experiment_key, action, value)
return unless Experimentation.enabled?(experiment_key) return unless Experimentation.enabled?(experiment_key)
yield experimentation_tracking_data(experiment_key, action) yield experimentation_tracking_data(experiment_key, action, value)
end end
def experimentation_tracking_data(experiment_key, action) def experimentation_tracking_data(experiment_key, action, value)
{ {
category: tracking_category(experiment_key), category: tracking_category(experiment_key),
action: action, action: action,
property: tracking_group(experiment_key), property: tracking_group(experiment_key),
label: experimentation_subject_id label: experimentation_subject_id,
} value: value
}.compact
end end
def tracking_category(experiment_key) def tracking_category(experiment_key)
......
...@@ -96,10 +96,10 @@ describe Gitlab::Experimentation do ...@@ -96,10 +96,10 @@ describe Gitlab::Experimentation do
expect(Gitlab::Tracking).to receive(:event).with( expect(Gitlab::Tracking).to receive(:event).with(
'Team', 'Team',
'start', 'start',
label: nil, property: 'experimental_group',
property: 'experimental_group' value: 'team_id'
) )
controller.track_experiment_event(:test_experiment, 'start') controller.track_experiment_event(:test_experiment, 'start', 'team_id')
end end
end end
...@@ -112,10 +112,10 @@ describe Gitlab::Experimentation do ...@@ -112,10 +112,10 @@ describe Gitlab::Experimentation do
expect(Gitlab::Tracking).to receive(:event).with( expect(Gitlab::Tracking).to receive(:event).with(
'Team', 'Team',
'start', 'start',
label: nil, property: 'control_group',
property: 'control_group' value: 'team_id'
) )
controller.track_experiment_event(:test_experiment, 'start') controller.track_experiment_event(:test_experiment, 'start', 'team_id')
end end
end end
end end
...@@ -144,13 +144,13 @@ describe Gitlab::Experimentation do ...@@ -144,13 +144,13 @@ describe Gitlab::Experimentation do
end end
it 'pushes the right parameters to gon' do it 'pushes the right parameters to gon' do
controller.frontend_experimentation_tracking_data(:test_experiment, 'start') controller.frontend_experimentation_tracking_data(:test_experiment, 'start', 'team_id')
expect(Gon.tracking_data).to eq( expect(Gon.tracking_data).to eq(
{ {
category: 'Team', category: 'Team',
action: 'start', action: 'start',
label: nil, property: 'experimental_group',
property: 'experimental_group' value: 'team_id'
} }
) )
end end
...@@ -164,12 +164,23 @@ describe Gitlab::Experimentation do ...@@ -164,12 +164,23 @@ describe Gitlab::Experimentation do
end end
it 'pushes the right parameters to gon' do it 'pushes the right parameters to gon' do
controller.frontend_experimentation_tracking_data(:test_experiment, 'start', 'team_id')
expect(Gon.tracking_data).to eq(
{
category: 'Team',
action: 'start',
property: 'control_group',
value: 'team_id'
}
)
end
it 'does not send nil value to gon' do
controller.frontend_experimentation_tracking_data(:test_experiment, 'start') controller.frontend_experimentation_tracking_data(:test_experiment, 'start')
expect(Gon.tracking_data).to eq( expect(Gon.tracking_data).to eq(
{ {
category: 'Team', category: 'Team',
action: 'start', action: 'start',
label: nil,
property: 'control_group' property: 'control_group'
} }
) )
......
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