Viewing 1 replies (of 1 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    There is a proposal to make this possible via 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 5 years, 1 month ago by Weston Ruter.
Viewing 1 replies (of 1 total)
  • The topic ‘gtag analytics and data-credentials=”include”’ is closed to new replies.