2020-06-22 11:09:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Analytics
|
|
|
|
class UniqueVisits
|
2020-07-23 17:09:19 -04:00
|
|
|
# Returns number of unique visitors for given targets in given time frame
|
|
|
|
#
|
|
|
|
# @param [String, Array[<String>]] targets ids of targets to count visits on. Special case for :any
|
2020-08-19 14:10:34 -04:00
|
|
|
# @param [ActiveSupport::TimeWithZone] start_date start of time frame
|
|
|
|
# @param [ActiveSupport::TimeWithZone] end_date end of time frame
|
2020-07-23 17:09:19 -04:00
|
|
|
# @return [Integer] number of unique visitors
|
2020-08-19 14:10:34 -04:00
|
|
|
def unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week)
|
2020-08-25 05:10:42 -04:00
|
|
|
events = if targets == :analytics
|
|
|
|
self.class.analytics_events
|
|
|
|
elsif targets == :compliance
|
|
|
|
self.class.compliance_events
|
|
|
|
else
|
|
|
|
Array(targets)
|
|
|
|
end
|
2020-07-21 20:09:26 -04:00
|
|
|
|
2020-08-25 05:10:42 -04:00
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: start_date, end_date: end_date)
|
2020-06-22 11:09:27 -04:00
|
|
|
end
|
|
|
|
|
2020-08-19 14:10:34 -04:00
|
|
|
class << self
|
2020-08-25 05:10:42 -04:00
|
|
|
def analytics_events
|
2020-08-19 14:10:34 -04:00
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('analytics')
|
|
|
|
end
|
2020-07-23 17:09:19 -04:00
|
|
|
|
2020-08-25 05:10:42 -04:00
|
|
|
def compliance_events
|
2020-08-19 14:10:34 -04:00
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('compliance')
|
|
|
|
end
|
2020-06-22 11:09:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|