Skip to content

Commit 0c5da35

Browse files
author
Adam Jazairi
authored
Merge pull request #11 from MITLibraries/DA-164_add-matomo-tracking-code
Replace Google Analytics with Matomo
2 parents 5f37eb5 + 437e00f commit 0c5da35

2 files changed

Lines changed: 15 additions & 21 deletions

File tree

app/views/layouts/_head.html.erb

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,20 @@
2525

2626
<%= yield :additional_js %>
2727

28-
<% if (ENV['GOOGLE_ANALYTICS']) %>
28+
<% if (ENV['MATOMO_URL'].present? && ENV['MATOMO_SITE_ID'].present?) %>
29+
<!-- Matomo -->
2930
<script type="text/javascript">
30-
// Google Analytics
31-
32-
(function(i,s,o,g,r,a,m){
33-
i['GoogleAnalyticsObject']=r;
34-
i[r]=i[r]||function(){
35-
(i[r].q=i[r].q||[]).push(arguments)
36-
};
37-
i[r].l=1*new Date();
38-
a=s.createElement(o);
39-
m=s.getElementsByTagName(o)[0];
40-
a.async=1;
41-
a.src=g;
42-
m.parentNode.insertBefore(a,m);
43-
44-
}(window,document,'script','https://www.google-analytics.com/analytics.js','ga'));
45-
46-
ga('create', '<%= ENV['GOOGLE_ANALYTICS'] %>', 'auto');
47-
ga('send', 'pageview');
48-
31+
var _paq = window._paq || [];
32+
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
33+
_paq.push(['trackPageView']);
34+
_paq.push(['enableLinkTracking']);
35+
(function() {
36+
var u='<%= ENV['MATOMO_URL'] %>';
37+
_paq.push(['setTrackerUrl', u+'matomo.php']);
38+
_paq.push(['setSiteId', '<%= ENV['MATOMO_SITE_ID'] %>']);
39+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
40+
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
41+
})();
4942
</script>
43+
<!-- End Matomo Code -->
5044
<% end %>

lib/mitlibraries/theme/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Mitlibraries
22
module Theme
3-
VERSION = '0.3.2'.freeze
3+
VERSION = '0.3.3'.freeze
44
end
55
end

0 commit comments

Comments
 (0)