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
Experimentation.enabled_for_user?(experiment_key, experimentation_subject_index) || forced_enabled?(experiment_key)
end
def track_experiment_event(experiment_key, action)
track_experiment_event_for(experiment_key, action) do |tracking_data|
def track_experiment_event(experiment_key, action, value = nil)
track_experiment_event_for(experiment_key, action, value) do |tracking_data|
::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), tracking_data)
end
end
def frontend_experimentation_tracking_data(experiment_key, action)
track_experiment_event_for(experiment_key, action) do |tracking_data|
def frontend_experimentation_tracking_data(experiment_key, action, value = nil)
track_experiment_event_for(experiment_key, action, value) do |tracking_data|
gon.push(tracking_data: tracking_data)
end
end
......@@ -77,19 +77,20 @@ module Gitlab
experimentation_subject_id.delete('-').hex % 100
end
def track_experiment_event_for(experiment_key, action)
def track_experiment_event_for(experiment_key, action, value)
return unless Experimentation.enabled?(experiment_key)
yield experimentation_tracking_data(experiment_key, action)
yield experimentation_tracking_data(experiment_key, action, value)
end
def experimentation_tracking_data(experiment_key, action)
def experimentation_tracking_data(experiment_key, action, value)
{
category: tracking_category(experiment_key),
action: action,
property: tracking_group(experiment_key),
label: experimentation_subject_id
}
label: experimentation_subject_id,
value: value
}.compact
end
def tracking_category(experiment_key)
......
......@@ -96,10 +96,10 @@ describe Gitlab::Experimentation do
expect(Gitlab::Tracking).to receive(:event).with(
'Team',
'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
......@@ -112,10 +112,10 @@ describe Gitlab::Experimentation do
expect(Gitlab::Tracking).to receive(:event).with(
'Team',
'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
......@@ -144,13 +144,13 @@ describe Gitlab::Experimentation do
end
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(
{
category: 'Team',
action: 'start',
label: nil,
property: 'experimental_group'
property: 'experimental_group',
value: 'team_id'
}
)
end
......@@ -164,12 +164,23 @@ describe Gitlab::Experimentation do
end
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')
expect(Gon.tracking_data).to eq(
{
category: 'Team',
action: 'start',
label: nil,
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