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


25
26
27
# File 'lib/gitlab/analytics/unique_visits.rb', line 25

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

.compliance_eventsObject


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

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

Instance Method Details

#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


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/analytics/unique_visits.rb', line 12

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