How to embed code in header of child-theme

I embed Google Analytics tag in my WordPress in “How to use Google Analytics in WordPress site“. And I created child-theme in “How To Create Child Themes In WordPress“. But, how can I embed google analytics tags into the header of the child-theme?

GOAL

To embed code in heder.php by adding the function to “functions.php” in the child theme.

Method

Use function add_action( ‘wp_head‘, <function_name> ), <<<(heredoc) and echo.

add_action( 'wp_head', 'header_customize');
function header_customize() {
	$header_tags = <<<EOM

	<!--ADD YOUR HTML HERE such as <script src="..."></script>-->

	EOM;
	echo $header_tags;
}

The argument function header_customize() is added when wp_head() is called in functions.php of parent theme as below.

<?php wp_head(); ?>

You can see the code written in the source of your website.