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.

UNLIMITED DOWNLOADS: 50+ Million Website Templates & Design Assets

All the Website Templates you need and many other design elements, are available for a monthly subscription by subscribing to Envato Elements. The subscription costs $16.50 per month and gives you unlimited access to a massive and growing library of over 50 million items that can be downloaded as often as you need (stock photos too)!

Recent Articles

How to Hide “Add to Cart” Button in WooCommerce Quickly

Once on your project, you will maybe need to disable selling products, make a catalog from your e-commerce store, or simply hide...

Agronix – Organic Farm Agriculture WordPress Theme [Free WordPress theme download]

Demo Download Agronix – Organic Farm WordPress Theme. We are Happy to presenting you the Agronix Agriculture Farming WordPress Theme. It is very easy to customize...

Roux – Creative Portfolio WordPress Theme [Free WordPress theme download]

Demo Download This is Roux, a splash of vibrant creativity your beautiful new website needs! Roux comes with tons of creative portfolio, gallery and graphic...

Brico – Plumber WordPress Theme [Free WordPress theme download]

Demo Download Features Overview Drag and drop page builder – Elementor One click install demo Demo content included WPML, RTL...

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