Commit cb275ec9 authored by Stan Hu's avatar Stan Hu

Merge branch '223768-add-google-analytics-tracking-to-sign-in-pages' into 'master'

Add Google Tag Manager to sign in/up and trial pages

See merge request gitlab-org/gitlab!38395
parents a87e3b99 36683da9
......@@ -151,6 +151,13 @@ module AuthHelper
current_user.allow_password_authentication_for_web? && !current_user.password_automatically_set?
end
def google_tag_manager_enabled?
Gitlab.com? &&
extra_config.has_key?('google_tag_manager_id') &&
extra_config.google_tag_manager_id.present? &&
!current_user
end
extend self
end
......
- page_title _("Sign up")
- add_page_specific_style 'page_bundles/signup'
- content_for :page_specific_javascripts do
= render "layouts/google_tag_manager_head"
= render "layouts/google_tag_manager_body"
.signup-page
= render 'devise/shared/signup_box',
......
- page_title _("Sign in")
- content_for :page_specific_javascripts do
= render "layouts/google_tag_manager_head"
= render "layouts/google_tag_manager_body"
#signin-container
- if any_form_based_providers_enabled?
......
- return unless google_tag_manager_enabled?
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=#{extra_config.google_tag_manager_id}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
- if google_tag_manager_enabled?
= javascript_tag nonce: true do
:plain
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','#{extra_config.google_tag_manager_id}');
---
title: Add Google Tag Manger to sign in/up and trial pages
merge_request: 38395
author:
type: changed
......@@ -1213,6 +1213,9 @@ production: &base
## Google analytics. Uncomment if you want it
# google_analytics_id: '_your_tracking_id'
## Google tag manager
# google_tag_manager_id: '_your_tracking_id'
## Piwik analytics.
# piwik_url: '_your_piwik_url'
# piwik_site_id: '_your_piwik_site_id'
......
- page_title _('Start a Free Gold Trial')
- add_page_specific_style 'page_bundles/signup'
- content_for :page_specific_javascripts do
= render "layouts/google_tag_manager_head"
= render "layouts/google_tag_manager_body"
%h2.center.pt-6.pb-4.gl-mb-0
= _('Start a Free Gold Trial')
......
- page_title _('Start a Free Gold Trial')
- content_for :page_specific_javascripts do
= render "layouts/google_tag_manager_head"
= render "layouts/google_tag_manager_body"
%h3.center.pt-6
= _('Almost there')
......
......@@ -260,4 +260,41 @@ RSpec.describe AuthHelper do
end
end
end
describe '#google_tag_manager_enabled?' do
let(:is_gitlab_com) { true }
let(:user) { nil }
before do
allow(Gitlab).to receive(:com?).and_return(is_gitlab_com)
stub_config(extra: { google_tag_manager_id: 'key' })
allow(helper).to receive(:current_user).and_return(user)
end
subject(:google_tag_manager_enabled?) { helper.google_tag_manager_enabled? }
context 'on gitlab.com and a key set without a current user' do
it { is_expected.to be_truthy }
end
context 'when not on gitlab.com' do
let(:is_gitlab_com) { false }
it { is_expected.to be_falsey }
end
context 'when current user is set' do
let(:user) { instance_double('User') }
it { is_expected.to be_falsey }
end
context 'when no key is set' do
before do
stub_config(extra: {})
end
it { is_expected.to be_falsey }
end
end
end
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