summaryrefslogtreecommitdiff
path: root/lib/gitlab/snowplow_tracker.rb
blob: 9f12513e09eeb312301934cefe6a993cb5f542e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'snowplow-tracker'

module Gitlab
  module SnowplowTracker
    NAMESPACE = 'cf'

    class << self
      def track_event(category, action, label: nil, property: nil, value: nil, context: nil)
        tracker&.track_struct_event(category, action, label, property, value, context, Time.now.to_i)
      end

      private

      def tracker
        return unless enabled?

        @tracker ||= ::SnowplowTracker::Tracker.new(emitter, subject, NAMESPACE, Gitlab::CurrentSettings.snowplow_site_id)
      end

      def subject
        ::SnowplowTracker::Subject.new
      end

      def emitter
        ::SnowplowTracker::Emitter.new(Gitlab::CurrentSettings.snowplow_collector_hostname)
      end

      def enabled?
        Gitlab::CurrentSettings.snowplow_enabled?
      end
    end
  end
end