-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Matomo Tag Manager Support #51
Open
amenk
wants to merge
6
commits into
fnogatz:main
Choose a base branch
from
amenk:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d8bc08
#32 Support Tag Manager - WIP
amenk 43f716a
#32 Matomo Tag Manager - First Working Version
amenk d626318
#32 Push Events with the same name as the Matomo native events + doc
amenk d17c16c
#32 Matomo Tag Manager - Include in Head
amenk 2ce924f
Merge branch 'main' of github.com:fnogatz/magento2-matomo into main
fnogatz b01fb77
Merge branch 'main' of github.com:fnogatz/magento2-matomo into main
fnogatz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,44 @@ | ||
# Using Matomo Tag Manager with the Matomo Magento 2 Module | ||
|
||
This describes how you can set up the tag manager to track events through Matomo Ecommerce tracking. | ||
Essentially, Ecommerce events generated by the Magento 2 module are forwarded to the Matomo events. | ||
|
||
First make sure to set the configuration *Enable Matomo Tag Manager Container* to yes and set the *Container Script Path*. | ||
|
||
## Configuring triggers | ||
|
||
In the Matomo Tag manager container, configure all the necessary triggers. | ||
|
||
Repeat the steps below for the four events | ||
|
||
* `setEcommerceView` | ||
* `addEcommerceItem` | ||
* `trackEcommerceCartUpdate` | ||
* `trackEcommerceOrder` | ||
|
||
### Steps to configure each trigger event | ||
|
||
1. Go to *Trigger* | ||
2. Click create new trigger | ||
3. Click custom event | ||
4. Name and Event name should be the same | ||
|
||
### Steps to configure the ecommerce tag | ||
|
||
1. Go to *Tags* | ||
2. Click *Create New Tag* | ||
3. Choose *Custom HTML* | ||
4. Name "Universal Ecommerce Tag for Matomo" (or choose your own) | ||
5. HTML | ||
``` | ||
<script> | ||
window._paq = window._paq || []; | ||
var parameters = {{parameters}}; | ||
var data = [{{customEventMatch}}].concat(parameters); | ||
console.log(data); | ||
window._paq.push(data); | ||
</script> | ||
``` | ||
|
||
6. *Configure when the tag should do this*, choose all the events from above, one by one | ||
7. Save tag |
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
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
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,86 @@ | ||
<?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 Tag Manager --> | ||
<script type="text/javascript"> | ||
var _mtm = window._mtm = window._mtm || []; | ||
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); | ||
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; | ||
g.type = 'text/javascript'; | ||
g.async = true; | ||
g.src = '<?= $block->escapeJsQuote($block->getContainerUrl()); ?>'; | ||
s.parentNode.insertBefore(g, s); | ||
</script> | ||
<!-- End Matomo Tag Manager --> | ||
<?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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original PR (that targeted the fork), @amenk wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think? should we create an additional block (actually 2 additional blocks) or leave it like that?