-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathmatomo.phtml
101 lines (98 loc) · 3.47 KB
/
matomo.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Copyright 2016-2018 Henrik Hedelund
* Copyright 2020 Falco Nogatz
*
* This file is part of Chessio_Matomo.
*
* Chessio_Matomo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chessio_Matomo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Chessio_Matomo. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<?php /** @var \Chessio\Matomo\Block\Matomo $block */
if ($block->isContainerEnabled()) {
return;
}
?>
<script type="text/x-magento-init">
<?= $block->jsonEncode([
'*' => [
'Chessio_Matomo/js/tracker' => $block->getJsOptions()
]
]); ?>
</script>
<?php
// The following script can be omitted in which case the
// `Chessio_Matomo/js/tracker' component will inject the tracker script instead.
// However that might cause the tracker script to miss the `DOMContentLoaded'
// event which breaks the link tracking feature.
?>
<!-- Matomo Analytics -->
<script type="text/javascript">
(function (w, d) {
w._paq = w._paq || [];
w._paq.push(['setTrackerUrl', '<?= $block->escapeJsQuote($block->getTrackerUrl()); ?>']);
w._paq.push(['setSiteId', <?= (int) $block->getSiteId(); ?>]);
var g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = '<?= $block->escapeJsQuote($block->getScriptUrl()); ?>';
s.parentNode.insertBefore(g, s);
})(window, document);
</script>
<!-- End Matomo Analytics -->
<?php
// The following script is a workaround that prevents the checkout loader
// overlay from spinning indefinitely in cases where a browser plugin such as
// AdBlock stops the tracker JS component from loading. The loader indicator
// relies on require's module registry to decide when to hide itself so here we
// export a mocked version of the component if we get an `errback' from require.
// @see vendor/magento/module-checkout/view/frontend/web/js/checkout-loader.js
// @see lib/web/mage/requirejs/resolver.js
?>
<script type="text/javascript">
(function (require, undefined) {
'use strict';
var moduleName = 'Chessio_Matomo/js/tracker';
(require !== undefined) && require([moduleName], undefined, function (e) {
if (e.requireType === 'scripterror'
&& (e.requireModules && e.requireModules[0]) === moduleName
) {
require.undef(moduleName);
define(moduleName, function () {
var noop = function () { /* NoOp */ };
var error = function () {
throw new Error('Failed to load Matomo module');
};
var mock = {
createTracker: error,
getMatomo: error,
getTracker: error,
push: noop
};
mock[moduleName] = noop;
return mock;
});
}
});
})(require);
</script>
<noscript>
<p>
<img src="<?= $block->getTrackingPixelUrl(); ?>"
style="border: 0;"
alt="" />
</p>
</noscript>