2019-08-28 02:52:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
SNOWPLOW_NAMESPACE = 'gl'
|
|
|
|
|
2019-09-26 17:06:29 -04:00
|
|
|
module ControllerConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def track_event(action = action_name, **args)
|
|
|
|
category = args.delete(:category) || self.class.name
|
|
|
|
Gitlab::Tracking.event(category, action.to_s, **args)
|
|
|
|
end
|
2019-10-11 05:06:43 -04:00
|
|
|
|
|
|
|
def track_self_describing_event(schema_url, event_data_json, **args)
|
|
|
|
Gitlab::Tracking.self_describing_event(schema_url, event_data_json, **args)
|
|
|
|
end
|
2019-09-26 17:06:29 -04:00
|
|
|
end
|
|
|
|
|
2019-08-28 02:52:14 -04:00
|
|
|
class << self
|
|
|
|
def enabled?
|
|
|
|
Gitlab::CurrentSettings.snowplow_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(category, action, label: nil, property: nil, value: nil, context: nil)
|
2020-11-04 10:08:41 -05:00
|
|
|
snowplow.event(category, action, label: label, property: property, value: value, context: context)
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
|
2019-10-11 05:06:43 -04:00
|
|
|
def self_describing_event(schema_url, event_data_json, context: nil)
|
2020-11-04 10:08:41 -05:00
|
|
|
snowplow.self_describing_event(schema_url, event_data_json, context: context)
|
2019-10-11 05:06:43 -04:00
|
|
|
end
|
|
|
|
|
2019-10-24 17:06:26 -04:00
|
|
|
def snowplow_options(group)
|
2019-08-28 02:52:14 -04:00
|
|
|
additional_features = Feature.enabled?(:additional_snowplow_tracking, group)
|
|
|
|
{
|
|
|
|
namespace: SNOWPLOW_NAMESPACE,
|
|
|
|
hostname: Gitlab::CurrentSettings.snowplow_collector_hostname,
|
|
|
|
cookie_domain: Gitlab::CurrentSettings.snowplow_cookie_domain,
|
2019-11-08 16:06:38 -05:00
|
|
|
app_id: Gitlab::CurrentSettings.snowplow_app_id,
|
2019-09-18 10:02:45 -04:00
|
|
|
form_tracking: additional_features,
|
2020-09-09 20:08:32 -04:00
|
|
|
link_click_tracking: additional_features
|
2019-08-28 02:52:14 -04:00
|
|
|
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def snowplow
|
2020-11-04 10:08:41 -05:00
|
|
|
@snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new
|
2020-09-03 14:08:29 -04:00
|
|
|
end
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|