How to insert tracking codes for Google Analytics and Google Tag Manager in WordPress AMP page

For those of who are using AMP for WordPress plugin to enable AMP pages for WordPress post, inserting the tracking codes for Google Analytics and Google Tag Manager is relatively simple:

  1. Create a copy of “html-start.php” in the plugin’s template folder, to a sub-folder called “amp” in your theme folder (create one if there isn’t any)
  2. Insert your tracking codes in the appropriate html section (for GA code, they recommend putting in the head section, and for GTM code put it in the beginning of body tag)
 * HTML start template part - start-html.php
 * @package AMP

 * Context.
 * @var AMP_Post_Template $this
<!doctype html>
<html amp <?php echo AMP_HTML_Utils::build_attributes_string( $this->get( 'html_tag_attributes' ) ); // WPCS: XSS ok. ?>>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
	<!-- AMP Analytics --><script async custom-element="amp-analytics" src=""></script>
	<?php do_action( 'amp_post_template_head', $this ); ?>
	<style amp-custom>
		<?php $this->load_parts( array( 'style' ) ); ?>
		<?php do_action( 'amp_post_template_css', $this ); ?>

<body class="<?php echo esc_attr( $this->get( 'body_class' ) ); ?>">
<!-- Google Tag Manager -->
<amp-analytics config="" data-credentials="include"></amp-analytics>

This should overwrite the default AMP code.