How to Add Google Analytics to WordPress
Google Analytics is an essential tool for tracking and understanding website traffic. By adding Google Analytics to your WordPress site, you can gather data about how visitors are interacting with your site, track conversions, and optimize your content accordingly. Here’s how to easily add Google Analytics to your WordPress website:
Step 1: Set Up a Google Analytics Account
If you don’t already have a Google Analytics account, follow these steps:
- Create a Google Account (if you don’t have one already) at Google Accounts.
- Go to Google Analytics: Visit Google Analytics and sign in with your Google account.
- Set Up a Property:
- Click on Admin (bottom left corner).
- Under the Account column, click Create Account.
- Fill in your website details:
- Account Name: Choose a name for your account (e.g., your website name).
- Property Name: Enter your website name.
- Time Zone: Select the correct time zone.
- Currency: Choose your preferred currency.
- Get Tracking ID:
- After setting up the property, you’ll be given a Tracking ID (e.g., UA-12345678-1), which is unique to your website.
- Copy this tracking ID; you’ll need it to integrate Google Analytics with WordPress.
Step 2: Add Google Analytics to WordPress
There are two main methods to add Google Analytics to WordPress: Using a Plugin or Manually Adding the Code. Below, we explain both methods.
Method 1: Using a Plugin (Recommended for Beginners)
The easiest way to add Google Analytics to WordPress is by using a plugin. There are several plugins that can do this for you. We’ll use the Site Kit by Google plugin, which is official and integrates with many Google services, including Analytics.
Step 1: Install and Activate Site Kit by Google Plugin
- Go to Plugins > Add New in your WordPress dashboard.
- Search for Site Kit by Google in the search bar.
- Click Install Now next to the plugin.
- Once installed, click Activate.
Step 2: Connect Site Kit to Google Analytics
- After activation, you will see a new menu item called Site Kit in the WordPress dashboard.
- Click on Site Kit > Settings.
- You will be prompted to sign in with your Google account. Follow the instructions to allow Site Kit to access your Google account.
- Once logged in, connect your Google Analytics account by selecting it from the list of available Google services.
- Follow the prompts to grant permissions, and Site Kit will automatically fetch your Google Analytics tracking ID.
- Activate Analytics: Select the Analytics account and property you created earlier, and Site Kit will link it to your WordPress site.
Step 3: Verify Google Analytics Data
Once the plugin is connected, visit your site, and after a few hours, you should start seeing your website’s data in Google Analytics. Site Kit will also provide basic analytics reports directly within your WordPress dashboard.
Method 2: Manually Add Google Analytics Tracking Code (For Advanced Users)
If you prefer not to use a plugin, you can manually add the Google Analytics tracking code to your WordPress theme. This method involves editing your theme files, so proceed with caution. Always back up your website before making changes to the code.
Step 1: Copy Your Google Analytics Tracking Code
- Go to Google Analytics and sign in to your account.
- In the Admin section, under Property, click on Tracking Info > Tracking Code.
- Copy the Global Site Tag (gtag.js) code snippet provided by Google.
Step 2: Add the Tracking Code to Your WordPress Theme
- In your WordPress dashboard, go to Appearance > Theme Editor.
- In the right-hand sidebar, find and select header.php under your active theme.
- Paste the Google Analytics tracking code just before the closing
</head>
tag (this ensures that the code is loaded on every page of your site). - Click Update File to save the changes.
Step 3: Verify Google Analytics
After you’ve added the code to your site, give it a few hours for data to start showing up in Google Analytics. You can verify if the tracking code is working by checking the Real-Time section in Google Analytics.
Method 3: Using a Theme or Header/Footer Plugin
Another option for adding Google Analytics to WordPress is by using a theme or header/footer plugin. Plugins like Insert Headers and Footers allow you to insert custom scripts into the header or footer of your website without modifying theme files.
Step 1: Install the “Insert Headers and Footers” Plugin
- In your WordPress dashboard, go to Plugins > Add New.
- Search for Insert Headers and Footers and click Install Now.
- Once installed, click Activate.
Step 2: Add the Google Analytics Tracking Code
- After activation, go to Settings > Insert Headers and Footers.
- In the Scripts in Header section, paste the Google Analytics tracking code you copied earlier.
- Click Save to apply the changes.
Step 3: Verify Google Analytics
Check Google Analytics to ensure that it’s tracking your website’s data.
Step 4: Verify Tracking in Google Analytics
It may take a few hours for data to show up in your Google Analytics account. To check that Google Analytics is tracking properly:
- Go to Google Analytics and log in to your account.
- Select your website’s property.
- In the Real-Time report, check if visitors are being tracked on your website (e.g., open your site in a new tab to see if it reflects as active).
Tips for Using Google Analytics with WordPress
- Set up Goals and Conversions: Set up goals in Google Analytics to track important actions on your site, such as form submissions or purchases.
- Link Google Search Console: In Site Kit by Google, you can also link your Google Search Console account to get insights about search traffic and site performance.
- Monitor Site Performance: Use Google Analytics to analyze bounce rates, traffic sources, and user behavior to improve your site’s content and structure.
Conclusion
Adding Google Analytics to WordPress helps you understand user behavior and make data-driven decisions to improve your website’s performance. Whether you choose to add Google Analytics using a plugin (like Site Kit by Google), manually adding the tracking code, or using a theme/plugin, the process is simple and straightforward.