Skip to content

Commit

Permalink
Merge pull request #1252 from google/hotfix/1251-amp-validation
Browse files Browse the repository at this point in the history
Fix AMP validation when tracking is disabled
  • Loading branch information
felixarntz authored Mar 16, 2020
2 parents 1a91ac9 + 8e30592 commit 9d1e01a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/sass/components/global/_googlesitekit-noscript.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
}

.no-js {
.no-js:not([amp-version]) {

[id^="js-googlesitekit-"] {
display: none;
Expand Down
9 changes: 7 additions & 2 deletions includes/Modules/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected function print_amp_gtag() {
}

$gtag_amp_opt = array(
'vars' => array(
'vars' => array(
'gtag_id' => $tracking_id,
'config' => array(
$tracking_id => array(
Expand All @@ -392,6 +392,7 @@ protected function print_amp_gtag() {
),
),
),
'optoutElementId' => '__gaOptOutExtension',
);

/**
Expand Down Expand Up @@ -1273,7 +1274,11 @@ private function get_home_domain() {
private function print_tracking_opt_out() {
?>
<!-- <?php esc_html_e( 'Google Analytics user opt-out added via Site Kit by Google', 'google-site-kit' ); ?> -->
<script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
<?php if ( $this->context->is_amp() ) : ?>
<script type="application/ld+json" id="__gaOptOutExtension"></script>
<?php else : ?>
<script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
<?php endif; ?>
<?php
}

Expand Down
13 changes: 12 additions & 1 deletion includes/Modules/Tag_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);

?>
<!-- Google Tag Manager added by Site Kit -->
<amp-analytics config="<?php echo esc_url( "https://www.googletagmanager.com/amp.json?id=$container_id" ); ?>" data-credentials="include"></amp-analytics>
<amp-analytics config="<?php echo esc_url( "https://www.googletagmanager.com/amp.json?id=$container_id" ); ?>" data-credentials="include">
<script type="application/json">
<?php echo wp_json_encode( $gtm_amp_opt ); ?>
</script>
</amp-analytics>
<!-- End Google Tag Manager -->
<?php
}
Expand Down

0 comments on commit 9d1e01a

Please sign in to comment.