Chapter 4: Magento 2 – Google Analytics setup

The Guide:

This Chapter:

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.

  • 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

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).

  • Select View > View Settings.
  • Turn site search tracking on.
  • Set query parameters to q.

Site searches will now show in the search terms report in Google Analytics in Reporting:

Behavior > Site Search > Search Terms.

Display Features

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

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

This needs to be enabled on both the site and in Google Analytics. To do this, 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 Featuresset Enable Demographics and Interest Reports to on.
  • The second step will need to be enabled at site level.

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 E-commerce.

You should also enable Enhanced eCommerce. You will not be able to set up checkout-funnel steps unless you are using the Magento 2 Commerce Edition and have Google Tag Manager (GTM) set up. This is covered later in this chapter.

Related products can be enabled if desired. It is 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-Commerce Edition installs (and those that prefer to use 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 funnel visualization

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.

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.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.

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).

The 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.x For Universal Analytics

This is the only option available in Magento 2.x Community, but may be preferred by Commerce 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 EE For Google Tag Manager

Note: While 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 Commerce. Google Tag Manager works with Google Analytics by passing “messages” from Magento 2 to Google Tag Manager, which then needs to be configured to output the “messages” to Google Analytics.

The setup comes in three stages.

1. Google Tag Manager Configuration

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

  • 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, go to 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 done, the only necessary configuration is to set your Google Analytics property ID.
  • In GTM, go to Variables >User-Defined Variables and click Google Analytics.
  • 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.

Setting up page views

 

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

  • 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:

    • The 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 set 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 Commerce Edition of Magento 2.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 should be set as a Custom Event.
  • Configure the Fire On is set to “purchase“.

When a purchase is made, Magento 2 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.

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 layer1

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 Configuration

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

magento2-gtm

In Magento 2, 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.

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.

Benefits of using Magento 2 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

Checkout Funnel

This should be implemented by:

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

Product Impressions

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, then 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-through rate”, “which up-sells are performing well” and understanding how various features in their site are performing (e.g. promotional blocks / banners, related products, extensions such as Nosto).

Magento 2 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.

 

Content Bonus – Google Content Experiments

Google Content Experiments allows a form of split testing to be added to Magento 2. To add this functionality, it must be enabled in Magento’s backend.

google-content-experiment-screen

Keep reading to discover more about Magento 2’s Extensions and Downloads in the next chapter.