-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from murny/ga/piwik-analytics
Add google/matomo analytics
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
$(document).on('turbolinks:load', function() { | ||
// Google Analytics | ||
if (typeof gtag === 'function') { | ||
return gtag('config', '<%= Rails.application.secrets.google_analytics_token %>', { | ||
'page_path': window.location.pathname | ||
}); | ||
} | ||
// Matomo Analytics | ||
if (window._paq != null) { | ||
return _paq.push(['trackPageView']); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<% if Rails.application.secrets.google_analytics_token.present? %> | ||
<!-- Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= Rails.application.secrets.google_analytics_token %>"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
</script> | ||
<!-- End Google Analytics --> | ||
<% end %> | ||
|
||
<% if Rails.application.secrets.matomo_url.present? && Rails.application.secrets.matomo_site_id.present? %> | ||
<!-- Matomo --> | ||
<script type="text/javascript"> | ||
var _paq = _paq || []; | ||
// tracker methods like "setCustomDimension" should be called before "trackPageView" | ||
_paq.push(['trackPageView']); | ||
_paq.push(['enableLinkTracking']); | ||
(function() { | ||
var u="//<%= Rails.application.secrets.matomo_url %>/"; | ||
_paq.push(['setTrackerUrl', u+'piwik.php']); | ||
_paq.push(['setSiteId', <%= Rails.application.secrets.matomo_site_id %>]); | ||
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+'piwik.js'; s.parentNode.insertBefore(g,s); | ||
})(); | ||
</script> | ||
<!-- End Matomo Code --> | ||
|
||
<!-- Matomo Image Tracker --> | ||
<noscript> | ||
<p><img src="//<%= Rails.application.secrets.matomo_url %>/piwik.php?idsite=<%= Rails.application.secrets.matomo_site_id %>&rec=1" style="border:0" alt="" /></p> | ||
</noscript> | ||
<!-- End Matomo --> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters