Power Your Store with Data: Setting Up Google Analytics in Magento 2

This tutorial will guide you through steps necessary to configure Google Analytics in Magento 2. The Google Analytics module comes with native Magento 2 built in, so you don’t need technical knowledge to make it work.

This tutorial will cover the following:

  • Tools and accounts required to follow this tutorial
  • Setting up an account inside Google Analytics for website tracking
  • Configuring Magento 2 to use Google Analytics Tracking ID
  • Testing Google Analytics

Requirements for Setting Up Google Analytics in Magento 2

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

To follow this tutorial successfully, you need to have the following points installed or set up on your machine and ready for use:

  • Complete development environment to support Magento 2.
  • The complete list of M2 requirements can be found here
  • Magento 2
  • Google Analytics account. You need a fully activated account so we can start creating a new website to track

Set Up Account and Website for Tracking

Navigate to the Google Analytics home page and click on the “Admin” link in the upper navigation menu. Locate and expand the “Account” drop-down in the first column, and click on the last option labeled as “Create New Account” (see screenshot below).
ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

You’ll be redirected to a new page called “New Account” where you will fill out the minimum required information to start tracking website statistics. The three required fields for setting up a new account are Account Name, Website Name and Website URL.

Account Name – the top-level identifier for your website/project. If you require multiple tracking statistics (which will use different tracking IDs), then they’ll be grouped under this account name. A good example is having one tracking ID for your development (staging/testing) environment and one tracking ID for your production (live) environment. This way you can easily separate your dummy statistics versus live traffic to your website.

Website Name – used to label your website. Google refers to this as a property.
Website URL – this is the URL of your website you want to track.
Industry Category (optional) – you can select your website’s category here.
Reporting Time Zone (optional) – you can pick which time zone will be used to present your website’s Google reports.

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

First, select the option “Website” (default) under the question What would you like to track? Continue by filling out required fields as seen on the screenshot below. Last, click “Get Tracking ID” (blue button) at the end of the form.

You’ll then be prompted to read and agree with Google’s Terms of Service Agreement. Click “I Accept.”

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

Once redirected to your brand new website account page, highlight and copy the Tracking ID as shown on the screenshot below.

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

Configuring Magento 2 to use Google Analytics Tracking ID

Log in to your Magento store backend and navigate to the section “Stores -> Configuration.”
ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

Scroll down and expand the Sales tab on the left side navigation menu, then click on the “Google API” label.

Switch the “Enable” flag to “Yes” and paste your previously copied Tracking ID into the Account Number field. Click “Save Config” then “Flush Magento Cache” from the “System -> Cache Management” section.

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

Now, refresh your Magento 2 store webpage, switch to Google Analytics “Reporting” tab, and select “Overview” under the “Real Time” category on the left hand side.

ecommerce, website design, demac media, magento 2, google analytics, magento ecommerce,magento 2 analytics

That’s it! You now have a fully functional Google Analytics tracking setup which will fire on all pages of your site. Magento 2 also supports order and product conversion tracking if eCommerce settings is enabled.