dwyl / learn-google-analytics

:chart_with_upwards_trend: A quick guide to learning/using google analytics for your web app.
73 stars 12 forks source link

Learn Google Analytics

Why?

As a person building a web application, you want to know how people are using your app.

The way most web apps track usage is using a 3rd party tool and the

In most cases developers are stingy and don't want to pay for anything. This is why most of the alternatives to GA

How?

The easiest way to learn how to use Google Analytics is with the Official Google Analytics Academy online course: https://analyticsacademy.withgoogle.com/

Alternatives?

Google Analytics

The first thing you must do to get started with Google Analytics is to register your site/project:

  1. You'll first need to sign in using an existing Google account. If you haven't got one already you can sign up for one here

  2. Next you'll need to sign up at https://analytics.google.com. To do this click Sign Up, then create an account name, and add your projects website name and url. Once you've done this you can click Get Tracking ID to create your account.

  3. You'll be taken through to your new project's dashboard, where you'll see your Tracking ID. This is what you'll use to link the services such as Google Tag Manager, so take note of it (you can find it later by clicking on your account name in the top left of the dashboard, or get back to this page by going to Admin > Tracking Info):

    screen shot 2017-05-15 at 10 55 23
  4. You'll also see a block of code named Website Tracking. Take this and paste it somewhere on every page you want to track.

  5. That's it! You can now visit the Reports section in the sidebar to see your active users, and you're ready to get started tracking your own custom events:

    view users

Google Tag Manager

In order to be able to update your analysis campaigns quickly and easily you might want to use Google Tag Manager. It's a tool that allows you to edit your analysis without touching the source code. It can save time and money by providing an easy platform to test and publish your user behaviour tracking.

