Module: Gitlab::Tracking

Included in:
ProfilesController
Defined in:
lib/gitlab/tracking.rb,
lib/gitlab/tracking/helpers.rb,
lib/gitlab/tracking/event_definition.rb,
lib/gitlab/tracking/standard_context.rb,
lib/gitlab/tracking/destinations/base.rb,
lib/gitlab/tracking/incident_management.rb,
lib/gitlab/tracking/service_ping_context.rb,
lib/gitlab/tracking/destinations/snowplow.rb,
lib/gitlab/tracking/destinations/snowplow_micro.rb,
lib/gitlab/tracking/helpers/weak_password_error_event.rb,
lib/gitlab/tracking/destinations/database_events_snowplow.rb

Defined Under Namespace

Modules: Destinations, Helpers, IncidentManagement Classes: EventDefinition, ServicePingContext, StandardContext

Constant Summary collapse

InvalidEventError =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.collector_hostnameObject



61
62
63
# File 'lib/gitlab/tracking.rb', line 61

def collector_hostname
  tracker.hostname
end

.database_event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) ⇒ Object

rubocop:disable Metrics/ParameterLists



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/tracking.rb', line 27

def database_event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
  action = action.to_s
  destination = Gitlab::Tracking::Destinations::DatabaseEventsSnowplow.new
  contexts = [
    Tracking::StandardContext.new(
      namespace_id: namespace&.id,
      plan_name: namespace&.actual_plan_name,
      project_id: project&.id,
      user_id: user&.id,
      **extra).to_context, *context
  ]

  track_struct_event(destination, category, action, label: label, property: property, value: value, contexts: contexts)
end

.definition(basename, category: nil, action: nil, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) ⇒ Object

rubocop:disable Metrics/ParameterLists



42
43
44
45
46
# File 'lib/gitlab/tracking.rb', line 42

def definition(basename, category: nil, action: nil, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
  definition = YAML.load_file(Rails.root.join("config/events/#{basename}.yml"))

  dispatch_from_definition(definition, label: label, property: property, value: value, context: context, project: project, user: user, namespace: namespace, **extra)
end

.dispatch_from_definition(definition, **event_data) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/gitlab/tracking.rb', line 48

def dispatch_from_definition(definition, **event_data)
  definition = definition.with_indifferent_access

  category ||= definition[:category]
  action ||= definition[:action]

  event(category, action, **event_data)
end

.enabled?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/gitlab/tracking.rb', line 6

def enabled?
  tracker.enabled?
end

.event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) ⇒ Object

rubocop:disable Metrics/ParameterLists



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/tracking.rb', line 10

def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
  action = action.to_s

  project_id = project.is_a?(Integer) ? project : project&.id

  contexts = [
    Tracking::StandardContext.new(
      namespace_id: namespace&.id,
      plan_name: namespace&.actual_plan_name,
      project_id: project_id,
      user_id: user&.id,
      **extra).to_context, *context
  ]

  track_struct_event(tracker, category, action, label: label, property: property, value: value, contexts: contexts)
end

.options(group) ⇒ Object



57
58
59
# File 'lib/gitlab/tracking.rb', line 57

def options(group)
  tracker.options(group)
end

.snowplow_micro_enabled?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/gitlab/tracking.rb', line 65

def snowplow_micro_enabled?
  Rails.env.development? && Gitlab.config.snowplow_micro.enabled
rescue GitlabSettings::MissingSetting
  false
end

.trackerObject



71
72
73
74
75
76
77
# File 'lib/gitlab/tracking.rb', line 71

def tracker
  @tracker ||= if snowplow_micro_enabled?
                 Gitlab::Tracking::Destinations::SnowplowMicro.new
               else
                 Gitlab::Tracking::Destinations::Snowplow.new
               end
end