How to Add Google Analytics to WordPress
Table of contents
There are two main methods to add Google Analytics to WordPress:
Method 1: Using a Plugin (Recommended)
Install Google Site Kit
- In your WordPress dashboard, go to Plugins > Add New.
- Search for “Google Site Kit” in the plugin directory.
- Click “Install” and then “Activate” on the Site Kit by Google plugin.
Connecting Google Analytics
- Once activated, you’ll see a new “Site Kit” menu in your WordPress dashboard.
- Click on “Start Setup” to begin the configuration process.
- Sign in with your Google account when prompted.
- Grant the necessary permissions for Site Kit to access your Google services.
Setting up Google Analytics 4 (GA4)
- In the Site Kit dashboard, go to Settings > Connected Services.
- Look for the “Analytics” section and click on “Connect Service” if not already connected.
- Choose your GA4 property from the dropdown menu. If you don’t have one, you can create a new property at this stage.
- Once selected, click “Confirm Changes” to save your settings
Verifying the Setup
- After connecting GA4, you should see both Universal Analytics (UA) and GA4 properties listed in the Analytics settings.
- Ensure that the option to place the analytics code is toggled on for both properties
- It may take up to 24 hours for data to start appearing in your GA4 dashboard.
This method is the easiest and most user-friendly, especially for beginners.
Method 2: Manual Installation
- Go to Appearance > Theme Editor in your WordPress dashboard.
- Open the Theme Header (header.php) file.
- Paste your Google Analytics tracking code just before the closing </head> tag.
- Click “Update File” to save changes.
Important Considerations
- Always back up your WordPress website before making any changes.
- If using a child theme, add the code to the child theme’s files, *NOT* the parent theme, to prevent loss during updates.
- Data may take up to 24 hours to appear in your Google Analytics account.
- Consider setting up goals in Google Analytics to track specific user actions on your site, such as when they submit a contact form.