Skip to main content

Google Tag Manager

Overview

How to know the increase in traffic of a website every week? What is the conversion rate of turning visitors to customers this month? Mageplaza Magento 2 Google Tag Manager extension will help online store track and report these data. The module is integrated with Google Analytics, Google Tag Manager, Facebook and Google Adwords to provide statistics about Shopping Behavior, Checkout Behavior, Product Performance that allow you to track website traffic and conversion rates with a few clicks.

How to download and install

Note:

  • After installing the extension, you need to download Liquid by running the command composer require liquid/liquid or need to install the library.

How to use

Google Tag Manager:

  • To register a Google Tag Manager account, please access the following link here

  • Then, fill in the required information to register your account:

  • Copy the code below and paste it into each page of your site.

  • Get Container ID to install in your Magento store.

Google Analytics:

Visit the following link to register a Google Analytics account

First, click on Sign up to register using the Google Analytics tool

  • Select the object you want to track, either Website or Mobile Apps. Then complete your account information in the New Account registration form.

  • After completing the information, click on the "Get Tracking ID" button.

  • Another dialog will appear:

  • Select to agree to the terms of service. And click on the I accept button.

  • If the registration is successful, we will see the following interface, and get GA Tracking ID to install in Magento.

Facebook Pixel

  • Visit here to get Facebook Pixel ID.

  • First, click on the Catalog section in the top left corner of the screen. In the Measure & Report column go to the Events Manager> select Pixels.

  • This time, at Datasources, go to Facebook Pixel > Track Website Activities. Click to Get Started to create Facebook Pixel

  • You can skip the Website URL field. It is not a required field. Click Create

  • Then, you can see a Pixel ID under your Pixel Name. That is the Facebook Pixel ID you need to get.

Google Adwords

  • Access to the link ads.google.com to log in with your Gmail account and enter the website to start using Google Adwords.
  • First, click on the Start now button in the top right corner of the screen.

  • Then select a suitable campain type then click on Continue. Or you can create an account without choosing any campain.

  • Confirm your business information and click Submit.

  • Next, click on Explore your account to explore your account and get your Google Adwords ID.

  • The serial number above your gmail is Google Adwords ID.

How to configure

1. Configuration

Login to the Magento Admin, choose Stores > Configuration > Mageplaza Extensions > Google Tag Manager.

1.1. General

  • Enable: Select Yes to enable the module's feature.

1.2. Advanced Configuration

  • Deduct Tax From Transaction: Select Yes to deduct tax from Grand Total
  • Enable Brand: Select Yes to turn on the configuration, take the value according to the brand

  • Brand Attribute: There are seven attributes: manufacturer, color, size, format, gift card type, allow amount range, and can redeem. Brand will be set according to the selected Attribute.

  • Enable Variant: Select Yes to show the Variant field

  • Deduct Shipping From Transaction: Select Yes to deduct Shipping from transaction
  • Ignore Orders with value 0: Select Yes to exclude orders with the value of 0

1.3. Google Tag Manager

  • Enable: Selecting Yes to enable the use of the Google Tag Manager feature is to update and control all tags for the site.
  • ID Variable Base On: Select the variable of the product ID to be replaced displayed:
    • ID: Display the ID value of the product according to the product ID.
    • SKU: Display the ID value of the product according to the product SKU.
  • Google Tag ID:
    • Enter Google Tag Manager's ID into the Google Tag ID field to update some information of event such as in category page, product page, when adding to cart, remove fromcart, order success, search, checkout default or checkout page of One Step Checkout) extensions which help shorten checkout process to only 6 steps within a page.

  • If left blank or incorrectly entered the Container ID will not display tag information.

Note: To turn on Google Tag Manager, you need to create Trigger then Tag and click Preview or Submit in case GTM is disable.

1.4. Google Analytics 4

  • Enable: Select Yes to add items of Google Analytics 4 to Google Tag Manager.
  • Enable Google Analytics Opt Out: If yes, when customers visit a GDPR-compliant website, their data will be protected and synced to Google Analytics. Compatible with Mageplaza GDPR Professional.

  • Custom Connection: Enter the corresponding Measurement ID and API Secrets values together to track events

    • To find the measurement ID, follow these steps:

        1. In Admin, under Data collection and modification, click Data streams.
        1. Select the Web tab.
        1. Click the web data stream
        1. Find the measurement ID in the first row of the stream details.

