What is Google Analytics?
Google Analytics is a free tool that counts the people who visit your website. It tells you how many came, which pages they read and where they came from. Think of a notebook that quietly writes down each visitor.
Before you start
- Sign in to Google Analytics with a Google account.
- Create an account and a property. A property is Google's name for one website you track.
- Create a web data stream and type in your website address.
- Copy the measurement ID. It looks like
G-XXXXXXXXXX.
Method 1: With a plugin
A plugin is an add-on that gives WordPress new features. You do not touch any code.
- Log in to your WordPress dashboard.
- Go to Plugins, then Add New.
- Search for Site Kit by Google or another Analytics plugin you like.
- Click Install Now, then Activate.
- Follow the setup wizard and sign in with your Google account.
- Pick the property you created, or paste the measurement ID if it asks.
Method 2: Without a plugin
Here you place the tracking code in your site's header yourself. The header is the top section of every page. Google gives you a small block of code called the global site tag. It starts with a script line that loads from Google.
Warning: editing theme files can break your site if you make a typing mistake. Take a full backup first.
- Copy the tag from the data stream settings in Google Analytics. Look for the option to view tag instructions.
- In WordPress, go to Appearance, then Theme File Editor.
- Choose your active theme and open
header.php. - Find the closing
</head>tag. - Paste the tag on the line just above it.
- Click Update File.
Another way is to add the code with a function in your child theme's functions.php. A child theme is a copy of your theme that keeps your changes when the main theme updates. Use a child theme if you can, because a normal theme update erases edits in header.php.
Test it
- Open your website in a private browser window.
- In Google Analytics, go to the Realtime report.
- Check that you see one active user.
Data in other reports can take a day to show up. That is normal.
Quick recap
- Create a property in Google Analytics and copy the measurement ID.
- With a plugin: install, activate and follow the wizard.
- Without a plugin: paste the tag before
</head>inheader.php, after a backup. - Check the Realtime report to confirm it works.