diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index e0fcbbcdfb8baede36abf84bf0981db09b84eda4..e55156c619b728f5103d06d8796a7c928e10c2b6 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -16,7 +16,7 @@ class RegistrationsController < Devise::RegistrationsController def new if experiment_enabled?(:signup_flow) - track_experiment_event(:signup_flow, 'start') + track_experiment_event(:signup_flow, 'start') # We want this event to be tracked when the user is _in_ the experimental group @resource = build_resource else redirect_to new_user_session_path(anchor: 'register-pane') @@ -24,7 +24,7 @@ def new end def create - track_experiment_event(:signup_flow, 'end') unless experiment_enabled?(:signup_flow) + track_experiment_event(:signup_flow, 'end') unless experiment_enabled?(:signup_flow) # We want this event to be tracked when the user is _in_ the control group accept_pending_invitations @@ -64,7 +64,7 @@ def update_role result = ::Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute if result[:status] == :success - track_experiment_event(:signup_flow, 'end') + track_experiment_event(:signup_flow, 'end') # We want this event to be tracked when the user is _in_ the experimental group set_flash_message! :notice, :signed_up redirect_to stored_location_or_dashboard_or_almost_there_path(current_user) else diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ab2b388149ad0f9ba60cd2c62406dcc09ca9cfb9..00e3be0edfad9ad0905c9cfcf94bf5ed18c67a20 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -296,6 +296,7 @@ def authentication_method end def frontend_tracking_data + # We want tracking data pushed to the frontend when the user is _in_ the control group frontend_experimentation_tracking_data(:signup_flow, 'start') unless experiment_enabled?(:signup_flow) end end diff --git a/lib/gitlab/experimentation.rb b/lib/gitlab/experimentation.rb index 626768c179b374fa2a7d7a4441caadc158cff309..8b315ae5606a7fb98f67da5b7d0897a70ac953e6 100644 --- a/lib/gitlab/experimentation.rb +++ b/lib/gitlab/experimentation.rb @@ -47,17 +47,15 @@ def experiment_enabled?(experiment_key) end def track_experiment_event(experiment_key, action) - return unless Experimentation.enabled?(experiment_key) - - tracking_data = experimentation_tracking_data(experiment_key, action) - ::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), tracking_data) + track_experiment_event_for(experiment_key, action) 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) - return unless Experimentation.enabled?(experiment_key) - - tracking_data = experimentation_tracking_data(experiment_key, action) - gon.push(tracking_data: tracking_data) + track_experiment_event_for(experiment_key, action) do |tracking_data| + gon.push(tracking_data: tracking_data) + end end private @@ -72,6 +70,12 @@ def experimentation_subject_index experimentation_subject_id.delete('-').hex % 100 end + def track_experiment_event_for(experiment_key, action) + return unless Experimentation.enabled?(experiment_key) + + yield experimentation_tracking_data(experiment_key, action) + end + def experimentation_tracking_data(experiment_key, action) { category: tracking_category(experiment_key),