• Get application security done the right way! Detect, Protect, Monitor, Accelerate, and more…
  • Having just a good-looking website isn’t enough. There are a lot more things that need to be done after that.

    And tracking your visitors is one of them. It’s one of those important things that you just CANNOT ignore; otherwise, you wouldn’t come to know what the source of your traffic is and how the content is performing.

    Tracking visitors isn’t the most difficult task, as it can be done with the help of Google Analytics.

    However, adding Google Analytics to your WordPress website can be slightly overwhelming because there’s more than one way to do it.

    You can either do it manually, via plugin or with the help of Cloudflare. I’ll be showing you the exact steps for adding Google Analytics via these different ways, but before that, let me tell you more about why you should install this service. 🙂

    Why you need Google Analytics?

    First things first, Google Analytics is a service that helps you identify what’s driving traffic to your website and also understand your customers better. It has tools within the service that allows you to dig deep into the insights and evaluate the overall performance of your website, after which you can better serve the users.

    Without a tool like Google Analytics, you wouldn’t know data like the countries that are driving the most traffic, the device used, the pages they’re visiting, the time till they stick around on your website, etc. You also wouldn’t be able to properly identify if your SEO results are paying off or not.

    Though there are a lot of other tracking tools too, but you may not want to use any of them because Google Analytics is the most accurate one, hands down. And on top of that, it’s completely free.

    Let’s see how to add them…

    There are a few ways to add Google Analytics to your WordPress site, which are discussed below, along with step-by-step instructions.

    Create Google Analytics Account

    First thing first, let’s get the Google Analytics setup ready. You need the tracking code no matter what option you choose. So, this is pre-requisite.

    Step 1: Set up your Google Analytics account

    Head over to their web page and sign in using your desired Gmail account.

    After that, hit the “Start Measuring” button to go ahead.

    Here, you’re required to enter your account name. It can be your website name, personal name, or whatever you prefer.

    Just know that you can handle multiple websites’ analytics from a single account, so enter a name that won’t confuse you. Once you’ve done that, keep the boxes checked as they are and hit the “next” button.

    Since you’ll be tracking your website, you need to choose the “web” option.

    In this step, you need to enter information, such as your website name, reporting time zone, etc.

    Now, you’ll see this “terms of service” popup window. Just give it a quick read and click on “I accept” after checking off the boxes.

    And we’re done with the account set up process.

    Step 2: Grab the Analytics tracking code.

    Assuming you’re signed in to your Google Analytics dashboard, click on “Admin” tab on the left side.

    After that, click on the Tracking Info > Tracking Code. Now, all you have to do is copy the huge code given under “website tracking”.

    Great, now you have the Google Analytics ready to use.

    Next, you can choose your preferred method to add them to WordPress.

    Manually

    If you don’t wish to install another plugin just for adding Google Analytics to your site, then doing it manually is a nice option.

    However, keep in mind that it’s not as feasible as doing it with a plugin, and you might also possibly lose the code when you change/update your theme in the future. If that’s alright with you, then continue with the steps below.

    Once you’ve copied the tracking code, head over to your WordPress dashboard and click on “Theme Editor” under “Appearance”.

    You need to go to the “header.php” section and paste your tracking code just before the closing “</head>” tag.

    NOTE: Don’t forget to do a backup before going ahead with this step, just in case you mess up something.

    Once you’ve pasted the code, hit “Update File” and you’re done.

    Using plugin

    If you don’t wish to take the risk of adding Google Analytics to your site manually, then you can utilize a plugin to get it done safely and easily. This is personally my favorite method, and I totally recommend it. In fact, I believe most of the people use this method and you should too if you want to cut through the unnecessary hassle.

    In this method, you can use any plugin of your choice, but I’ll be showing you two of my favorite ones.

    The first one is “Insert Headers and Footers” plugin. Here are the steps for it:

    Step 1: Install the plugin.

    Head over to your WordPress dashboard, then Plugins > Add New and type in “Insert Headers and Footers” on the search bar.

    Click on “Install Now” and activate it. I’ve already installed it so you can see it’s active.

    Step 2: Copy and paste the tracking code.

    In this step, all you have to do is copy the tracking code from your Google Analytics dashboard and paste it into the plugin. To do that, look for “Insert Headers and Footers” on the left side of your WordPress dashboard under the “Settings” tab.

    Once you click on that, you’ll see something like this:

    Here, you need to paste the code on the box under “Scripts in Header”. All done with this plugin.

    The next plugin that I was talking about is MonsterInsights. It’s quite reliable and widely used. On top of that, you can track visitors and view Analytics information right from your WordPress dashboard. Follow the below steps to set it up.

    Step 1: Install the plugin.

    As always, head over to your WordPress dashboard and click on Plugins > Add New. After that, type in MonsterInsights on the search bar.

    Once the plugin pops up, click on “Install Now” and then hit “Activate”.

    Step 2: Configure it.

    Before you can start using Google Analytics on your WordPress site via MonsterInsights, you need to configure the plugin first.

    On the left side of your dashboard, look for “Insights” and click on “Settings” under it. You’ll see a page like this.

    Click on “Connect MonstersInsights”, which will take you to the login page of your Google account. Fill in your information and hit “Next”.

    Now, you’ll see the permissions page, for which you need to click on “Allow”.

    Congrats! All the steps are done, and your Analytics should start working.

    Cloudflare

    The last method is to utilize Cloudflare Apps. They have a whole bunch of third-party integrations that allow you to extend the functionality of Cloudflare services, and Google Analytics is one of them. To set it up using this method, follow the steps below:

    Step 1: Grab Google Analytics tracking ID

    You need to log in to your Google Analytics account and go to Admin > Tracking Info > Tracking Code. Look for this shortcode that starts with “UA”.

    Copy it for now.

    Step 2: Add the code to Cloudflare Apps

    Start by logging in to your Cloudflare account (or register if you don’t have an account) and add your domain name to it. After that, click on “Apps”.

    Type in “Google Analytics” on the search bar and click on the app once it pops up. Hit the “Preview on your site” button and enter the Analytics tracking ID, which you copied.

    After that, you can click on “Install” to finish the process.

    If you are using Cloudflare, then it makes sense to use this method as you don’t have to worry about setting up plugin or editing theme files manually.

    Conclusion

    There you have it! I hope now you’ll easily be able to add Google Analytics to your WordPress website.