1. Home
  2. Docs
  3. General Settings
  4. Add Google Analytics code in child theme

Add Google Analytics code in child theme

If you need to count the accesses to your website, Google Analytics is an excellent solution.
However, to work properly, Google Analytics will ask you to add a Javascript code within each page of your website.
This can be done very simply by using the child theme.

Edit the “functions.php” file of your child theme and paste this PHP code:

function attesa_child_google_analytics() {
	<!-- Paste your Google Analytics code here and remove this message -->
add_action('wp_head', 'attesa_child_google_analytics');

This code will automatically add the Google Analytics code in the header of all the pages of your website.

This method is generic, ie it can be used to show any type of javascript code in the header of your website (example: Facebook Pixel), not necessarily Google Analytics.