To get started with GTM follow these steps:

  1. If you haven't already got a Google Analytics account (detailed in the 'Google Analytics' section above), make sure you sign up to that first.

  2. Next you'll need to log in to the GTM dashboard. You do this by providing a project name and a container (web, app, amp specification). You can create your new project at https://tagmanager.google.com/?authuser=0#/admin/accounts/create

  3. Once you've successfully logged in you should see a modal with some instructions on how to get set up. It should look something like this: gtm

  4. To add a tag, click on the 'ADD A NEW TAG >' link: new tag

  5. Another modal will appear for the configuration of your tag. Click on the tag configuration box and then select which tag type you want. We've selected Universal Analytics: tag config universal

  6. Enter the tracking ID that you received when you registered your project for Google Analytics. (See 'Google Analytics' above. It's the number that starts with UA-) tracking id

  7. Next add details on when you would want the tag to be triggered. We've gone with a simple example of when a user visits any page: trigger

  8. Once you've done this click save: save

  9. Finally click 'PUBLISH' to go live: publish

  10. Once your update is live, you can go back to your Google Analytics dashboard, and see what pages your users are visiting:

    pages visited

Event Tracking

Tracking Page Views is nice, but you'd probably like to know a little more about what users are doing on your site. For this we can track events. If you're familiar with javascript you probably have a good idea of what an event is, but if not, it's some kind of change happening on the page, usually in the form of user interaction.

  1. To track an event, we first need to set up a trigger. Select Triggers from the sidebar, and click New.

    screen shot 2017-06-01 at 10 24 51
  2. From here, click Trigger Configuration and you'll see the various types of triggers you can set. For this demo, we'll be using Clicks -> All Elements.

    screen shot 2017-06-01 at 10 59 43
  3. Here is where you set up a trigger to occur in certain circumstances. In our case, let's say we want an event to trigger every time a user signs up to our newsletter, by clicking on a Sign Up button. If the HTML of our button looks like this:
    <button type="submit" id="newsletter-signup">Sign Up</button>
    Then we could use its unique id to reference it. We'd set up our trigger to fire on Some Link Clicks, with the condition of Click ID -> equals -> newsletter-signup. If you don't see Click ID in the first dropdown, you'll first need to configure Tag Manager's Built In Variables. See step 3.1 below.

screen shot 2017-06-01 at 11 02 59
  1. Now just change your trigger's name from Untitled Trigger on the top left to Newsletter Signup, and click save.

  2. Now that we've set up a trigger, it's time to apply it to a tag. You create a tag in much the same way as we did in the previous section, with the only differences being the Trigger, the Track Type. For the trigger, we'll use our new Newsletter Signup trigger:

    screen shot 2017-06-01 at 11 07 19

For the Track Type, we want to use Event. When we select this, we're given a number of options for Event Tracking Parameters. These can be used to group and give names to our events, which can make them easier to analyse. Our Newsletter Signup button will be on our homepage, so we'll use that as the category, which will group it together with any other homepage events we track on or Analytics dashboard. We'll also give it an action of Newsletter Signup so we can identify it. These values are entirely customisable, so feel free to group your events in any way you see fit. You can also use some of Tag Managers built in variables (see 3.1 above), for example, to automatically group all events on a particular page. This can be especially useful if you're using one trigger to track multiple items, that could all be on different pages (You'd most likely use Click Classes rather than Click ID for that when creating a trigger). Once you're done with your parameters, make sure you set your settings variable that you created earlier with your Tracking ID, name your tag, and click save.

screen shot 2017-06-01 at 11 23 34
  1. You're done! You can now preview or publish your changes, and view the results on your analytics dashboard, in the events tab. screen shot 2017-06-01 at 11 27 17

Custom Reports

Now that you have some more detailed data, you might want to make it a little easier to view. Custom reports can be generated in Google analytics to group together key analytics you're interested in for quick and easy access.

To create a custom report, click on Customization > Custom reports in the sidebar, then + New Custom Report.

Custom Reports

Here you'll see a few different settings. The Metric Groups are the data you're interested in viewing together, and the Dimension drilldown will determine how the data is grouped.

So you can view all of your metrics (for example: page visits, avg. time on page, certain custom events), grouped by a particular dimension (browser, country, time of day etc).

Report Metrics

You can also add filters to your reports, to ensure you only see the data you're interested in, for example, you might only want to see data from users using a particular operating system.

Report Filters

You can create more than one group of metrics to apply to the same dimension. You can also create multiple report tabs to keep related reports together.

Data Layer

For more advanced analytics, you may want to use the dataLayer. This requires a bit more javascript knowledge, but can allow for very flexible implementations that give you much greater control over what you track.

The two uses of the data layer we're going to go through in this guide are custom variables, and custom events.

  1. To get started, first you need to initialise the data layer. To do this, simply add the following code to your html, just above the Google Tag Manager script:

    <script>
    dataLayer = [];
    </script>
  2. The data layer is useful if you want to store a number of variables. To do this, you push a key-value pair into the dataLayer as you would an array. The key being the variable name you'll use to access it later.

    dataLayer.push({"key": "value"});

    Each key that you push to the data layer is unique, so if you push a key that already exists, the key-value pair will be overwritten.

  3. To trigger a custom event, you push to the data layer a key-value pair where the key is "event", and the value is the name of the event.

    dataLayer.push({"event": "myCustomEvent"})
  4. You must now configure these variables and events for use with Google Tag Manager.

    • To set a trigger to occur whenever your custom event is called, on the Tag Manager dashboard, go to Variables and click new under User-Defined Variables. Here, all you have to do is choose a variable type of Custom Event, and give it the same name as the event you're pushing to the data layer ("myCustomEvent", above). This is now available as a trigger you can add to any tag.
    • To configure a custom variable, do the same, but choose Data Layer Variable, giving it the name of your variable ("key", above). You can now access the value of this variable in the Event Tracking Parameters when you create a tag.

How to set up Scroll Tracking with time on page

google tag manager - google chrome_030

google tag manager - google chrome_031

google tag manager - google chrome_033

google tag manager - google chrome_035

google tag manager - google chrome_036

google tag manager - google chrome_038

google tag manager - google chrome_039

google tag manager - google chrome_042

Recommended Reading

Books

Note: DWYL has physical copies of all these books in London. If you want to borrow any of them, ask! They can also be found by googling for "name of the book" + "pdf"... but we highly recommended buying a copy as they are all excellent!