How to add Google Analytics to your Elementor site without a plugin

Why Google Analytics?

Most sites will want to make use of Google Analytics, which is a great free tool to track the way users find and navigate your website. However, most places will tell you that to get the code (found in Google Analytics > Admin > Tracking Info > Tracking Code) onto your website you need to either edit the theme or add a plugin. But there is a better way!

Why you shouldn’t edit the theme or header.php

If you edit header.php it will put the tracking code in the html of every page on your site in the <head> section where it should be. This seems like the cleanest solution, however every time your theme gets an update (which you should do for security and stability on browsers) the tracking code will be removed. This can become a headache having to re-add the tracking code after every theme update, and skipping the updates can become a risky option in the long run.

Why you shouldn’t use a plugin

Every plugin I’ve come across, even official ones try to do far more than you want them too. Yes they will work, and be safe when themes or the plugins themselves automatically update, but they are also more costly on resources. Good speed is half the battle on a good website, and although it doesn’t add much, you don’t want to slow your site any more than you have to with needless functions and plugins. Afterall, you want Google Analytics to do the work, not your server!

The correct way to add Google Analytics tracking code to your Elementor site

Ideally add to the functions.php of your child theme. However, if you are using “Hello Elementor” with no child, and don’t want one: Go to custom code in the Dashboard >Elementor > Custom Code:

Copy and paste the <script> tracking code into the <head> location, priority 1. Here it will be amongst the firsts thing in the html head that the browser reads and is exactly where Google Analytics expects to find it. It is safe from theme updates, and won’t use any more resources than you intend it to.