What is Google Analytics?
Google Analytics is a free tool from Google. It counts the visitors on your website and shows where they come from and which pages they read. It works like a people counter at a shop door. To use it, you add a small piece of code to your site. Google gives you this code, or an ID that starts with G-, when you create a property. A property is Google's name for one tracked website.
First, sign in at Google Analytics with your Google account, create a property for your site, and copy the measurement ID. It looks like G-XXXXXXXXXX. Google's screens change over time, so look for the data stream details of your website.
Way 1: Use a plugin
A plugin is an add-on that gives WordPress new features. This is the easiest way.
- In your WordPress dashboard, go to Plugins, then Add New.
- Search for a Google Analytics plugin, such as Site Kit by Google or MonsterInsights.
- Click Install Now, then Activate.
- Follow the setup screen and sign in to your Google account.
- Choose your property, or paste your measurement ID when asked.
Way 2: Add the code to your theme header
A theme controls how your site looks. The header is the top part of every page. Placing the code there makes it load on every page.
- Take a backup of your site first. A mistake in theme files can break your site.
- Copy the tracking code from Google Analytics.
- Go to Appearance, then Theme File Editor. On a block theme this menu may be called Editor and work differently.
- Open the file
header.php. - Paste the code just before the closing
</head>tag. - Click Update File.
If you update your theme, this change can disappear. A child theme avoids this problem. A child theme is a small copy of your theme that keeps your own changes safe.
Way 3: Use a header and footer plugin
This is a middle path. It keeps your code safe when the theme updates, and you do not edit files.
- Go to Plugins, then Add New.
- Search for a plugin such as WPCode (Insert Headers and Footers). Install and activate it.
- Open the plugin's settings and find the Header box.
- Paste your Google Analytics code there.
- Click Save.
Check that it works
- Open your website in a new browser window.
- In Google Analytics, open the Realtime report.
- You should see yourself as one active visitor within a minute or so.
Quick recap
- Google Analytics counts visitors. You connect it with a code or a measurement ID.
- Way 1: an Analytics plugin. Easiest.
- Way 2: paste the code in
header.php. Back up first. - Way 3: a header and footer plugin. Safe from theme updates.
- Test in the Realtime report, and use only one method.