How to install Google Analytics tracking code on your website
Install Google Analytics tracking code by copying the GA4 measurement ID from your Analytics property and adding the gtag code to your website's head section. The tracking code will then collect visitor data and send it to your Analytics dashboard.
Prerequisites
- A Google account
- Access to your website's HTML code
- Administrative access to Google Analytics property
Step-by-Step Instructions
Access your Google Analytics property
analytics.google.com. Select the property where you want to get the tracking code. If you don't have a property yet, create one by clicking Create Property and following the setup wizard.Navigate to Data Streams
Select or create a web stream
Copy the measurement ID
G-XXXXXXXXXX.Get the tracking code
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>Add code to your website
<head> section of every page you want to track, preferably right after the opening <head> tag. If using a CMS like WordPress, you can add it to your theme's header.php file or use a plugin.Verify installation
Common Issues & Troubleshooting
Tracking code not showing data in reports
Check that the code is placed in the <head> section, not the body. Verify the measurement ID matches exactly, and ensure there are no JavaScript errors on your page blocking the code execution.
Multiple tracking codes detected
Remove any old Universal Analytics codes (starting with UA-) and ensure you only have one GA4 tracking code per page. Multiple codes can cause data duplication or conflicts.
Code appears as text on the website
Make sure you're pasting the code in the HTML editor, not a visual/WYSIWYG editor. The code should be added to template files, not page content areas.
Real-time reports not showing visitors
Clear your browser cache, disable ad blockers that might block Analytics, and ensure you're not filtering out internal traffic. Try visiting from a different device or network to test.