Browse Source

Add matomo/piwik analytics support

pull/405/head
Jus de Patate_ 5 years ago
parent
commit
c7c766a0ca
No known key found for this signature in database GPG Key ID: AD0245537CA3FC0D
10 changed files with 56 additions and 23 deletions
  1. +1
    -1
      README.md
  2. +9
    -0
      config/config.ini.example
  3. +1
    -1
      system/admin/views/layout.html.php
  4. +39
    -15
      system/includes/functions.php
  5. +1
    -1
      themes/blog/layout.html.php
  6. +1
    -1
      themes/clean/layout.html.php
  7. +1
    -1
      themes/default/layout.html.php
  8. +1
    -1
      themes/logs/layout.html.php
  9. +1
    -1
      themes/twentyfifteen/layout.html.php
  10. +1
    -1
      themes/twentysixteen/layout.html.php

+ 1
- 1
README.md View File

@ -21,7 +21,7 @@ Features
- Social Links
- Disqus Comments (optional)
- Facebook Comments (optional)
- Google Analytics
- Google Analytics and Matomo
- Built-in Search
- Related Posts
- Per Post Navigation (previous and next post)


+ 9
- 0
config/config.ini.example View File

@ -55,9 +55,18 @@ google.wmt.id = ""
; Google+ publisher
google.publisher = ""
; -- Analytics --
analytics = ""
; "google" or "matomo"
; Google analytics
google.analytics.id = ""
; Matomo config
matomo.url = ""
matomo.siteid = ""
; rules for matomo.url: it should start with "://" and end with "/"
; Google reCaptcha
; https://www.google.com/recaptcha/admin. Options "false" and "true"


+ 1
- 1
system/admin/views/layout.html.php View File

@ -57,6 +57,6 @@
</div>
</div>
</div>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 39
- 15
system/includes/functions.php View File

@ -1942,27 +1942,51 @@ function publisher()
// Google Analytics
function analytics($analyticsDir = null)
{
$analytics = config('google.analytics.id');
if ($analyticsDir === null) {
$analyticsDir = '//www.google-analytics.com/analytics.js';
} else {
$analyticsDir = site_url() . 'themes/' . $analyticsDir . 'analytics.js';
}
$script = <<<EOF
<script>
(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','{$analyticsDir}','ga');
ga('create', '{$analytics}', 'auto');
ga('send', 'pageview');
</script>
if (config("analytics") == "google") {
$analytics = config('google.analytics.id');
if ($analyticsDir === null) {
$analyticsDir = '//www.google-analytics.com/analytics.js';
} else {
$analyticsDir = site_url() . 'themes/' . $analyticsDir . 'analytics.js';
}
$script = <<<EOF
<script>
(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','{$analyticsDir}','ga');
ga('create', '{$analytics}', 'auto');
ga('send', 'pageview');
</script>
EOF;
} elseif (config("analytics") == "matomo") {
$analytics = config('matomo.siteid');
$analyticsDir = config('matomo.url');
$script = <<<EOF
<script type="text/javascript">
var _paq = window._paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="{$analyticsDir}";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{$analytics}']);
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="{$analyticsDir}matomo.php?idsite={$analytics}&amp;rec=1" style="border:0;" alt="" /></p></noscript>
EOF;
}
if (!empty($analytics)) {
return $script;
}
}
// Menu
function menu($custom = null)
{


+ 1
- 1
themes/blog/layout.html.php View File

@ -197,6 +197,6 @@
<!-- Javascript -->
<script type="text/javascript" src="<?php echo site_url();?>themes/blog/js/jquery-latest.min.js"></script>
<script type="text/javascript" src="<?php echo site_url();?>themes/blog/js/bootstrap.min.js"></script>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 1
- 1
themes/clean/layout.html.php View File

@ -50,6 +50,6 @@
<section id="content">
<?php echo content() ?>
</section>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 1
- 1
themes/default/layout.html.php View File

@ -82,6 +82,6 @@
</div>
</div>
</div>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 1
- 1
themes/logs/layout.html.php View File

@ -97,6 +97,6 @@
</footer>
</div>
</div>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 1
- 1
themes/twentyfifteen/layout.html.php View File

@ -135,6 +135,6 @@
<script type="text/javascript" src="<?php echo site_url();?>themes/twentyfifteen/js/jquery-migrate.js"></script>
<script type="text/javascript" src="<?php echo site_url();?>themes/twentyfifteen/js/functions.js"></script>
<script type="text/javascript" src="<?php echo site_url();?>themes/twentyfifteen/js/skip-link-focus-fix.js"></script>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

+ 1
- 1
themes/twentysixteen/layout.html.php View File

@ -159,6 +159,6 @@
/* ]]> */
</script>
<script type="text/javascript" src="<?php echo site_url();?>themes/twentysixteen/js/functions.js"></script>
<?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?>
<?php if (! empty(config("analytics"))): ?><?php echo analytics() ?><?php endif; ?>
</body>
</html>

Loading…
Cancel
Save