-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
Google Analytics #429
Comments
If GA is loaded via GTM then this should help you out: #110 (comment). What do you exactly mean with "one script file"? Is it a dedicated file for GA and GTM's setup or is it the plugin's config. file (cookieconsent-init.js)? |
it's a dedicate file for it, Only that the second requires a preloaded google script, Another question, when i go to change my choose to decline anl permission, did i need reload page? |
There are 2 ways to load GA4, either via gtag.js or via GTM. Since you're already using GTM, I would suggest to simply configure GA4 there. If you really want to load both gtag and gtm's scripts, then this is how I would do it: // Replace with your codes
const GA4_CODE = 'G-XXXXXXXXXX';
const GTM_CODE = 'GTM-XXXXXXX';
// Load ga4
cc.loadScript(`https://www.googletagmanager.com/gtag/js?id=${GA4_CODE}`, () => {}, [
{name: 'async', value: ''}
]);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', GA4_CODE);
// Load gtm
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer',GTM_CODE);
cc.run({
// your config
onAccept: function () {
if(cc.allowedCategory('analytics')){
cc.loadScript('./analytics-scripts.js');
}
},
onChange: function (cookie, changedCategories) {
if(changedCategories.includes('analytics')){
if(cc.allowedCategory('analytics')){
cc.loadScript('./analytics-scripts.js');
}else {
// disable gtag/ga
window['ga-disable-G-XXXXXXXXXX'] = true;
gtag('consent', 'update', {
'analytics_storage': 'denied'
});
}
}
}
});
Yes, if you want the tracking to stop immediately! You can configure the plugin to reload the page for you: // ...
toggle: {
value: 'analytics',
enabled: false,
readonly: false,
reload: 'on_disable'
}
// ... |
hello orestbida , I copied this setup, but it does not delete _GA_XXXXX, it only deletes _GA on reload. v2.8.9 making changes AFTER the initial OK, then I want to disable, call |
you can check if the plugin is effectively deleting the cookies by using the You have to execute Make sure you implement the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi,
i need to add GTM and google Analytics tag in one script file,
how i can do it, where i can find some example?
The text was updated successfully, but these errors were encountered: