Magento 2.0 Guide: Google Analytics & Google Tag Manager Setup

Introduction

The final step in the SEO setup is the implementation of Google Analytics tracking. This section of the guide assumes that you already have a Google Analytics account set up and that you already know your Google Analytics property ID.

How to find your Google Analytics property ID

  • In Google Analytics Home, the code is next to the name of the property (UA-36399261-1)
  • Alternatively, in Admin, navigate to Property / Tracking Info > Tracking Code

Note: Click on the icons to get extended information and the rationale behind each change or click here to show them all.

Setting up Google Analytics for Magento 2.0

Once your Google Analytics account is set up, some extra details are needed to ensure full tracking.

Internal Site Search Tracking

This is identical to Magento 1.x. In Google Analytics admin, navigate to the appropriate view (selecting the correct option in the drop-down in the 3rd column).

  • Google Analytics admin
  • Google Analytics internal search
  • Select View > View Settings.
  • Turn site search tracking on.
  • Set query parameter to q.

Site searches will now show in the search terms report in Google Analytics (Behavior > Site Search > Search Terms in Reporting).

Display Features

Display features (also known as “Demographics and Interest Reports”) allow site owners to take take advantage of Remarketing with Analytics and Remarketing Lists for Search Ads with Analytics – remarketing across the Google advertising networks.

It also gives site owners access to demographic and interest data using inferred data based on previous usage.

  • Google Analytics Demographics
  • Google Analytics Display Features

This needs to be enabled on both the site and in Google Analytics.

To enable this in Google Analytics, in Google Analytics admin, navigate to the appropriate property (selecting the correct property in the drop-down in the second column).

  • Select Property Settings.
  • Under Advertising Features set Enable Demographics and Interest Reports to on.
  • The second step will need to be enabled at site level and is discussed in the “Setting up Magento 2.0 for Google Analytics” section.

This section can also be used to enable Enhanced Link Attribution.

Ecommerce Tracking

Ecommerce tracking will also need to be enabled in Google Analytics.

Magento 2.0 GA Ecommerce setup

  • Within the Google Analytics backend, go to Admin > View > Ecommerce Settings and check Enable Ecommerce.
  • You should also enable Enhanced Ecommerce. You will not be able to set up checkout-funnel steps unless you are using the Magento 2 Enterprise Edition and have Google Tag Manager (GTM) set up. This is covered later in this chapter.
  • Related products can be enabled if desired. It’s useful to enable it to help improve up-sell/cross-sell and related products. The related products report is only accessible via the API and shows which SKUs are commonly sold with each other. See below.

Google Analytics API output for related products

Checkout Goals and Funnels

An alternative to checkout funnel for non-Enterprise Edition installs (and those that prefer to use just UA) is Goal Funnels around the checkout page. In practice, this is very similar – it produces an output that looks a little like:

  • Google Analytics Sales Funnel
  • Google Analytics Goal Funnel

Source: https://blog.kissmetrics.com/wp-content/uploads/2013/09/google-analytics-5-funnel-visualization.jpg

This allows site owners to understand where users are dropping out during the purchase process by monitoring each step of the process. Unfortunately, this requires some work to set up in Magento – the One Page Checkout system means that each of the steps during the conversion process share the same URL.

Setting Up a Magento 1.x Checkout Goal Funnel

One of the essential Google Analytics modifications for Magento 1.x was tracking checkout abandonment (Universal Analytics update – line 13).

This modification allowed site owners to understand where users dropped out within the one-page checkout by pushing notifications (virtual page views) to Google when a user got to the next stage of the One Step Checkout process.

  • Setting up the funnel is done in Google Analytics, Admin,  View > Goals (with the correct view selected in the drop-down in the third column).
  • Create New Goal > Custom,
    • Name: Checkout
    • Type: Destination
      • Begins with /checkout/onepage/success
      • Value: Off
      • Funnel:  On

For the funnel, the following settings should be used:

