2020-07-27 09:09:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Projects::ProductAnalyticsController < Projects::ApplicationController
|
|
|
|
before_action :feature_enabled!
|
|
|
|
before_action :authorize_read_product_analytics!
|
|
|
|
before_action :tracker_variables, only: [:setup, :test]
|
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :product_analytics
|
|
|
|
|
2020-07-27 09:09:42 +00:00
|
|
|
def index
|
|
|
|
@events = product_analytics_events.order_by_time.page(params[:page])
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
|
|
|
@event = product_analytics_events.try(:first)
|
|
|
|
end
|
|
|
|
|
2020-07-30 15:09:40 +00:00
|
|
|
def graphs
|
|
|
|
@graphs = []
|
|
|
|
@timerange = 30
|
|
|
|
|
|
|
|
requested_graphs = %w(platform os_timezone br_lang doc_charset)
|
|
|
|
|
|
|
|
requested_graphs.each do |graph|
|
|
|
|
@graphs << ProductAnalytics::BuildGraphService
|
|
|
|
.new(project, { graph: graph, timerange: @timerange })
|
|
|
|
.execute
|
|
|
|
end
|
2020-09-14 21:09:27 +00:00
|
|
|
|
|
|
|
@activity_graph = ProductAnalytics::BuildActivityGraphService
|
|
|
|
.new(project, { timerange: @timerange })
|
|
|
|
.execute
|
2020-07-30 15:09:40 +00:00
|
|
|
end
|
|
|
|
|
2020-07-27 09:09:42 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def product_analytics_events
|
|
|
|
@project.product_analytics_events
|
|
|
|
end
|
|
|
|
|
|
|
|
def tracker_variables
|
|
|
|
# We use project id as Snowplow appId
|
|
|
|
@project_id = @project.id.to_s
|
|
|
|
|
|
|
|
# Snowplow remembers values like appId and platform between reloads.
|
|
|
|
# That is why we have to rename the tracker with a random integer.
|
|
|
|
@random = rand(999999)
|
|
|
|
|
|
|
|
# Generate random platform every time a tracker is rendered.
|
|
|
|
@platform = %w(web mob app)[(@random % 3)]
|
|
|
|
end
|
|
|
|
|
|
|
|
def feature_enabled!
|
2022-05-06 15:09:03 +00:00
|
|
|
render_404 unless Feature.enabled?(:product_analytics, @project)
|
2020-07-27 09:09:42 +00:00
|
|
|
end
|
|
|
|
end
|