diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/controllers/projects/product_analytics_controller.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/controllers/projects/product_analytics_controller.rb')
-rw-r--r-- | app/controllers/projects/product_analytics_controller.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/controllers/projects/product_analytics_controller.rb b/app/controllers/projects/product_analytics_controller.rb new file mode 100644 index 00000000000..badd7671dcf --- /dev/null +++ b/app/controllers/projects/product_analytics_controller.rb @@ -0,0 +1,53 @@ +# 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] + + 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 + + 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 + end + + 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! + render_404 unless Feature.enabled?(:product_analytics, @project, default_enabled: false) + end +end |