Step Name Screen/Page
1 Checkout /checkout/onepage/
2 Login /checkout/onepage/login/
3 Billing Address /checkout/onepage/billing/
4 Shipping Address /checkout/onepage/shipping/
5 Shipping Method /checkout/onepage/shipping_method/
6 Payment Method /checkout/onepage/payment/
7 Order Review /checkout/onepage/review/

Setting Up a Magento 2.0.x Checkout Goal Funnel

Note: This only applies if GTM is not used. If GTM is used, site owners will eventually have access to the slightly better Checkout Funnel report.

The easiest way to implement this is via the free Google Analytics Plus Extension by Fooman. This plugin does not implement Enhanced Ecommerce but its installation enables the notifications needed to track progress.

Once this is installed, Google Analytics itself will need to be configured.

  • Setting up the funnel is done in Google Analytics, Admin, View > Goals (with the correct view selected in the drop-down in the third column).
  • Create New Goal and set the type to Custom,
    • Name: Checkout
    • Type: Destination
      • Begins with /checkout/onepage/success
      • Value: Off
      • Funnel: On

For the funnel, the following settings should be used:

Step Name Screen/Page
1 Checkout /checkout
2 Email Entered /checkout/email-entered
3 Get Shipping Rates /checkout/get-shipping-rates
4 Proceeded to Payment /checkout/payment
5 Place Order Button Clicked /checkout/place-order

Consult the manual for more details

Custom Segments

Custom segments allow site owners to analyse specific groups of users to find insights to improve marketing or site performance.

Checkout Abandonment Segment

Site owners should also set up a Google Analytics custom segment to look at users that reached the store checkout but did not convert. Site owners can focus remarketing efforts on these users by using this segment to build an audience* that can be targeted across Google.

* Display features (a GA setting) will need to be enabled on the site AND in Google Analytics for this to be possible. This is discussed later in this chapter.

Setting this up is as follows.

  • Setting up the segment is done in Google Analytics, Admin > View > Goals (with the correct view selected in the drop-down in the third column).
  • Create New Segment > Custom,
    • Segment Name: Checkout Abandoned.
    • Select Advanced > Conditions.
    • Sessions include:
      • Page exactly matches: /checkout/
    • Then click Add Filter to add Sessions Exclude
      • Transactions per session = 0

This information can also be used to calculate the checkout abandonment rate:

Basket Abandonment Rate = Number of sessions with an abandoned basket / (Number of sessions with abandoned basket + Number of transactions)

Additional setup would be necessary to understand the value of the items in the basket when the order was abandoned.

Note: Magento 2 changes the URL of the “one page checkout” from https://www.example.com/checkout/onepage/ to http://www.example.com/checkout/ so any goals in Analytics around visits of this page will need to be updated in the GA backend. This also only applies if “guest checkout” is enabled.

Setting Up Magento 2.0.x For Universal Analytics

This is the only option available in Magento 2.0.x Community but may be preferred by Enterprise site owners too.

To implement this,

  • Navigate to Stores > Configuration > Sales / Google API.
  • In Google Analytics
    • Enable: Yes
    • Account Type: Universal Analytics (field missing in Community)
    • Enable Content Experiments: Optional (covered later)
    • Account Number – your Google Analytics ID, e.g. UA-36399261-3

Setting Up Remarketing

To enable remarketing features (aka “displayfeatures”), an extension such as the free Google Analytics Plus Extension by Fooman (free) will need to be installed.

Once installed, this feature can be enabled on the above screen.

Setting Up Magento 2.0 EE For Google Tag Manager

Note: Whilst GTM Could also be added via an extension or a small amount of dev work for Community, this section only covers the implementation via the official version.

Google Tag Manager (GTM) support exists in Magento 2.0 Enterprise. Google Tag Manager works with Google Analytics by passing “messages” from Magento 2.0 to Google Tag Manager which then needs to be configured to output the “messages” to Google Analytics.

Setup comes in three stages.

