add google analytics

Add Google Analytics

No need to mention the importance of Google Analytics at this present competitive world. Google Analytics not only give you the statistics report of your website but also help you to grow your audience and revenue. So if you have a website then you must Add Google Analytics. Go to Google and register your website for Google Analytics.

In this article I am going to show how to Add Google Analytics both in HTML5 and WordPress Theme.

Add Google Analytics in HTML5 Website:

  • Copy this below codes and paste before ending html BODY tag.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}</script>

Important: Don’t forget to change “UA-XXXXXXXX-X” with your Analytics Code

VIDEO: Add Google Analytics in HTML5 Website:

Add Google Analytics in WordPress Theme:

Note:  Before you do any changes in your wordpress theme I will recommend you to use WordPress Child Theme. Download Free WordPress Child Theme

  1. Open functions.php file
  2. Add this below code at the end
function add_google_analytics() {
?>
<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
    try {
        var pageTracker = _gat._getTracker("UA-XXXXXXXX-X");
        pageTracker._trackPageview();
    } catch(err) {}</script>
<?php
}
add_action('wp_footer', 'add_google_analytics');

Important: Don’t forget to change “UA-XXXXXXXX-X” with your Analytics Code

VIDEO: Add Google Analytics in WordPress Theme:

Published by

Emdad Khan

I am Emdad Khan, A WordPress Theme Developer and Author of BN Web Design Website. A full time Freelancer on WordPress Theme Development & Optimization as well as blogger.

Leave a Reply