This tutorial goes over how to add Google Analytics to your WordPress theme without a plugin.
In this case, I don’t feel like it is necessary to add ANOTHER (people can get out of hand with plugins) WordPress plugin just to add some tracking code such as Google Analytics. I also like to add the tracking code with a WordPress hook to keep the header.php
file as clean as possible.
Add Google Analytics to WordPress theme with Hook
- Create a new file in the
/inc/
directory calledtracking.php
with the following code:
Be sure you switch out the UA code (UA-XXXXXXXX-X) to your UA code. - In the
functions.php
file, add a line to the newtracking.php
file with the following code:
Now Google Analytics should be added to your WordPress theme!