Class: Gitlab::Tracking::Destinations::Snowplow

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/tracking/destinations/snowplow.rb

Direct Known Subclasses

SnowplowMicro

Constant Summary collapse

SNOWPLOW_NAMESPACE =
'gl'
DEDICATED_APP_ID =
'gitlab_dedicated'
SELF_MANAGED_APP_ID =
'gitlab_sm'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination_configuration = DestinationConfiguration.snowplow_configuration) ⇒ Snowplow

Returns a new instance of Snowplow.



17
18
19
20
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 17

def initialize(destination_configuration = DestinationConfiguration.snowplow_configuration)
  @destination_configuration = destination_configuration
  @event_eligibility_checker = Gitlab::Tracking::EventEligibilityChecker.new
end

Instance Attribute Details

#destination_configurationObject (readonly)

Returns the value of attribute destination_configuration.



15
16
17
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 15

def destination_configuration
  @destination_configuration
end

Instance Method Details

#app_idObject



51
52
53
54
55
56
57
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 51

def app_id
  if Gitlab::CurrentSettings.snowplow_enabled?
    Gitlab::CurrentSettings.snowplow_app_id
  else
    product_usage_event_app_id
  end
end

#emit_event_payload(payload) ⇒ Object



37
38
39
40
41
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 37

def emit_event_payload(payload)
  # Using #input as the tracker doesn't have an option to track using a json object
  # https://snowplow.github.io/snowplow-ruby-tracker/SnowplowTracker/Emitter.html#input-instance_method
  emitter.input(payload)
end

#event(category, action, label: nil, property: nil, value: nil, context: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 22

def event(category, action, label: nil, property: nil, value: nil, context: nil)
  return unless @event_eligibility_checker.eligible?(action)

  tracker.track_struct_event(
    category: category,
    action: action,
    label: label,
    property: property,
    value: value,
    context: context,
    tstamp: (Time.now.to_f * 1000).to_i
  )
  increment_total_events_counter
end

#frontend_client_options(group) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gitlab/tracking/destinations/snowplow.rb', line 43

def frontend_client_options(group)
  if Gitlab::CurrentSettings.snowplow_enabled?
    snowplow_options(group)
  else
    product_usage_events_options
  end
end