Web Analytics setup

153 views
Skip to first unread message

stani...@gmail.com

unread,
Jan 9, 2020, 1:31:04 PM1/9/20
to AtoM Users
Greetings!

We are running AtoM 2.3.1 on Scientific Linux 7.4.  We want to configure Google Analytics, so I looked at https://www.accesstomemory.org/en/docs/2.5/admin-manual/maintenance/web-analytics/#google-analytics-for-tracking-institutional-pageviews and added our tracking ID to the file config/app.ym.  If I understand correctly, I should now insert a JavaScript code snippet into the pages I want to be tracked.  Could someone point me toward such script?

Thank you in advance
Stan

Dan Gillean

unread,
Jan 9, 2020, 3:10:48 PM1/9/20
to ICA-AtoM Users
Hi Stan, 

A couple of things. First, there's no need to manually add JavaScript - you just need to add your Analytics tracking ID to the config/app.yml AtoM configuration file. See: 
If you've done this already, then you should be good to go! AtoM's page templates already have the JS in place, and the tracking ID will be automatically added to them by taking the value from the config file. 

Second, the custom dimensions support (for tracking individual page views per institution in a multi-repository AtoM instance, as opposed to just overall analytics for the site) is currently only supported in AtoM 2.5 or higher, so you will need to upgrade to use that specific feature. However, just adding the GA tracking ID code to the config/app.yml page should get your overall Analytics working! 

Finally, once you make changes to the configuration files, if you haven't already, please remember to clear the application cache, and restart PHP-FPM.

Clearing the application cache: 
Restarting PHP-FPM
Also, it may take a while for analytics results to start showing up in your dashboard - I would give it a minimum of 24 hours beofre you should expect to start seeing data! 

Cheers, 

Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory
he / him


--
You received this message because you are subscribed to the Google Groups "AtoM Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ica-atom-users/2a9d2cec-532e-40c2-b112-b28a5bddae67%40googlegroups.com.

Matthew Bruton

unread,
Jan 13, 2020, 9:07:45 AM1/13/20
to AtoM Users
Dan
do the open source analytic tools have as simple a setup?
Matthew
To unsubscribe from this group and stop receiving emails from it, send an email to ica-ato...@googlegroups.com.

Dan Gillean

unread,
Jan 14, 2020, 10:47:06 AM1/14/20
to ICA-AtoM Users
Hi Matthew, 

Unfortunately, Google Analytics is the only analytics tool that has such an easy integration set up already, where you can just add the tracking code to a config file and have it work. However, I know we have made analytics work with other tools in the past. I will ask our team if they can provide any pointers on what you would need to do. 

Cheers, 

Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory
he / him

To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ica-atom-users/c4235956-5f00-4eb3-8387-d932450af289%40googlegroups.com.

Samuel Bancal

unread,
Feb 17, 2020, 8:26:14 AM2/17/20
to AtoM Users
Hi Dan,

We're also interested to know how we could integrate our AtoM instance into our own hosted Matomo instance.
As we've seen, Google Analytics is the only tool that has the facility to be setup, so we understand that we'll need to inject some JS code at the right file.

I tried to edit /usr/share/nginx/atom/apps/qubit/templates/layout.php to add that bit just before the </head> tag.

After this, I restarted php7.2-fpm, run php symfony cc , restarted memcached and restarted nginx ... but the changes never appeared.

What is the right file to change for this and what operations do we have to run then to make it apply ?

Thank you,
Samuel

Samuel Bancal

unread,
Feb 18, 2020, 4:49:28 AM2/18/20
to AtoM Users
Hi,

I've been playing a bit more with it ... and found that some URLs include our Matomo injection and some don't.
The reason I couldn't see anything yesterday was that I was GETting always the same test URL, which was the home page ... which didn't include it.

What file (if possible, only one) do we have to edit in order to inject theese 5 lines of HTML/JS just before the </head> tag of every HTML page served by AtoM?

Best regards,
Samuel

Samuel Bancal

unread,
Feb 18, 2020, 8:53:31 AM2/18/20
to AtoM Users
Little update ...

I edited the function responseFilterContent() in /usr/share/nginx/atom/apps/qubit/config/qubitConfiguration.class.php to inject our Matomo HTML/JS code.

