skip to Main Content

where should I add Google Tag Manager code?

From the documentation of GTM I should copy one script into head tag and another one at the start of body tag.

As far as i could research for liferay it should be added to the theme. Where exactly should I add the GTM code, (head and body code)

Any advice would be helpful, thanks! 🙂

2

Answers


  1. I also had to configure the GTM. Finally I had to edit the Liferay Theme.
    I did it by adding theme settings:

    <head>
    <title> $ {the_title} - $ {company_name} </title>
    <meta content = "initial-scale = 1.0, width = device-width" name = "viewport" />
    <@liferay_util ["include"] page = top_head_include />
    $ {google_tag_manager_header_script}
    </head>
    <body class = "$ {css_class}">
    $ {google_tag_manager_body_script}
    ...
    </body>
    

    where:

    <#assign google_tag_manager_header_script = getterUtil.getString (themeDisplay.getThemeSetting ("google.tag.manager.header.script")) />
    <#assign google_tag_manager_body_script = getterUtil.getString (themeDisplay.getThemeSetting ("google.tag.manager.body.script")) />
    

    and in the liferay-look-and-feel.xml I added:

    <setting key = "google.tag.manager.header.script" value = "" type = "textarea" configurable = "true"> </setting>
    <setting key = "google.tag.manager.body.script" value = "" type = "textarea" configurable = "true"> </setting>
    
    Login or Signup to reply.
  2. you can use by the optimal way like JBaeza said or without Theme Settings if you use the theme only for one site.
    In the last case you can paste the head script before < / head > and the body script next to the < body > tag on the portal_normal.ftl

    Regards!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search