debian-mirror-gitlab/lib/gitlab/tracking.rb

62 lines
2.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Gitlab
module Tracking
SNOWPLOW_NAMESPACE = 'gl'
2019-12-21 20:55:43 +05:30
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
2021-02-22 17:27:13 +05:30
def track_self_describing_event(schema_url, data:, **args)
Gitlab::Tracking.self_describing_event(schema_url, data: data, **args)
2019-12-21 20:55:43 +05:30
end
end
2019-12-04 20:38:33 +05:30
class << self
def enabled?
Gitlab::CurrentSettings.snowplow_enabled?
end
2021-03-11 19:13:27 +05:30
def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil) # rubocop:disable Metrics/ParameterLists
context += [Tracking::StandardContext.new(project: project, user: user, namespace: namespace).to_context]
2021-03-08 18:12:59 +05:30
2021-01-29 00:20:46 +05:30
snowplow.event(category, action, label: label, property: property, value: value, context: context)
2021-02-22 17:27:13 +05:30
product_analytics.event(category, action, label: label, property: property, value: value, context: context)
2019-12-04 20:38:33 +05:30
end
2021-02-22 17:27:13 +05:30
def self_describing_event(schema_url, data:, context: nil)
snowplow.self_describing_event(schema_url, data: data, context: context)
2019-12-21 20:55:43 +05:30
end
2019-12-04 20:38:33 +05:30
def snowplow_options(group)
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-12-26 22:10:19 +05:30
app_id: Gitlab::CurrentSettings.snowplow_app_id,
2019-12-04 20:38:33 +05:30
form_tracking: additional_features,
2020-11-24 15:15:51 +05:30
link_click_tracking: additional_features
2019-12-04 20:38:33 +05:30
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
end
private
def snowplow
2021-01-29 00:20:46 +05:30
@snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new
2020-11-24 15:15:51 +05:30
end
2021-02-22 17:27:13 +05:30
def product_analytics
@product_analytics ||= Gitlab::Tracking::Destinations::ProductAnalytics.new
end
2019-12-04 20:38:33 +05:30
end
end
end