and sent it to production with :

$ systemctl restart php7.2-fpm
$ cd /usr/share/nginx/atom
$ php symfony cache:clear

According to our tests, this works.

Any recommendation or comment on it is welcomed.

Best,
Samuel

Dan Gillean

unread,
Feb 18, 2020, 11:15:06 AM2/18/20
to ICA-AtoM Users
Hi Samuel, 

Glad to hear you found an approach that worked in the end! 

For reference, I will explain how the Google Analytics integration is currently set up, and hopefully by studying it, you can figure out how to replace it with your own code if you decide you'd like to try to follow the same pattern. 

First, we store a users API key in the apps/config.yml file. See: 
We place the code to inject the analytics key into each page in the footer file, here: 
As of 2.5, we also support the use of Google's Custom Dimensions to add per-institution analytics in a multi-repository environment. See: 
The code for this dimension is here: 
This is then injected into the templates: 

There might be more pieces that I haven't found - you might want to do some searching against our code repository. Here are the original commits - again, there may have been more with fixes along the way, but this should give you an idea of what we did: 
Here is the PR that upgraded the support to Universal Analytics and added the custom dimensions: 
Hope this helps! 
 
Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory
he / him

To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ica-atom-users/0d6efdac-6fff-4c38-ab59-65d0b282b4c5%40googlegroups.com.

Samuel Bancal

unread,
Feb 19, 2020, 5:38:34 AM2/19/20
to AtoM Users
Thank you Dan for these details.

Best regards,
Samuel

Matthew Bruton

unread,
Feb 27, 2020, 8:44:44 AM2/27/20
to ica-ato...@googlegroups.com
Hi samuel,

Where exactly in function "responseFilterContent" field did you enter the code?

Message has been deleted

Matthew Bruton

unread,
Feb 27, 2020, 9:41:36 AM2/27/20
to ica-ato...@googlegroups.com

Also, how did you create a public folder on your atom for the web install of matomo?

Samuel Bancal

unread,
Feb 28, 2020, 4:43:09 AM2/28/20
to AtoM Users
Hi Matthew,

Here is how I modified the function responseFilterContent in /usr/share/nginx/atom/apps/qubit/config/qubitConfiguration.class.php

  public function responseFilterContent(sfEvent $event, $content)
  {
    ProjectConfiguration::getActive()->loadHelpers('Javascript');

    $new_content = str_ireplace('</head>', "
<!-- ENACIT SB Matomo -->
<script type='text/javascript'>
  var _paq = window._paq || [];
  /* tracker methods like 'setCustomDimension' should be called before 'trackPageView' */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u='https://our-matomo-server.example.com/piwik/';
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '123']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src='https://our-matomo-server.example.com/piwik/matomo.php?idsite=123&amp;rec=1' style='border:0;' alt='' /></p></noscript>
<!-- End Matomo Code -->
</head>", $content);

    return str_ireplace('</head>', javascript_tag('jQuery.extend(Qubit, '.json_encode(array('relativeUrlRoot' => sfContext::getInstance()->request->getRelativeUrlRoot())).');').'</head>', $new_content);
  }

Why are you asking this?

Regards,
Samuel

Samuel Bancal

unread,
Feb 28, 2020, 4:47:59 AM2/28/20
to AtoM Users
Hi. I don't see what you mean by public folder for the web install of matomo.

All I did was to edit /usr/share/nginx/atom/apps/qubit/config/qubitConfiguration.class.php as I pasted in my previous post, restarted php and clear cache of symfony.

Can you explain a bit more please?

Regards,
Samuel

Matthew Bruton

unread,
Feb 28, 2020, 6:11:48 AM2/28/20
to ica-ato...@googlegroups.com
Hi
yes, when setting up matomo, there is a web install screen like with atom. To find the index.php of the web install, you have to set it up, as they explain, in a subdirectory of your website.
I couldn't easily find a way to do this because the atom/php set up forces everything through the index of the atom webpage.
I don't know how to create sub directories on my atom website therefore.

This all comes before the pasting of the code.

Unless there is a command line way to set up matomo?
Reply all
Reply to author
Forward
0 new messages