Title: gtag analytics and data-credentials=&#8221;include&#8221;
Last modified: October 12, 2019

---

# gtag analytics and data-credentials=”include”

 *  Resolved [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/gtag-analytics-and-data-credentialsinclude/)
 * Hello,
 * **gtag** type needs attribute/value pair data-credentials=”include” in **amp-
   analytics** elemenet. ref: [https://developers.google.com/analytics/devguides/collection/amp-analytics/#how_it_works](https://developers.google.com/analytics/devguides/collection/amp-analytics/#how_it_works)
 * eg:
 *     ```
       <amp-analytics type="gtag" data-credentials="include">
         ...
       </amp-analytics>
       ```
   
 * with default plugin settings doesn’t seem doable.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/gtag-analytics-and-data-credentialsinclude/#post-12024145)
 * There is a proposal to make this possible via [https://github.com/ampproject/amp-wp/pull/3095](https://github.com/ampproject/amp-wp/pull/3095)
 * However, at the moment you are correct. You should rather add the `amp-analytics`
   tag to the page yourself with the desired configuration, rather than using the
   plugin’s analytics settings.
 * You can do this via:
 *     ```
       function drlightman_print_amp_analytics() {
           $is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
           if ( ! $is_amp ) {
               return;
           }
           ?>
           <amp-analytics type="gtag" data-credentials="include">
             ...
           </amp-analytics>
           <?php
       }
   
       // Standard/Transitional modes.
       add_action( 'wp_footer', 'drlightman_print_amp_analytics' );
   
       // Reader mode.
       add_action( 'amp_post_template_footer', 'drlightman_print_amp_analytics' );
   
       // The following will be unnecessary after <https://github.com/ampproject/amp-wp/issues/2202>.
       add_filter(
       	'amp_post_template_data',
       	function( $data ) {
       		$data['amp_component_scripts'] = array_merge(
       			$data['amp_component_scripts'],
       			array(
       				'amp-analytics' => true,
       			)
       		);
       		return $data;
       	}
       );
       ```
   
    -  This reply was modified 6 years, 7 months ago by [Weston Ruter](https://wordpress.org/support/users/westonruter/).

Viewing 1 replies (of 1 total)

The topic ‘gtag analytics and data-credentials=”include”’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

## Tags

 * [gtag](https://wordpress.org/support/topic-tag/gtag/)

 * 1 reply
 * 2 participants
 * Last reply from: [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/gtag-analytics-and-data-credentialsinclude/#post-12024145)
 * Status: resolved