Generate API secrets in Analytics Admin

  • In Admin, under Data collection and modification, click Data Streams.
  • Click Web, then click a web data stream.

  • In the web stream details, click Measurement Protocol API Secrets.

  • If necessary, review and accept the User Data Collection Acknowledgement.
  • Click Create

  • Enter a nickname for the secret, then click Create.

  • Click the below symbol to copy the secret so you can paste it into your POST request

  • Custom Dimension: To create a GA4 custom dimension, follow these steps:

      1. Sign in to Google Analytics and click Admin.
      1. Click Custom definitions > Custom dimensions.
      1. Click the Create custom dimension button.
      1. Enter a Name and Scope for the dimension.
      1. Click Create.

  • Custom Dimensions to collect and analyze attributes from your store that are not automatically tracked by Google Analytics 4.

  • Custom Metrics: In the Custom Definition section, choose Custom Metrics and Create Custom Metric

  • Custom Metrics to collect and analyze attributes from your store that are not automatically tracked by Google Analytics 4.

  • Note:

    • Please enter the Parameter Name that matches the GA4 side to sync data
    • On Magento site, if the Parameter Name and Index match, the data will be taken according to the latest one. Duplicate Parameter Name is not acceptable

  • Track Impression and Click By Positions: Choose where to track product impressions and clicks, including Related Product, Up-sell Product and Cross-sell Product

  • Show Events: Select one or more events in this field to track the number of impressions and clicks on the product, and synchronize some data taken from the website. Events include:

    • Search Result Page
    • Add to wishlist Customer Registration
    • Customer Login After
    • Order Refunds
    • Add Payment
    • Add Shipping
    • Add to cart
    • Remove from cart
    • Begins checkout
    • Purchase
    • View Item
    • View Item List
    • View Cart

1.5. Google Analytics eCommerce

  • Enable: Select Yes to enable the use of the Google Analytics function for the website to analyze the report.

  • ID Variable Base On: Select the variable of the product ID to be replaced displayed:

    • ID: Display the ID value of the product according to the product ID.
    • SKU: Display the ID value of the product according to the product SKU.
  • GA Tracking ID:

    • Enter Tracking ID of Google Analytics into GA Tracking ID field.
    • If you leave it blank or enter a wrong tracking ID, it will not be able to track the information.
  • Second Tracking ID:

    • Enter another Tracking ID of Google Analytics in the Second Tracking ID field so you can add the ability to track website information such as product, category page, checkout page, page cart, one step checkout page (compatible with One step checkout), remove from cart, ...

  • Enable Enhanced Link Attribution: Selecting Yes to enable allows customers to track each link, know the accuracy of the analytics report in the page by automatically distinguishing between multiple links to the same URL on one The page from which the number of customers clicked on the page or product was calculated. For example, your link to the same page is the same but the path is completely different in the same page. When you go to Gear> Bags folder, but you still click on the view of products like Grid or List, then click on each part in the Bags folder and when you click on the Grid or list are different You should install and turn on Google Analytics Debugger and Page Analytics add to the browser you are using to support the reporting feature to see the number of clicks.

  • Enable Linker:

    • If you select Yes, Google Analytics allows you to view sessions from two related websites (such as separate e-commerce and shopping cart websites) as a session. Show more Linker Domain(s) fields.
      • Linker Domain(s): Enter an additional domain link to count customer tracking from two related websites. You can import multiple domain links at the same time and be separated by a ",". You can configure additional domain links for your site when you go to Store > Configuration > Web. For example, the current link domain of your site is http://example.com. You configure another domain link when changing store view with the same content as http://mageplaza.com. So the tracking number of customers will be counted as 1 session. You can access to Audience > Overview of Google Analytics to view the exact number of sessions by day.

  • Enable Display Ads (Remarketing): Select Yes to enable Google Analytics advertising features (including Remarketing Lists for Search Ads) that can be enabled in Google Analytics from Property Settings > Data Collection.

  • Enable IP Anonymization: Select Yes to allow anonymous IP addresses of visits (http requests) sent to Google Analytics. And will be sent to the region. You can view it at Google Analytics, go to Real-Time > Overview or Locations.

