From fb4dbe27dd2567b87cd30bc8cbf04c0b36358e1d Mon Sep 17 00:00:00 2001 From: Alex Buijs <abuijs@gitlab.com> Date: Wed, 23 Oct 2019 12:02:47 +0200 Subject: [PATCH] Implement feedback fixes --- app/controllers/registrations_controller.rb | 6 +++--- app/controllers/sessions_controller.rb | 1 + lib/gitlab/experimentation.rb | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index e0fcbbcdfb8ba..e55156c619b72 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 ab2b388149ad0..00e3be0edfad9 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 626768c179b37..8b315ae5606a7 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), -- GitLab