|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * |
4 | 3 | * Based on Piwik Extension for Magento created by Adrian Speyer
|
5 | 4 | *
|
6 | 5 | * @category Matomo
|
7 | 6 | * @package Matomo_Analytics
|
8 | 7 | * @copyright Copyright (c) 2018 Thiago Contardi.
|
9 | 8 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
10 | 9 | *
|
| 10 | + * @see https://matomo.org/faq/reports/advanced-manually-tracking-ecommerce-actions-in-matomo/ |
| 11 | + * @see https://matomo.org/blog/2017/04/different-ways-embedding-piwik-tracking-code-faster-website-performance/ |
11 | 12 | */
|
12 | 13 | /** @var Matomo_Analytics_Block_Script $this */
|
13 | 14 | ?>
|
14 | 15 | <?php if (! $this->helper('core/cookie')->isUserNotAllowSaveCookie() && $this->getSiteId()): ?>
|
15 |
| - <!-- Matomo --> |
16 |
| - <script> |
| 16 | + <script nonce="<?= $this->getNonce() ?>"> |
17 | 17 | var _paq = window._paq = window._paq || [];
|
18 | 18 | (function () {
|
19 |
| - var u = "<?php echo $this->getInstallPath() ?>"; |
20 |
| - _paq.push(['setSiteId', <?php echo $this->getSiteId() ?>]); |
| 19 | + var u = "<?= $this->getInstallPath() ?>"; |
| 20 | + _paq.push(['setSiteId', <?= $this->getSiteId() ?>]); |
21 | 21 | _paq.push(['setTrackerUrl', u + 'matomo.php']);
|
22 | 22 |
|
23 |
| - <?php echo $this->getEcommerceCartUpdate() ?> |
24 |
| - <?php echo $this->getOrdersTrackingCode() ?> |
25 |
| - <?php echo $this->getProductPageview() ?> |
26 |
| - <?php echo $this->getCategoryPageview() ?> |
| 23 | + <?= $this->getEcommerceCartUpdate() ?> |
| 24 | + <?= $this->getOrdersTrackingCode() ?> |
| 25 | + <?= $this->getProductPageview() ?> |
| 26 | + <?= $this->getCategoryPageview() ?> |
27 | 27 |
|
28 | 28 | <?php if ($this->getSearchResultCount() > 0): ?>
|
29 |
| - _paq.push(['setCustomUrl', '' + document.URL + '&search_count=<?php echo $this->getSearchResultCount() ?>']); |
| 29 | + _paq.push(['setCustomUrl', '' + document.URL + '&search_count=<?= $this->getSearchResultCount() ?>']); |
30 | 30 | <?php endif ?>
|
31 | 31 |
|
32 | 32 | <?php if ($this->is404()): ?>
|
|
35 | 35 |
|
36 | 36 | _paq.push(['trackPageView']);
|
37 | 37 | _paq.push(['enableLinkTracking']);
|
38 |
| - var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; |
39 |
| - g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); |
| 38 | + function embedTrackingCode() { |
| 39 | + var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript"; |
| 40 | + g.defer=true; g.async=true; g.src=u+"matomo.js"; s.parentNode.insertBefore(g,s); |
| 41 | + } |
| 42 | + |
| 43 | + if (window.addEventListener) { |
| 44 | + window.addEventListener("load", embedTrackingCode, false); |
| 45 | + } else if (window.attachEvent) { |
| 46 | + window.attachEvent("onload", embedTrackingCode); |
| 47 | + } else { |
| 48 | + embedTrackingCode(); |
| 49 | + } |
40 | 50 | })();
|
41 | 51 | </script>
|
42 |
| - <noscript><p><img src="<?php echo $this->getInstallPath() ?>matomo.php?idsite=<?php echo $this->getSiteId() ?>&rec=1" style="border:0" alt="" /></p></noscript> |
43 |
| - <!-- End Matomo Code --> |
| 52 | + <noscript><p><img src="<?= $this->getInstallPath() ?>matomo.php?idsite=<?= $this->getSiteId() ?>&rec=1" style="border:0" alt="" /></p></noscript> |
44 | 53 | <?php endif ?>
|
0 commit comments