Skip to content

Commit d299eee

Browse files
Add static Matomo integration to theme
** Why are these changes being introduced: * We want to receive web traffic reports about users to our digital exhibits platforms, and have defined a site profile within Matomo for this purpose. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/post-36 ** How does this address that need: * This creates a separate javascript file in the theme, matomo.js, which has the needed JS calls to our Matomo instance. I'm hard-coding the property ID within this partial because there is no need for different sites to use different profiles. ** Document any side effects to this change: * This approach means that changes to our Matomo setup will require code changes to the theme, and also - as far as this change goes - means that sites which don't use our theme will not be included in our analytics. Ultimately this integration should probably be handled at the module level, but for now we've just got a theme to deal with.
1 parent e44cf65 commit d299eee

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

asset/js/matomo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var _paq = window._paq = window._paq || [];
2+
/* tracker methods like 'setCustomDimension' should be called before 'trackPageView' */
3+
_paq.push(['trackPageView']);
4+
_paq.push(['enableLinkTracking']);
5+
(function() {
6+
var u='https://matomo.libraries.mit.edu/';
7+
_paq.push(['setTrackerUrl', u+'matomo.php']);
8+
_paq.push(['setSiteId', '9']);
9+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
10+
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
11+
})();

view/layout/layout.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $this->headScript()->prependFile($this->assetUrl('vendor/jquery/jquery.min.js',
2626
$this->headScript()->appendFile($this->assetUrl('js/global.js', 'Omeka'));
2727
$this->headScript()->appendFile($this->assetUrl('js/smartmenus/dist/jquery.smartmenus.min.js'));
2828
$this->headScript()->appendFile($this->assetUrl('js/tesseract.js'));
29+
$this->headScript()->appendFile($this->assetUrl('js/matomo.js'));
2930
$this->trigger('view.layout');
3031
$userBar = $this->userBar();
3132
?>

0 commit comments

Comments
 (0)