2019-08-28 02:52:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
SNOWPLOW_NAMESPACE = 'gl'
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def enabled?
|
|
|
|
Gitlab::CurrentSettings.snowplow_enabled?
|
|
|
|
end
|
|
|
|
|
2021-04-01 08:08:56 -04:00
|
|
|
def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
|
|
|
|
contexts = [Tracking::StandardContext.new(project: project, user: user, namespace: namespace, **extra).to_context, *context]
|
2021-01-14 22:10:30 -05:00
|
|
|
|
2021-03-12 10:09:33 -05:00
|
|
|
snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
|
|
|
|
product_analytics.event(category, action, label: label, property: property, value: value, context: contexts)
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => error
|
2021-03-17 08:09:19 -04:00
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
|
2019-08-28 02:52:14 -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
|
2020-11-21 01:09:33 -05:00
|
|
|
|
|
|
|
def product_analytics
|
|
|
|
@product_analytics ||= Gitlab::Tracking::Destinations::ProductAnalytics.new
|
|
|
|
end
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|