I enjoy use Google Analytics, nevertheless the boring stuff is always that if you switch themes, you’ll have to re-insert the code inside the new theme. To stop it, let’s use the power of WordPress hook to insert our analytics code without editing theme files.
1- Insert the following code into your functions.php file, and you’re done. Don’t forget to paste your Google Analytics code after replacing // Paste your Google Analytics code here
<?php
add_action('wp_footer', 'ga');
function ga() { ?>
// Paste your Google Analytics code here
<?php } ?>