How to add Google Analytics to WordPress?

Adding Google Analytics to your WordPress website can give you insightful data about your website’s visitors and their interactions.

Here’s a simple step-by-step guide to do it:

Option 1: Using a Plugin (For Beginners)

1. Install a Plugin: Go to your WordPress dashboard, click on “Plugins” > “Add New”. Search for “MonsterInsights” (a popular choice) and click “Install Now”, then activate it.

WordPress dashboard showing plugin search results.

 

2. Set Up Google Analytics: Once activated, MonsterInsights will prompt you to connect your Google Analytics account. Follow the on-screen instructions to authenticate and select the profile you want to track.

WordPress MonsterInsights setup guide and features overview.

 

3. Configure Settings: After linking, go through the configuration settings to tailor the tracking to your needs.

WordPress General Settings menu highlighted

Option 2: Adding Code Manually (For Advanced Users)

1. Get Tracking Code: Sign in to your Google Analytics account and select the property you’re working with. Go to “Admin” > “Tracking Info” > “Tracking Code”. Copy the Global Site Tag (gtag.js) script.

 

Screenshot of analytics platform data collection setup.

 

2. Paste Code in WordPress: Access your WordPress dashboard, go to “Appearance” > “Theme File Editor”. Find the header.php file and paste the tracking code just before the closing </head> tag.

Screenshot of WordPress dashboard with Appearance menu highlighted.

 

3. Update File: After pasting, click “Update File” to save changes.

WordPress theme editor showing CSS file.

 

 

Testing Your Setup

  • After adding Google Analytics to your WordPress site, test if it’s working by visiting your site and then checking the “”Real-Time”” report in Google Analytics to see if your visit is recorded.

 

Analytics dashboard showing zero user activity data.

Remember, using a plugin is the easiest and safest method for beginners, as it prevents potential errors that can come from directly editing theme files.