Class: Gitlab::Analytics::UniqueVisits

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/analytics/unique_visits.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.analytics_eventsObject


29
30
31
# File 'lib/gitlab/analytics/unique_visits.rb', line 29

def analytics_events
  Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('analytics')
end

.compliance_eventsObject


33
34
35
# File 'lib/gitlab/analytics/unique_visits.rb', line 33

def compliance_events
  Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('compliance')
end

Instance Method Details

#track_visit(visitor_id, target_id, time = Time.zone.now) ⇒ Object


6
7
8
# File 'lib/gitlab/analytics/unique_visits.rb', line 6

def track_visit(visitor_id, target_id, time = Time.zone.now)
  Gitlab::UsageDataCounters::HLLRedisCounter.track_event(visitor_id, target_id, time)
end

#unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week) ⇒ Integer

Returns number of unique visitors for given targets in given time frame

Parameters:

  • targets (String, Array[<String>])

    ids of targets to count visits on. Special case for :any

  • start_date (ActiveSupport::TimeWithZone) (defaults to: 7.days.ago)

    start of time frame

  • end_date (ActiveSupport::TimeWithZone) (defaults to: start_date + 1.week)

    end of time frame

Returns:

  • (Integer)

    number of unique visitors


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/analytics/unique_visits.rb', line 16

def unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week)
  events = if targets == :analytics
             self.class.analytics_events
           elsif targets == :compliance
             self.class.compliance_events
           else
             Array(targets)
           end

  Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: start_date, end_date: end_date)
end