1. Google Tag Manager Configuration

The following is essential for Google Analytics tracking to be captured.

If a GTM Container is not already setup
  • Visit Tag Manager to set up a new account/container. You can call these anything but recommend:
    • Account Name: Name of the company.
    • Container Name: URL
    • Where to use container: Web
  • Once the data policy is accepted, ignore the “Install Google Tag Manager” box – you will not need this code.
  • Instead, make a note of the GTM code in the top left corner – it will be in the format GTM-XXX

Import Settings

The quickest way to get the correct settings is to download our settings file and import it into GTM.

  • In GTM, Admin > Container > Import Container (ensuring that the right account and container are selected).
  • On the next screen, select the above file. Overwrite should be fine for new installations, merge for existing.
  • Once this is down, the only necessary configuration is to set your Google Analytics property ID.
    • In GTM, go to Variables > User-Defined Variables and click GoogleAnalytics.
    • Edit Configure Variable (click the pencil) and update the value to reflect your Google Analytics ID (begins UA-).
  • You can now publish the container and move on to the second section.

If you would prefer to do this manually, setup is as follows.

Step by step setup of GTM

Setting up page views

Once the container is created, page views will need to be tracked. To do this in GTM:

  • GTM step 1
  • GTM step 2
  • GTM step 3
  • GTM step 4
  • Select Tags and create a New one. Name this something useful like “GA – Page View
  • Choose Product is set as Google Analytics and Tag Type as Universal Analytics.
  • To configure the tag:
    • Tracking ID is set as the Google Analytics ID but to prevent you from re-entering this every time a tag is set up, click on the + icon and select “New Variable …”
    • Name this new variable something useful like GoogleAnalytics and set type as Constant, setting the variable value as your Google Analytics ID.
    • When this is created, your Tracking ID will be set as {{GoogleAnalytics}}.
    • Enable Display Advertising Features.
    • Set Track Type to Pageview if it is not set already.
    • To enable other configuration options for Google Analytics, see the section below.
  • This tag must be configured to Fire On each page view. Select All Pages.
  • You can then save this tag and publish the container.

Optional features

To enable optional features of Google Analytics, in the tag that is used to track page views, click edit on Configure Tag and select More settings.

  • Enhanced Link Attribution (knowing which specific link was clicked on) is enabled via More settings > Advanced Configuration > Enable Enhanced Link Attribution and setting this to True.
  • AnonymizeIP is enabled via More settings > Fields to Set and setting Field Name as anonymizeIp and value as True.
  • Cross domain tracking is enabled via More settings > Cross-Domain Tracking > Auto Link Domains. For full details, consult this five-step guide .
  • A list of other settings is available in this blog post from Simo Ahava.

Ecommerce Tracking

To enable eCommerce tracking, multiple tags need to be set up. The Enterprise Edition of Magento 2.0.x has been set up to pass “messages” containing eCommerce data to Google Tag Manager. Google Tag Manager must be configured to listen out for these messages and pass them onto Google Analytics.

To do this in GTM:

  • Select Triggers and create a New one. Name this something useful like “CE – purchase” (short for “Custom Event”).
  • Choose Event is set as Custom Event.
  • To configure the Fire On is set to “purchase“.
    • When a purchase is made, Magento 2.0 sends a “message” named “purchase” to GTM. This trigger allows GTM to listen out for it.
  • No filters are necessary; you can then save this trigger but you will need to repeat this process by creating triggers for the following event types.
    • purchase (as above)
    • refund
    • addToCart
    • checkout
    • productClick
    • productDetail
    • productImpression
    • promotionClick
    • promotionView
    • removeFromCart
  • creating triggers
  • selecting triggers
  • setting up ecommerce features

