Module: Gitlab::Experimentation::ControllerConcern

Extended by:
ActiveSupport::Concern
Includes:
GroupTypes
Included in:
ApplicationController, Oauth::ApplicationsController, Oauth::AuthorizationsController
Defined in:
lib/gitlab/experimentation/controller_concern.rb

Constant Summary

Constants included from GroupTypes

GroupTypes::GROUP_CONTROL, GroupTypes::GROUP_EXPERIMENTAL

Instance Method Summary collapse

Instance Method Details

#experiment_enabled?(experiment_key) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
41
42
43
44
45
# File 'lib/gitlab/experimentation/controller_concern.rb', line 38

def experiment_enabled?(experiment_key)
  return false if dnt_enabled?

  return true if Experimentation.enabled_for_value?(experiment_key, experimentation_subject_index(experiment_key))
  return true if forced_enabled?(experiment_key)

  false
end

#experiment_tracking_category_and_group(experiment_key) ⇒ Object


78
79
80
# File 'lib/gitlab/experimentation/controller_concern.rb', line 78

def experiment_tracking_category_and_group(experiment_key)
  "#{tracking_category(experiment_key)}:#{tracking_group(experiment_key, '_group')}"
end

#frontend_experimentation_tracking_data(experiment_key, action, value = nil) ⇒ Object


55
56
57
58
59
60
61
# File 'lib/gitlab/experimentation/controller_concern.rb', line 55

def frontend_experimentation_tracking_data(experiment_key, action, value = nil)
  return if dnt_enabled?

  track_experiment_event_for(experiment_key, action, value) do |tracking_data|
    gon.push(tracking_data: tracking_data)
  end
end

#push_frontend_experiment(experiment_key) ⇒ Object


31
32
33
34
35
36
# File 'lib/gitlab/experimentation/controller_concern.rb', line 31

def push_frontend_experiment(experiment_key)
  var_name = experiment_key.to_s.camelize(:lower)
  enabled = experiment_enabled?(experiment_key)

  gon.push({ experiments: { var_name => enabled } }, true)
end

#record_experiment_conversion_event(experiment_key) ⇒ Object


70
71
72
73
74
75
76
# File 'lib/gitlab/experimentation/controller_concern.rb', line 70

def record_experiment_conversion_event(experiment_key)
  return if dnt_enabled?
  return unless current_user
  return unless Experimentation.enabled?(experiment_key)

  ::Experiment.record_conversion_event(experiment_key, current_user)
end

#record_experiment_user(experiment_key) ⇒ Object


63
64
65
66
67
68
# File 'lib/gitlab/experimentation/controller_concern.rb', line 63

def record_experiment_user(experiment_key)
  return if dnt_enabled?
  return unless Experimentation.enabled?(experiment_key) && current_user

  ::Experiment.add_user(experiment_key, tracking_group(experiment_key), current_user)
end

21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/experimentation/controller_concern.rb', line 21

def set_experimentation_subject_id_cookie
  return if cookies[:experimentation_subject_id].present?

  cookies.permanent.signed[:experimentation_subject_id] = {
    value: SecureRandom.uuid,
    secure: ::Gitlab.config.gitlab.https,
    httponly: true
  }
end

#track_experiment_event(experiment_key, action, value = nil) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/gitlab/experimentation/controller_concern.rb', line 47

def track_experiment_event(experiment_key, action, value = nil)
  return if dnt_enabled?

  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