Today I am excited to launch a small new plugin that embeds the Google Analytics Tracking Code inside your theme files dynamically without you needing to hard-code it in your template files. The plugin is called as GATCE

This is pretty useful if you frequently change your WordPress Theme files, and now you don’t need to worry about leaving out your Google Analytics code accidently just because you switched to a new theme.

You can download the plugin from WordPress.

How it works

This plugin is very simple and easy to use.

  1. Download the plugin and upload and unzip to your plugins directory as you would usually do.
  2. Activate the plugin from your WordPress Admin.
  3. Go to the plugin’s options page to add your Google Analytics Tracking Code. You can find the options page under Settings >> GA Tracking Code
  4. Save your changes. You have now successfully added your GA tracking code, and it will be automatically added to all your blog pages.
  5. To verify if your Google Analytics Tracking code has been added correctly, go to any of your blog page and View the source of your page. If the plugin is working correctly you should be able to see your Google Analytics tracking code inside the head tag or near to the end of the page (near to the closing </body> tag) depending on your settings. If you don’t see your Google Analytics code, please refer to the Prerequisites section below.


The plugin requires that your theme files have one of the following action/template tags depending on where you want to place your GA tracking code.

<?php wp_head(); ?>

If you want to place the tracking code inside the head section before the closing tag.

<?php wp_footer(); ?>

If you want to place the tracking code near page end/footer before the closing tag

While these actions/template tags are widely supported by most of the theme authors, chances are there that these actions are not available in your theme file. In such a case, the plugin won’t be able to embed the Google Analytics tracking code to your theme.

However, you can easily edit your header.php file and add the tag just before the closing </head> tag or for footer place the tag towards the end of the file, just before the closing <body> tag.

Your header.php file should look similar to this (If you want place GA code inside head section).

<?php wp_head(); ?>

Your footer.php file should look similar to this.

<?php wp_footer(); ?>

Save your files.

Your plugin should work normally then.