Where is the best place to insert the google analytics code in WordPress?

Every site needs to track traffic, therefore Google Analytics is here. The best free useful tracking software from Google! When you were registered and got a WordPress site, the coming question, where is the best place to insert google analytics code especially in WordPress? Is the best place header or footer?

Google recommendations:

Paste it into your web page, just before the closing </head> tag. One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. It is customary to place JavaScript code in the <head> section, and we recommend placing the snippet at the bottom of the <head> section for best performance.

Google recommend to putting your Google Analytics code in WordPress just before the closing </head> tag and this is the best place. To add the code edit the header.php in /wp-content/themes/your_theme/ and put the code into.

The code in <head> will add a little latency but Google Analytics code in the footer will reduce the number of pageviews recorded at some small margin.

The Google Analytics tracking code looks like:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'YOUR_ID');
</script>

Bonus:

To adding your Google Analytics code in the <head> also comes with the added benefit of being able to verify Google Search Console without any other manual verification methods.

Recent Articles

How to bulk delete WordPress comments in PHPMyAdmin

Any user working on the computer system has the option in quickly deleting all the WordPress comments by using MySQL or phpMyAdmin....

Removing unwanted p and br tags from WordPress

When working with HTML, you sometimes don’t like your HTML editors because of the irritating automatic bugs. Yes, we are here with...

The 7 Best WordPress Plugins For Google Analytics 2020

As the saying goes, "what is not measured, is not managed." After setting up a WordPress website, it’s important to see what’s...

How to hide all WordPress update notifications in dashboard

When working on a project, it can be frustrating to have to deal with all the update notifications that are in the...

How to add custom HTML to wp_nav_menu

WordPress has a lot of features that help us solve almost all daily tasks of any programmer or web developer. Due to...

Get in touch

Be our first-class reader, build a community and follow us on social media!

Leave A Reply

Please enter your comment!
Please enter your name here