Commit 166bdf04 authored by Imre Farkas's avatar Imre Farkas Committed by Bob Van Landuyt

Add Snowplow integration

parent f35a3c5b
......@@ -125,6 +125,17 @@
.settings-content
= render 'performance_bar'
%section.settings.as-snowplow.no-animate#js-snowplow-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
Snowplow
%button.btn.btn-default.js-settings-toggle{ type: 'button' }
= expanded ? _('Collapse') : _('Expand')
%p
= _('Configure the %{link} integration.').html_safe % { link: link_to('Snowplow', 'https://snowplowanalytics.com/', target: '_blank') }
.settings-content
= render 'snowplow', application_setting: @application_setting
%section.settings.as-background.no-animate#js-background-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
......
......@@ -74,3 +74,4 @@
= render 'layouts/google_analytics' if extra_config.has_key?('google_analytics_id')
= render 'layouts/piwik' if extra_config.has_key?('piwik_url') && extra_config.has_key?('piwik_site_id')
= render 'layouts/snowplow' if Gitlab::CurrentSettings.snowplow_enabled?
......@@ -208,6 +208,10 @@ ActiveRecord::Schema.define(version: 20180803001726) do
t.boolean "enforce_terms", default: false
t.boolean "pseudonymizer_enabled", default: false, null: false
t.boolean "hide_third_party_offers", default: false, null: false
t.boolean "snowplow_enabled", default: false, null: false
t.string "snowplow_collector_uri"
t.string "snowplow_site_id"
t.string "snowplow_cookie_domain"
t.boolean "instance_statistics_visibility_private", default: false, null: false
t.boolean "web_ide_clientside_preview_enabled", default: false, null: false
t.integer "custom_project_templates_group_id"
......
......@@ -167,6 +167,9 @@ PUT /application/settings
| `slack_app_id` | string | yes (if `slack_app_enabled` is true) | The app id of the Slack-app |
| `slack_app_secret` | string | yes (if `slack_app_enabled` is true) | The app secret of the Slack-app |
| `slack_app_verification_token` | string | yes (if `slack_app_enabled` is true) | The verification token of the Slack-app | `terminal_max_session_time` | integer | no | Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time. |
| `snowplow_enabled` | boolean | no | Enable Snowplow integration. Default is `false`. |
| `snowplow_collector_uri` | string | yes (if `snowplow_enabled` is `true`) | Snowplow Collector URI |
| `snowplow_site_id` | string | no | Snowplow Site/Application ID |
| `two_factor_grace_period` | integer | no | Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication |
| `unique_ips_limit_enabled` | boolean | no | Limit sign in from multiple ips |
| `unique_ips_limit_per_user` | integer | yes (if `unique_ips_limit_enabled` is true) | Maximum number of ips per user |
......
This diff is collapsed.
......@@ -68,7 +68,11 @@ module EE
:slack_app_enabled,
:slack_app_id,
:slack_app_secret,
:slack_app_verification_token
:slack_app_verification_token,
:snowplow_collector_uri,
:snowplow_cookie_domain,
:snowplow_enabled,
:snowplow_site_id
]
end
......
......@@ -46,6 +46,10 @@ module EE
allow_blank: true,
length: { maximum: EMAIL_ADDITIONAL_TEXT_CHARACTER_LIMIT }
validates :snowplow_collector_uri,
presence: true,
if: :snowplow_enabled
validates :external_authorization_service_default_label,
presence: true,
if: :external_authorization_service_enabled?
......@@ -102,6 +106,10 @@ module EE
slack_app_id: nil,
slack_app_secret: nil,
slack_app_verification_token: nil,
snowplow_collector_uri: nil,
snowplow_cookie_domain: nil,
snowplow_enabled: false,
snowplow_site_id: nil,
custom_project_templates_group_id: nil
)
end
......
= form_for @application_setting, url: admin_application_settings_path, html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting)
%fieldset
.form-group
.form-check
= f.check_box :snowplow_enabled, class: 'form-check-input'
= f.label :snowplow_enabled, class: 'form-check-label' do
Enable Snowplow
.form-group
= f.label :snowplow_collector_uri, 'Collector URI', class: 'label-light'
= f.text_field :snowplow_collector_uri, class: 'form-control', placeholder: 'https://snowplow.example.com'
.form-group
= f.label :snowplow_site_id, class: 'label-light' do
Site ID
= f.text_field :snowplow_site_id, class: 'form-control'
.form-group
= f.label :snowplow_cookie_domain, class: 'label-light' do
Cookie domain
= f.text_field :snowplow_cookie_domain, class: 'form-control'
= f.submit 'Save changes', class: 'btn btn-success'
-# haml-lint:disable InlineJavaScript
:javascript
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","#{asset_url('/assets/shared/snowplow/sp.js')}","snowplow"));
window.snowplow('newTracker', 'cf', '#{Gitlab::CurrentSettings.snowplow_collector_uri}', {
appId: '#{Gitlab::CurrentSettings.snowplow_site_id}',
cookieDomain: '#{Gitlab::CurrentSettings.snowplow_cookie_domain}',
userFingerprint: false,
respectDoNotTrack: true,
forceSecureTracker: true,
post: true,
contexts: {
webPage: true,
}
});
window.snowplow('enableActivityTracking', 30, 30);
window.snowplow('trackPageView');
---
title: Add Snowplow integration
merge_request: 6642
author:
type: added
class AddBasicSnowplowAttributesToApplicationSettings < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :application_settings, :snowplow_enabled, :boolean, default: false, null: false
add_column :application_settings, :snowplow_collector_uri, :string
add_column :application_settings, :snowplow_site_id, :string
add_column :application_settings, :snowplow_cookie_domain, :string
end
end
......@@ -12,10 +12,19 @@ describe API::Settings, 'EE Settings' do
describe "PUT /application/settings" do
it 'sets EE specific settings' do
put api("/application/settings", admin), help_text: 'Help text'
put api("/application/settings", admin),
help_text: 'Help text',
snowplow_collector_uri: 'https://snowplow.example.com',
snowplow_cookie_domain: '.example.com',
snowplow_enabled: true,
snowplow_site_id: 'site_id'
expect(response).to have_gitlab_http_status(200)
expect(json_response['help_text']).to eq('Help text')
expect(json_response['snowplow_collector_uri']).to eq('https://snowplow.example.com')
expect(json_response['snowplow_cookie_domain']).to eq('.example.com')
expect(json_response['snowplow_enabled']).to be_truthy
expect(json_response['snowplow_site_id']).to eq('site_id')
end
end
......@@ -101,4 +110,13 @@ describe API::Settings, 'EE Settings' do
it_behaves_like 'settings for licensed features'
end
context "missing snowplow_collector_uri value when snowplow_enabled is true" do
it "returns a blank parameter error message" do
put api("/application/settings", admin), snowplow_enabled: true
expect(response).to have_gitlab_http_status(400)
expect(json_response['error']).to eq('snowplow_collector_uri is missing')
end
end
end
......@@ -152,6 +152,12 @@ module API
optional :help_text, type: String, desc: 'GitLab server administrator information'
optional :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.'
optional :snowplow_enabled, type: Boolean, desc: 'Enable Snowplow'
given snowplow_enabled: ->(val) { val } do
requires :snowplow_collector_uri, type: String, desc: 'Snowplow Collector URI'
optional :snowplow_cookie_domain, type: String, desc: 'Snowplow cookie domain'
optional :snowplow_site_id, type: String, desc: 'Snowplow Site/Application ID'
end
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
## EE-only END
......
......@@ -2073,6 +2073,9 @@ msgstr ""
msgid "Configure storage path and circuit breaker settings."
msgstr ""
msgid "Configure the %{link} integration."
msgstr ""
msgid "Configure the way a user creates a new account."
msgstr ""
......
......@@ -62,6 +62,23 @@ describe 'layouts/_head' do
end
end
context 'when an asset_host is set and snowplow url is set' do
let(:asset_host) { 'http://test.host' }
before do
allow(ActionController::Base).to receive(:asset_host).and_return(asset_host)
allow(Gitlab::CurrentSettings).to receive(:snowplow_enabled?).and_return(true)
allow(Gitlab::CurrentSettings).to receive(:snowplow_collector_uri).and_return('www.snow.plow')
end
it 'add a snowplow script tag with asset host' do
render
expect(rendered).to match('http://test.host/assets/shared/snowplow/')
expect(rendered).to match('window.snowplow')
expect(rendered).to match('www.snow.plow')
end
end
def stub_helper_with_safe_string(method)
allow_any_instance_of(PageLayoutHelper).to receive(method)
.and_return(%q{foo" http-equiv="refresh}.html_safe)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment