Google Analytics in OMP 1.1.1.1

Hello,

Is there some google analytics plugin for OMP? Like OJS?

Best regards,
Tarcisio Pereira

Hi @Tarcisio_Pereira,

I’m not aware of one, though we’ll likely be porting it to OMP as we approach the release of OJS 3.0 (this summer). If you want a quick way to add analytics support before then, you could add the tracking JS code into the header template.

Regards,
Alec Smecher
Public Knowledge Project Team

I was unable to put it inside a .tlp file, because of “{” smarty goes crazy.
I create a file:
lib/pkp/js/lib/googleanalytics/googleanalytics.js
With:

(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,‘script’,‘//www.google-analytics.com/analytics.js’,'ga’);
ga(‘create’, ‘MyIdHERE’, ‘auto’);
ga(‘send’, ‘pageview’);

And added the following line in lib/pkp/templates/common/headerHead.tpl:

>  68         <script src="{$baseUrl}/lib/pkp/js/lib/googleanalytics/googleanalytics.js"></script>
>  69 </head>

I leave recorded because it can serve to someone.

Best regards,
Tarcisio Pereira

Hi @Tarcisio_Pereira,

If you put JS code inside a Smarty template, you’ll likely have to escape it. See the Smarty {literal} tag for a common way of doing this.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like