2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'snowplow-tracker'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def track_self_describing_event(schema_url, event_data_json, **args)
|
|
|
|
Gitlab::Tracking.self_describing_event(schema_url, event_data_json, **args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
class << self
|
|
|
|
def enabled?
|
|
|
|
Gitlab::CurrentSettings.snowplow_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(category, action, label: nil, property: nil, value: nil, context: nil)
|
|
|
|
return unless enabled?
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
snowplow.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def self_describing_event(schema_url, event_data_json, context: nil)
|
|
|
|
return unless enabled?
|
|
|
|
|
|
|
|
event_json = SnowplowTracker::SelfDescribingJson.new(schema_url, event_data_json)
|
2020-01-01 13:55:28 +05:30
|
|
|
snowplow.track_self_describing_event(event_json, context, (Time.now.to_f * 1000).to_i)
|
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
|
|
|
|
@snowplow ||= SnowplowTracker::Tracker.new(
|
2020-11-24 15:15:51 +05:30
|
|
|
emitter,
|
2019-12-04 20:38:33 +05:30
|
|
|
SnowplowTracker::Subject.new,
|
|
|
|
SNOWPLOW_NAMESPACE,
|
2019-12-26 22:10:19 +05:30
|
|
|
Gitlab::CurrentSettings.snowplow_app_id
|
2019-12-04 20:38:33 +05:30
|
|
|
)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
def emitter
|
|
|
|
SnowplowTracker::AsyncEmitter.new(
|
|
|
|
Gitlab::CurrentSettings.snowplow_collector_hostname,
|
|
|
|
protocol: 'https'
|
|
|
|
)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|