From 085ea357268574c7bbd20b7283c84eedbf2b06fd Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Tue, 25 Dec 2012 23:35:41 +0100 Subject: [PATCH] Add Google Analytics support --- app/helpers/application_helper.rb | 4 ++++ app/views/layouts/_head.html.haml | 1 + app/views/shared/_google_analytics.html.haml | 9 +++++++++ config/gitlab.yml.example | 12 +++++++++++- config/initializers/1_settings.rb | 3 +++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/views/shared/_google_analytics.html.haml diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 52715a265bd..359d5cdaef5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -160,4 +160,8 @@ module ApplicationHelper image_tag("authbuttons/#{file_name}", alt: "Sign in with #{provider.to_s.titleize}") end + + def analytics_enable? + Gitlab.config.analytics.enabled and Rails.env.production? + end end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 4a0f60d36c2..013ff6d15e0 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -15,3 +15,4 @@ - if current_controller?(:issues) = auto_discovery_link_tag(:atom, project_issues_url(@project, :atom, private_token: current_user.private_token), title: "#{@project.name} issues") = csrf_meta_tags + = render "shared/google_analytics" if analytics_enable? diff --git a/app/views/shared/_google_analytics.html.haml b/app/views/shared/_google_analytics.html.haml new file mode 100644 index 00000000000..e8d4b914668 --- /dev/null +++ b/app/views/shared/_google_analytics.html.haml @@ -0,0 +1,9 @@ +:javascript + var _gaq = _gaq || []; + _gaq.push(['_setAccount', '#{ Gitlab.config.analytics.tracking_id }']); + _gaq.push(['_trackPageview']); + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index f47625eb132..3a603159cfa 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -1,4 +1,4 @@ -# # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # Gitlab application config file # # # # # # # # # # # # # # # # # # # # @@ -109,3 +109,13 @@ git: max_size: 5242880 # 5.megabytes # Git timeout to read commit, in seconds timeout: 10 + git_timeout: 10 + +# +# 4. Other settings: +# ========================== + +# Google Analytics +analytics: + enabled: false + tracking_id: '_your_tracking_id' diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index efc81611835..f2c965a0a45 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -75,3 +75,6 @@ Settings['git'] ||= Settingslogic.new({}) Settings.git['max_size'] ||= 5242880 # 5.megabytes Settings.git['bin_path'] ||= '/usr/bin/git' Settings.git['timeout'] ||= 10 + +Settings['analytics'] ||= Settingslogic.new({}) +Settings.analytics['enabled'] ||= false -- GitLab