Once these triggers are set up, a tag will be needed to be created to push the data into Google Analytics. To do this:

  • Select Tags and create a New one. Name this something useful like “GA – Enhanced Ecommerce
  • Choose Product is set as Google Analytics and Tag Type as Universal Analytics.
  • To configure the tag:
    • Tracking ID is set as the Google Analytics ID. If you’ve set this up as a variable, fill this in with the name surrounded by double curly brackets, e.g. {{GoogleAnalytics}}.
    • Set Track Type to Event but leave the Event Tracking Parameters blank.
    • Set Non-Interaction Hit to True.
    • Select More Settings and  Ecommerce Features and check Enable Enhanced Ecommerce Features and Use data layer.
  • This tag must be configured to Fire On all of the Custom Event triggers that were just set up. To do this, select More and check each of these that appear.
  • You can then save this tag and publish the container.

This completes the GTM setup portion.

2. Magento 2.0 Configuration

Some settings will need to be updated in Magento’s backend.

magento2-gtm

  • In Magento 2.0, navigate to Stores > Configuration > Sales / Google API.
  • In Google Analytics:
    • Enable: Yes
    • Account Type: Google Tag Manager (field missing in Community)
    • Enable Content Experiments: Optional (covered later)
    • Container Id – your Google Analytics ID, e.g.GTM-W3PNJ9
    • The remaining fields do not need to be configured.

3. Google Analytics Checkout Funnel

The final step is to set up the checkout funnel in Google Analytics. Unfortunately, Magento’s implementation suffers from some bugs (at least in version 2.0.1). This is discussed below.

Even though this does not currently work, future releases should be able to fix this so it will be useful to have the above set up and ready.

  • Within the Google Analytics backend, go to Admin > View > Ecommerce Settings.
  • Set up checkout funnel steps as in image below – each of the steps is assigned a number; naming them makes the report easier to understand.

Step Name
1 Login
2 Billing or Addresses
3 Shipping
4 Shipping Method
5 Payment
6 Review

Benefits of using Magento 2.0 and Google Tag Manager

Implementation of this approach gives a lot more information via the advanced features in Universal Analytics. For example, the shopping behaviour analysis report (in Google Analytics Reporting > Conversions > Ecommerce > Shopping Analysis / Shopping Behaviour).

Shopping Behaviour Analysis

A separate blog post will cover this in more detail.

Issues with implementation of Google Tag Manager

Checkout Funnel

The existing implementation doesn’t work.

Cause

This is because of a bug in the message passed to Google Tag Manager from Magento 2.0.

Implementation is supposed to be similar to:

dataLayer.push({
"event": "checkout",
"ecommerce": {
"checkout": {
"actionField": {
"step": 5
},
"products": []
}
}
});

Where the step field is an Integer that relates to the stage within the checkout process that the user has reached. The code implementing this tracking in Magento 2.0 seems to be aware of this but outputs the label (text field) of the stage instead of the number. It should be a quick fix!

Product Impressions

  • product Impression 1
  • product Impression 2
  • product Impression 3

When a user sees a product, for example, listed on

  • a category page;
  • site search results; or
  • in a list of related or up-sell products on another product’s product page,

this information is different from a page view because it tells you exactly what products a user has seen on their visit to the site. Such data is useful for understanding information such as “how position on a page affects click-throughs”, “which up-sells are peforming well” and understanding how various features in their site are performing (e.g. promotional blocks/banners, related products, extensions such as Nosto).

Magento 2.0 EE sends enhanced eCommerce data to Google Tag Manager to show that the user has seen those products. For example, on http://magento2.pushonltd.co.uk/radiant-tee.html , product impressions are registered for four related products and eight up-sell products. Sometimes.

In our test implementation, this functionality doesn’t work most often on category pages and doesn’t send product list names (if category); we are uncertain why this is.

Downloadable Content Bonus – Google Content Experiments

Google Content Experiments allows a form of split testing to be added to Magento 2.0. To add this functionality, it must be enabled in Magento’s backend. A write-up of this feature is included in the downloadable version as bonus content.

google-content-experiment-screen

Copyright 2016 PushON | All Rights Reserved | PushON Ltd