liferay Configure Google Tag manager(GTM) in liferay Using GTM to configure GA events


GTM simplifies the whole process of managing tags.In GTM terminology

  1. We put a GTM javascript snippet on the concerned page,in portal_normal.vm in custom theme in liferay, containing the GTM id and a data layer structure(if needed) to map values from page to variables
  2. Corresponding to data layer variables,we need to create Variables at GTM end,which retrieve data from data layer
  3. Subsequently,we create tags,which are basically fields which maps variables from data layer to events,which are triggered on certain conditions,leading to events being sent to respective tracking tool(GA,in our case).

Below is a sample of GTM javascript snippet embedded on a page,

    <!-- 1) Data layer section -->
    <script type="text/javascript">
        dataLayer = [{
                "page" : "<? Virtual path of the page ?>"
                ,"pageType" : "<? Page type ?>"
                ,"user" : {
                            "type" : "<? User type ?>"
                            ,"userId" : "<? Logged user id ?>"
                            ,"country" : "<? Logged user country ?>"
                            ,"userRole" : "<? Role of user ?>"
    <!-- 2) GTM Container -->
    <noscript><iframe src="//"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    <!-- End Google Tag Manager -->

Post including this script in page,we need to configure the respective variables and tags from GTM end.

enter image description here enter image description here enter image description here enter image description here

Post we have configured the required fields,we can view events on GA console upon a user view.

enter image description here

In order to view the data sent from portal to GA,we can use Google Analytics Debugger plugin,to view events being sent to GA via browser console.