Google Analytics 4 in OJS3.3.x

Hello friends, Google analytics is currently using GA4 for page access measurement, and is leaving aside Universal Analytics (UA). Does the current GA plugin support this new GA4 version?


HI @dagosalas, our Publishing Services team recently identified this as a priority. I believe they’ll be putting out a new version of the plugin at some point.

1 Like

Any updates on this fix?

Hi @PaulS, I checked with out Publishing Services team and they have not done any work on the Google Analytics plugin. Can you point us to any information about when Google plans to remove support for UA?

1 Like

Hi @NateWr, the change in the plugin of Google Analytic for supporting GA4 is to modify the lines googleAnalytics/ at 8990b7768ebd02adc2c1fa4ba8c01c8b760d47dd · pkp/googleAnalytics · GitHub

			$googleAnalyticsCode = "
(function(i,s,o,g,r,q,a,m){i[q]=i[q]||[];i[r]=i[r]||function(){i[q].push(arguments)}; a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','$googleAnalyticsSiteId','gtag','dataLayer');
  gtag('js', new Date());
  gtag('config', '$googleAnalyticsSiteId');

I tested it, and It works, also I improved the plugin by adding a way of selecting the GA version like the picture, but the code above is the solution for the GA4 feature.


Thanks @yasielpv!

@mfelczak, were you interested in this or happy to stick with GA Universal for now?

1 Like

Google analytics plugins is not working and I found a simple works pretty well.

Please find lib/pkp/templates/frontend/components/header.tpl and paste your script
Add your google script to the {literal} ranges



If you do the same for yandex metrics, it works.

An alternative solution is using the “Custom Headers” plugin.

The benefit of this way is you don’t need to keep the track of changes in your template.

You will probably also like to check other analytics tools like Matomo or Plausible that are designed to be GDPR compliant.



Hi @marc
Thanks for your workarround to this issue.
I’m also having issues with the Google Analytics Plugin. The analytics script seems to be not suitable for GA4.

Can the “Custom Header Plugin” be applied to a multi-journal OJS instance?


Hi @jascanio, Custom Header can be applied to a multi-journal instance. I was able to get it working on ours.


1 Like

Hi @Stevel
Great. Thanks for your reply.

Hello @Stevel ,

I am also looking for a solution to GA-4 support plugin. Can you please share with us the plugin (code) or how to upgrade the current Google Analytic plugin version 1 to work with a multi-journal instance and GA-4?

Thank you so much!



Hi @dung , unfortunately I’m not familiar with the Google Analytic plugin, just the Custom Header plugin that was suggested as an alternative.


1 Like

It may be of interest to others that the solution with the custom header plugin for GA4 worked very well for us (thanks to @MariyaM for the tip!):

I have entered the Google tag’s javascript snippet into the Custom Header plugin and half an hour later the results were visible in our Analytics account.

The code starts with

<!-- Google tag (gtag.js) -->

and ends with