From 95a2cc1a0f4f5867899d018b07a706b6a2f69bb3 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Fri, 13 Mar 2020 11:47:03 +0200 Subject: [PATCH 01/12] Don't print amp-analytics if tracking disabled. --- includes/Modules/Analytics.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index bf0a89e139d..25f50e17e28 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -380,6 +380,10 @@ protected function print_amp_gtag() { return; } + if ( $this->is_tracking_disabled() ) { + return; + } + $gtag_amp_opt = array( 'vars' => array( 'gtag_id' => $tracking_id, From 74f5d4707d24cbbd17a74da0541a6e47735bd3e2 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Fri, 13 Mar 2020 11:50:52 +0200 Subject: [PATCH 02/12] Don't output tracking opt-out in AMP context. --- includes/Modules/Analytics.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index 25f50e17e28..a9a6cdcc859 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1275,6 +1275,10 @@ private function get_home_domain() { * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out */ private function print_tracking_opt_out() { + if ( $this->context->is_amp() ) { + // AMP does not support inline custom JS. + return; + } ?> From 34a945afb3ac1c0c86186ed6ae712cfb4f8eff6e Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Fri, 13 Mar 2020 12:46:04 +0200 Subject: [PATCH 03/12] Update no-js selector to exclude valid amp contexts. --- assets/sass/components/global/_googlesitekit-noscript.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/sass/components/global/_googlesitekit-noscript.scss b/assets/sass/components/global/_googlesitekit-noscript.scss index 688ade9a4b6..9b7f497d2a0 100644 --- a/assets/sass/components/global/_googlesitekit-noscript.scss +++ b/assets/sass/components/global/_googlesitekit-noscript.scss @@ -29,7 +29,7 @@ } } -.no-js { +.no-js:not([amp-version]) { [id^="js-googlesitekit-"] { display: none; From 8c26d3a0069dc15d7a29fa57c57b4a335062ac07 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 16 Mar 2020 13:14:46 +0200 Subject: [PATCH 04/12] Add optoutElementId to amp analytics config. --- includes/Modules/Analytics.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index a9a6cdcc859..01c0a591639 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -388,12 +388,13 @@ protected function print_amp_gtag() { 'vars' => array( 'gtag_id' => $tracking_id, 'config' => array( - $tracking_id => array( + $tracking_id => array( 'groups' => 'default', 'linker' => array( 'domains' => array( $this->get_home_domain() ), ), ), + 'optoutElementId' => '__gaOptOutExtension', ), ), ); From 20d520b78d3781c316792cb6516b9b4c52132c36 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 16 Mar 2020 13:16:44 +0200 Subject: [PATCH 05/12] Update tracking opt out for AMP compatibility. --- includes/Modules/Analytics.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index 01c0a591639..d3416f19f01 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1276,12 +1276,16 @@ private function get_home_domain() { * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out */ private function print_tracking_opt_out() { + printf( '', esc_html__( 'Google Analytics user opt-out added via Site Kit by Google', 'google-site-kit' ) ); + if ( $this->context->is_amp() ) { - // AMP does not support inline custom JS. + ?> + + - Date: Mon, 16 Mar 2020 13:19:24 +0200 Subject: [PATCH 06/12] Remove guard to rely on opt-out in AMP again. --- includes/Modules/Analytics.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index d3416f19f01..2374aa9d5af 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -380,10 +380,6 @@ protected function print_amp_gtag() { return; } - if ( $this->is_tracking_disabled() ) { - return; - } - $gtag_amp_opt = array( 'vars' => array( 'gtag_id' => $tracking_id, From a89657a71228d4e5e78a3c48570c2cbb7f403acc Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 16 Mar 2020 13:32:06 +0200 Subject: [PATCH 07/12] Replace meta as opt-out element with plain script. --- includes/Modules/Analytics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index 2374aa9d5af..eb4c75c0cac 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1276,7 +1276,7 @@ private function print_tracking_opt_out() { if ( $this->context->is_amp() ) { ?> - + Date: Mon, 16 Mar 2020 13:42:27 +0200 Subject: [PATCH 08/12] Simplify printing tracking opt out. --- includes/Modules/Analytics.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index eb4c75c0cac..a96c456a20e 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1272,17 +1272,13 @@ private function get_home_domain() { * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out */ private function print_tracking_opt_out() { - printf( '', esc_html__( 'Google Analytics user opt-out added via Site Kit by Google', 'google-site-kit' ) ); - - if ( $this->context->is_amp() ) { - ?> - - - + + context->is_amp() ) : ?> + + + + Date: Mon, 16 Mar 2020 14:09:30 +0200 Subject: [PATCH 09/12] Use application/ld+json as type for now. --- includes/Modules/Analytics.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index a96c456a20e..aa1490aab06 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1274,8 +1274,8 @@ private function get_home_domain() { private function print_tracking_opt_out() { ?> - context->is_amp() ) : ?> - + context->is_amp() ) : // TODO: update script type to `text/plain` when supported by AMP plugin. ?> + From 8328b65a7a1d745297d6ba4333d914e1d4c6700a Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 16 Mar 2020 20:23:55 +0200 Subject: [PATCH 10/12] Remove irrelevant todo comment. --- includes/Modules/Analytics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index aa1490aab06..5782e7d8a9c 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -1274,7 +1274,7 @@ private function get_home_domain() { private function print_tracking_opt_out() { ?> - context->is_amp() ) : // TODO: update script type to `text/plain` when supported by AMP plugin. ?> + context->is_amp() ) : ?> From 17e7019292bf04479c863c83219e9ac942579d2f Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 16 Mar 2020 20:27:07 +0200 Subject: [PATCH 11/12] Set optoutElementId at top level. --- includes/Modules/Analytics.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Modules/Analytics.php b/includes/Modules/Analytics.php index 5782e7d8a9c..cb9581bca64 100644 --- a/includes/Modules/Analytics.php +++ b/includes/Modules/Analytics.php @@ -381,18 +381,18 @@ protected function print_amp_gtag() { } $gtag_amp_opt = array( - 'vars' => array( + 'vars' => array( 'gtag_id' => $tracking_id, 'config' => array( - $tracking_id => array( + $tracking_id => array( 'groups' => 'default', 'linker' => array( 'domains' => array( $this->get_home_domain() ), ), ), - 'optoutElementId' => '__gaOptOutExtension', ), ), + 'optoutElementId' => '__gaOptOutExtension', ); /** From 8e30592f05c016e535006ff9615a679cc36cbf3c Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 16 Mar 2020 12:45:31 -0700 Subject: [PATCH 12/12] Add support for optoutElementId to AMP Tag Manager snippet. --- includes/Modules/Tag_Manager.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/Modules/Tag_Manager.php b/includes/Modules/Tag_Manager.php index fd33805ca34..a86d2d4f70f 100644 --- a/includes/Modules/Tag_Manager.php +++ b/includes/Modules/Tag_Manager.php @@ -302,9 +302,20 @@ protected function print_amp_gtm() { return; } + // Add the optoutElementId for compatibility with our Analytics opt-out mechanism. + // This configuration object will be merged with the configuration object returned + // by the `config` attribute URL. + $gtm_amp_opt = array( + 'optoutElementId' => '__gaOptOutExtension', + ); + ?> - " data-credentials="include"> + " data-credentials="include"> + +