diff --git a/app/views/layouts/_snowplow.html.haml b/app/views/layouts/_snowplow.html.haml index 10b2002dfef0e3c93924f1e279a1643ee6eb7e2f..3582deea902e25bc83612432f01d0137e03734ca 100644 --- a/app/views/layouts/_snowplow.html.haml +++ b/app/views/layouts/_snowplow.html.haml @@ -2,7 +2,7 @@ - namespace = @group || @project&.namespace || @namespace = webpack_bundle_tag 'tracker' -- if Gitlab.com? && Feature.enabled?(:browsersdk_tracking) +- if Gitlab.com? && Feature.enabled?(:browsersdk_tracking) && Feature.enabled?(:gl_analytics_tracking, Feature.current_request) = webpack_bundle_tag 'analytics' = javascript_tag do :plain diff --git a/config/feature_flags/development/gl_analytics_tracking.yml b/config/feature_flags/development/gl_analytics_tracking.yml new file mode 100644 index 0000000000000000000000000000000000000000..3a67aa058129e226b5bd56b6bb2bf560e75cf160 --- /dev/null +++ b/config/feature_flags/development/gl_analytics_tracking.yml @@ -0,0 +1,8 @@ +--- +name: gl_analytics_tracking +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132534 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/426106 +milestone: '16.5' +type: development +group: group::analytics instrumentation +default_enabled: false diff --git a/lib/gitlab/content_security_policy/config_loader.rb b/lib/gitlab/content_security_policy/config_loader.rb index 87a6d4ada706c7b67751bbdb41b6304243c2fc4d..f7c9d95c53c6bbfc4ab2401a395318035e69476b 100644 --- a/lib/gitlab/content_security_policy/config_loader.rb +++ b/lib/gitlab/content_security_policy/config_loader.rb @@ -86,7 +86,7 @@ def allow_snowplow_micro(directives) def add_browsersdk_tracking(directives) return if directives.blank? - return unless Gitlab.com? && Feature.enabled?(:browsersdk_tracking) && ENV['GITLAB_ANALYTICS_URL'].present? + return unless Gitlab.com? && ENV['GITLAB_ANALYTICS_URL'].present? default_connect_src = directives['connect-src'] || directives['default-src'] connect_src_values = Array.wrap(default_connect_src) | [ENV['GITLAB_ANALYTICS_URL']] diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index 47fb39f15acf873626e2741dd4b5820b4c0446ad..a7f8b93ee102dac5aa10247e6ba39e235e6b41cd 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -120,7 +120,9 @@ def default_avatar_url end def add_browsersdk_tracking - return unless Gitlab.com? && Feature.enabled?(:browsersdk_tracking) + return unless Gitlab.com? && Feature.enabled?(:browsersdk_tracking) && Feature.enabled?(:gl_analytics_tracking, +Feature.current_request) + return if ENV['GITLAB_ANALYTICS_URL'].blank? || ENV['GITLAB_ANALYTICS_ID'].blank? gon.analytics_url = ENV['GITLAB_ANALYTICS_URL'] diff --git a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb index 3682a65418164e8e7440cbd2215fb5198e492e0e..9e2f3bda14cf150de0db27a6b880f53653a56c8c 100644 --- a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb +++ b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb @@ -577,17 +577,6 @@ end end - context 'when browsersdk_tracking is disabled' do - before do - stub_feature_flags(browsersdk_tracking: false) - stub_env('GITLAB_ANALYTICS_URL', analytics_url) - end - - it 'does not add GITLAB_ANALYTICS_URL to connect-src' do - expect(connect_src).not_to include(analytics_url) - end - end - context 'when GITLAB_ANALYTICS_URL is not set' do before do stub_env('GITLAB_ANALYTICS_URL', nil) diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb index fc722402917b7fa8bba0b0036b59a7eb759e319f..e4684597ddf69e3d5cf7774b4a4330e48ed17760 100644 --- a/spec/lib/gitlab/gon_helper_spec.rb +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -206,6 +206,7 @@ context 'when feature flag is false' do before do stub_feature_flags(browsersdk_tracking: false) + stub_feature_flags(gl_analytics_tracking: false) end it "doesn't set the analytics_url and analytics_id" do