Plugins can introduce bugs, security issues, and degrade performance. This tech-recipe demonstrates the most simple and secure way to add Google Analytics to your WP blog.
If performing a simple task, do not compromise your site’s security by stacking plugin on-top of plugin. Adding the Google Analytics tracking code to your blog is very easy to do manually.
Since WordPress creates a dynamic site that is always changing with new content, we need a way for the tracking code to appear on every single page and post. All pages generated within WP are built from some variety of the header.php file. Thus, if we put our tracking code in this header file, we can be assured it will trigger on every view of any part of our WP site.
1. Log in to your WordPress Backend and navigate to Appearance -> Editor
2. On the right of the screen you will see all the files used within the theme of your current site. We are looking for the header.php file. If you are using a custom theme, it is possible that it might not be named this exactly. This is rare, however, as most theme designers use common standards to maintain compatibility. Click the file when you find it and it will open in the editor on this page.
3. Take the tracking code snippet from your Google Analytics admin area. Paste it into the top of your header.php file immediately before the closing </head> tag
4. Click the Update File button to save this file. Refresh some of your WordPress generated pages and see if the tracking code appears in the source code.
Remember, with Google Analytics you will not start seeing traffic info for up to 24 to 48 hours.