Product Dev Back to Ghost

How to install Google Analytics on your Ghost blog

Where do your visitors come from?
Have they been on your blog before?
How long do they stay?

These are all questions that can easily be answered through the use of Google Analytics. Google Analytics lets you do more than just see how many people have visited your blog, it provides you with valuable insights and provides you with a "big picture" overview of your traffic.

Why tracking is important

Understanding how visitors interact with your content is important to the success of your blog. In fact, even here at Ghost we keep an eye on our own traffic metrics among other things.

Understanding your traffic also gives you an opportunity to set goals for yourself, and gauge whether or not the content you're producing is helping or hurting your efforts.

Setting up Google Analytics on your blog allows you to keep track of:

1. Who visits your blog
Knowing who visits your blog can help answer a lot of questions about your audience, such as where they're located, what browser they're using, what their screen resolution is, and tons of other important information.

Having this type of information on hand is extremely valuable. For example, if the majority of visitors are accessing your blog from their phone or tablet, you could make viewing your blog on a mobile device easier, by using a design compatible with smaller screens.

2. What time visitors come to your blog
Understanding what day of the week—and even time of day—people are viewing your blog is incredibly useful. You can use this information to decide when to publish your content so that it reaches the widest audience, during your high-traffic hours.

3. What visitors do on your blog
Knowing what percentage of users interact with your content and knowing which links they clicked on can be very important when determining whether or not your content strategy is effective. For example, if you can see how your users are interacting with your content, you can work the content around what they are already interested in, and focus your strategy around what's already working.

Why use Google Analytics?

There are hundreds of services out there that will provide detailed information about your visitors, however the most popular by far would be Google Analytics.

Google Analytics is completely free, and offers a wide range of options when it comes to drilling down for specific information about your visitors. Although it's interface may be intimidating to those unfamiliar with it, Google Analytics is so widely accepted that finding support documentation takes no time at all.

Let's get started.

Setting up your account
To setup a Google Analytics account, you'll first need to create a Google Account. If you already have one, you should be able to sign into Google Analytics using your existing Google Account credentials.

Once you've logged into Google Analytics, you'll want to follow their guide to create an account for your blog. Once the account has been created, you'll receive a tracking code - copy your tracking code. Not sure where to find your tracking code? Try this.

Installing the tracking code
When you've copied the tracking code, head over to your Ghost blog and access your code injection settings. It's from this location that you will paste your tracking code into the Blog Header. The benefit of adding your tracking code using code injection, rather than adding the script manually to your theme files, is that your tracking code will still be collecting information, regardless of whether or not you switch themes—this saves time and minimizes your risk for gaps in traffic data.

The tracking code should look similar to this,

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-XXXXXXXX-X', '');
  ga('send', 'pageview');

When you've finished pasting the tracking code into the Blog Header, go ahead and Save your code injection settings.

When pasted, your code injection screen should look similar to the screenshot below,

To make sure the tracking code is working properly, you can always check your "Real-Time" reports in Google Analytics.

Now that you've got Google Analytics installed, you can start tracking your visitors and using the data collected to help improve and grow your blog.

If you have any questions about this guide, feel free to ask them in the comments below.