Skip to content

Commit

Permalink
Block GA until consent given, fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
sprankhub committed Sep 3, 2020
1 parent 1427b10 commit b01fafc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var config = {
config: {
mixins: {
'Magento_GoogleAnalytics/js/google-analytics': {
'CustomGento_Cookiebot/js/google-analytics-mixin': true
}
}
}
};
19 changes: 19 additions & 0 deletions view/frontend/web/js/google-analytics-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
define(['mage/utils/wrapper'], function (wrapper) {
'use strict';

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) {
parentMethod(config);
}
})
}
});

0 comments on commit b01fafc

Please sign in to comment.