Legacy Knowledge Base
Published Jul. 2, 2025

How to use Google Analytics 4 in Liferay

Written By

Roberto Díaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • In Liferay you can configure Google Analytics (GA) under Configuration > Site Settings > Advanced > Analytics
  • You can see 3 fields related with GA:
    • Google Analytics ID (Set the Google Analytics ID that is used for this set of pages).
    • Google Analytics Create Method Only Custom Configuration (Set the Google Analytics create method's custom options that are used for this set of pages).
    • Google Analytics Custom Configuration (Set the Google Analytics custom options that are used for this set of pages).
  • If you use these fields to configure Google Analytics 4 (GA4), it doesn't work.

Environment

  • Liferay DXP 7.0
  • Liferay DXP 7.1+ 
  • Liferay DXP 7.4 update 59

Resolution

  • These fields are just a help for using Google Analytics and could not be used to Google Analytics 4.
    • Liferay only adds these values to a JS script that is introduced in the head of the pages and uses as base script http://www.google-analytics.com/analytics.js.
    • GA4 uses a different JS base script: https://www.googletagmanager.com/gtag/js.
  • So, to use GA4 you have to add this base script in your pages and add a custom script to configure it.
  • Liferay provides a mechanism to add this kind of elements:
    • Modify admin.analytics.typesproperty (if the settings at Control panel/Instance Settings/Miscellaneous/Analytics were never saved before; if they were, then modify from there rather then the portal property)
      • The default value is google\npiwik.
      • If you add a new option, admin.analytics.types=google\npiwik\nga4, a new field appears in the Configuration > Site Settings > Advanced > Analytics for Ga4: GA4-field.png
    • In this text field you could add the GA4 implementation.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base