2019-08-28 06:52:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
SNOWPLOW_NAMESPACE = 'gl'
|
|
|
|
|
2019-09-26 21:06:29 +00: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 09:06:43 +00: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 21:06:29 +00:00
|
|
|
end
|
|
|
|
|
2019-08-28 06:52:14 +00: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 15:08:41 +00:00
|
|
|
snowplow.event(category, action, label: label, property: property, value: value, context: context)
|
2020-11-21 06:09:33 +00:00
|
|
|
product_analytics.event(category, action, label: label, property: property, value: value, context: context)
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
|
2019-10-11 09:06:43 +00:00
|
|
|
def self_describing_event(schema_url, event_data_json, context: nil)
|
2020-11-04 15:08:41 +00:00
|
|
|
snowplow.self_describing_event(schema_url, event_data_json, context: context)
|
2019-10-11 09:06:43 +00:00
|
|
|
end
|
|
|
|
|
2019-10-24 21:06:26 +00:00
|
|
|
def snowplow_options(group)
|
2019-08-28 06:52:14 +00: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 21:06:38 +00:00
|
|
|
app_id: Gitlab::CurrentSettings.snowplow_app_id,
|
2019-09-18 14:02:45 +00:00
|
|
|
form_tracking: additional_features,
|
2020-09-10 00:08:32 +00:00
|
|
|
link_click_tracking: additional_features
|
2019-08-28 06:52:14 +00:00
|
|
|
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def snowplow
|
2020-11-04 15:08:41 +00:00
|
|
|
@snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new
|
2020-09-03 18:08:29 +00:00
|
|
|
end
|
2020-11-21 06:09:33 +00:00
|
|
|
|
|
|
|
def product_analytics
|
|
|
|
@product_analytics ||= Gitlab::Tracking::Destinations::ProductAnalytics.new
|
|
|
|
end
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|