In this tutorial, you learn how to add Google Analytics to your WordPress blog. We will share with you various ways of integrating Google Analytics with WordPress.
Why should you use Google Analytics on your blog?
Google Analytics allows you to better understand your blog’s traffic through various data sets that are pulled quickly on Google’s colossal cloud infrastructure. This can help you make better actions and informed business decisions for your blog. It is a freemium web analytics service so there should be no reason not to try it.
How to Create a Google Analytics Account.
- Go to analytics.google.com and log in with your Google account. If you don’t have a Google account yet, you need to create one.
- Click Sign up on the page that follows.
- Fill up the New Account form. Note: Choose the right protocol (http or https) for your blog on the Website URL when filling up the form.
- Click Get Tracking ID at the bottom of the form and Accept Google Analytics Terms of Service.
- Voila! You’ll be redirected to the Google Analytics Dashboard where you can copy your Tracking ID and Global Site Tag. You’ll need those on the next steps.
Tip: You may add several properties (websites) in one Google Analytics account.
Note: For the purpose of this tutorial, we’ll share to you different options of adding Google Analytics with WordPress. However, using the first two options, you can lose your tracking code if you change your theme. You’ll need to repeat the process after changing your theme if you want Google Analytics to keep on tracking your WordPress blog. We recommend using the last two options.
Now, let’s proceed integrating Google Analytics on WordPress.
Add Google Analytics on WordPress using theme options
Add Google Analytics to WordPress without a plugin.
Here is another way of integrating Google Analytics into your WordPress site. However, we don’t recommend this method on beginners for a few reasons. You may jump to the next option if you’re not tech savvy.
- You might mess up with the codes in your theme if you’re not familiar with it. This could potentially break your site. In such a case, you’ll need to access your server to fix the error. (We’ll try to avoid that by sharing you a visual sample of how Google Analytics codes look like when inserted.)
- You can lose your tracking code when you update your theme. However, it can be avoided. You just need to copy your header.php to your child theme’s folder before. There you can paste your tracking code and you won’t have to worry about losing it on your next theme update.
Here’s how to add Google Analytics on WordPress without a plugin.
- Login to your WordPress Dashboard.
- Go to Appearance>Editor on the left side menu.
- Look for the Theme Header file (header.php) on the right side.
- Copy your Google Analytics Global Site Tag and paste it below the body tag. Refer to the image below.
- Click Update File.
That’s it! You are able to add Google Analytics on WordPress without plugin.
Let proceed on adding Google Analytics to WordPress with the use of plugin.
Add Google Analytics to WordPress using a plugin.
Using a plugin is the easiest way. There are many WordPress plugins out there that allow you to insert scripts to your theme’s header and footer area. It is best to use a plugin that is crafted for Google Analytics and WordPress integration if you wish to see analytics data within your blog without leaving. In this tutorial, we will be using one of our recommended plugins.
- Login to your WordPress Admin Dashboard.
- Go to Plugins>Add New and search for Google Analytics Dashboard for WP.
- Install then Activate the plugin. A new menu item called Google Analytics is added on the left pane of your WordPress Dashboard.
- Hover your mouse on to Google Analytics on the left pane and click General Settings.
- Click Authorize Plugin. Here you have to authorize the plugin to make a connection with your Google Analytics account and to be able to pull data.
- You’ll be asked for an Access Code on the page that follows. Click the Get Access Code link.
- Choose your Google account on the new tab that opens.
- Click Allow to generate you Access Code.
- Copy the generated code then paste it on the Access Code field on the plugin’s General Settings.
- Click Save Access Code button. You’ll see a notice that plugin authorization succeeded.
- Select your blog on the dropdown then click Lock Selection.
- That’s it! When you go to Dashboard>Home, you’ll see a Google Analytics Dashboard. You may configure the plugin settings if you’re not happy with the defaults.
Alternative Plugin for Integrating Google Analytics with WordPress
If you’re skeptical on how the plugin above uses your blog’s analytics data, you may use this alternative plugin. This plugin also allows you to add other scripts besides Google Analytics. The plugin is called Insert Headers and Footers. It allows you to print (insert) multiple scripts on either above </header> or </body> tag.
To use Insert Headers and Footers for Google Analytics follow these steps.
- Install and activate the plugin.
- Go to Settings>Insert Headers and Footers then paste your tracking code on the Script on footer box. The script will be printed above the
Add Google Analytics on WordPress using Cloudflare.
This option is perfect for bloggers who are using Cloudflare service. We will be using a Google Analytics Cloudflare app developed by Google themselves.
- Login to your Cloudflare account.
- Select your blog in which you want to integrate Google Analytics.
- Click the Apps buttons.
- Search for “Google Analytics”.
- Click Google Analytics on the search result.
- Click the Preview your site button.
- Go back to your Google Analytics account and Copy your Tracking ID.
- Paste your tracking ID on the Universal Tracking ID text field.
- Click Install on all pages.
And that’s how you add Google Analytics to your WordPress blog using Cloudflare.
For bloggers who don’t plan to change their theme in the future, you may use theme option to add tracking codes (if the feature is available). Use direct theme insertion of the Google Analytics script if you’re not terrified with codes. A plugin particularly built for Google Analytics is a good option if you want more features available on your WordPress Dashboard. The problem with such plugins is that they have access to your analytics data. Use Insert Headers and Footers plugin or integrating with Cloudflare instead if you doubt how they might use your data.
Were you able to add Google Analytics to your WordPress blog with the help of this tutorial?