Skip to content

Commit

Permalink
Merge pull request #13 from edvardsSW/master
Browse files Browse the repository at this point in the history
Prevent Google Analytics from getting triggered twice
  • Loading branch information
sprankhub authored Feb 17, 2021
2 parents 65c36c7 + f7338d6 commit 30af39d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions view/frontend/web/js/google-analytics-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ define(['mage/utils/wrapper'], function (wrapper) {

return function (gaFunction) {
return wrapper.wrap(gaFunction, function (parentMethod, config) {
window.addEventListener('CookiebotOnAccept', function () {
if (Cookiebot.consent.statistics) {
parentMethod(config);
}
});
if (typeof Cookiebot === 'undefined') {
return;
}
if (Cookiebot.consent.statistics) {
if (!Cookiebot.hasResponse) {
window.addEventListener('CookiebotOnAccept', function () {
if (Cookiebot.consent.statistics) {
parentMethod(config);
}
});
} else if (Cookiebot.consent.statistics) {
parentMethod(config);
}
})
Expand Down

0 comments on commit 30af39d

Please sign in to comment.