Adding Google Analytics Code to Website
Table of Contents
- How to Add Google Analytics Code to Website?
How to Add Google Analytics Code to Website?
You have to add the tracking code to all the web pages that you want to track using Google Analytics.
Copy the tracking code from Google Analytics. In the header part of the web pages, paste this code. The code will look like this:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TRACKING_ID');
</script>
Make sure that you enter your own Tracking ID in the code before saving the web page files.
To cross-check or verify that your tracking code is working on a website, open Google Analytics and open the property. Check the Real-Time page in the interface. It will show at least one visitor viewing the page. If it’s showing no data, check if you entered the right code properly.
If you have a WordPress website or blog, you can enter tracking code easily using a plugin, like MonsterInsights.