Note: To see the amount of Link Attribution, Linker or some features of Google Analytics, you need to wait some time for Google Analytics to update data. You should install and enable Google Analytics Debugger and Page Analytics add to the browser you are using to support adding reporting features to see the number of clicks.

  • Enable Google Analytics Opt Out: Select Yes so that when customers enter your website, if they do not follow and accept cookies, the data will not be synced to Google Analytics, and if they do, the data will be synced to Google Analytics. This can help customers protect their information and reduce some unecessary data. This feature is compatible with Mageplaza GDPR Professional.

  • Custom Dimensions:

    • First, you should go to Admin > Custom Dimensions > Add New Customer Dimensions or Dimensions available in Google Analytics.

    • Then go to Custom Dimensions field, click Add button and select values of Name, Track Custom Attribute, Index so that when you create New Customer Report in Google Analytics, you can collect and analyze selected store attributes that are not automatically tracked by Google Analytics.

  • Custom Metrics:

    • Enter Admin > Custom Dimensions > Add New Customer Metrics or Metrics available in Google Analytics.

    • Then go to Custom Metrics field, click Add button and select values of Name, Track Custom Attribute, Index so that when you create New Customer Report in Google Analytics, you can collect and analyze selected store attributes that are not automatically tracked by Google Analytics.

    Note: To create New Custom Report in Google Analytics, Dimensions and metrics are 2 custom attributes that always go along with each other and needs creating and customizing.

1.6. Facebook Pixel

  • Enable: Select Yes to enable the use of Facebook Pixel features.

  • ID Variable Base On: Select the variable of the product ID to be replaced displayed:

    • ID: Display the ID value of the product according to the product ID.
    • SKU: Display the ID value of the product according to the product SKU.
  • Facebook supports 3 additional events: Add to Wishlist, Customer Registration, Add Payment and previous old events including Search Result Page, Begin Checkouts, Purchase, View Content, Add To Cart

  • Facebook Pixel ID:

    • Enter Facebook Pixel ID in the Facebook Pixel ID field to report and update website information such as in product page, category, checkout page, cart page, one step checkout page (compatible with Mageplaza One Step Checkout), remove from cart,...You should installl Facebook pixel helper into your browse to view information.

    • If left blank or incorrectly filled in, the Pixel ID will not report and update the website's information to Facebook.
  • Enable Advanced Matching: Select Yes to add Tracking Add to Wishlist and Advanced Matching Parameters for Facebook Pixel.

1.7. Google Adwords Conversion Tracking

  • Guide: Click to the link to configure the conversion tracking function in Google Adwords in Magento 2.

1.8. Create Tags, Triggers, Variables

  • Enter essential information to Export JSON File for Tags, Triggers, Variables such as: Measurement ID of Google Analytics 4, Conversion ID and Conversion Label of Google Ads Conversion Tracking and Google Ads Conversion Remarketing.
  • Click Export JSON File for Tags, Triggers, Variables button to Export JSON File. After that, you can upload that file to Google Tag Manager to create and import Tags, Triggers, Variables.

You can upload file here:

2. API

Google Tag Manager extension by Mageplaza supports using the REST API to get data with events such as product, category, homepage, catalog search, checkout index, checkout cart, checkout success, one step checkout, multi shipping checkout success, thank you page, add to cart, remove cart, and get head of Google Tag Manager, Google Analytics, Facebook Pixel.

Please see details here.

Guide on how to create Integration tokens can be viewed here.

3. GraphQL

Run the following command in Magento 2 root folder:

composer require mageplaza/module-google-tag-manager

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy

Google Tag Manager extension by Mageplaza supports getting data with events such as product, category, homepage, catalog search, checkout index, checkout cart, checkout success, one step checkout, multi shipping checkout success, thank you page, add to cart, remove cart, and get head of Google Tag Manager, Google Analytics, Facebook Pixel via GraphQL.

To start working with Google Tag Manager GraphQL in Magento, you need to:

  • Use Magento 2.3.x or 2.4.x. Return your site to the developer mode
  • See GraphQL requests we support here.