How to set script with default consent and then activate? (V3) #559
Replies: 2 comments 5 replies
-
Hi @darkWolf-PR, There are 2 ways to handle scripts/cookies:
This particular case can be implemented using events/callbacks. Example using events (should do exactly what you asked): <script type="text/javascript" src="https://c.seznam.cz/js/rc.js"></script>
<script>
var retargetingConf = {rtgId: 123456};
window.addEventListener('load', () => {
if(!CookieConsent.validConsent()) {
if (window.rc && window.rc.retargetingHit) {
window.rc.retargetingHit(retargetingConf);
}
console.log('Invalid consent:', retargetingConf);
}
});
window.addEventListener('cc:onConsent', () => {
const targetingEnabled = CookieConsent.acceptedCategory('targeting') ? 1 : 0;
retargetingConf = {rtgId: 123456, consent: targetingEnabled};
if (window.rc && window.rc.retargetingHit) {
window.rc.retargetingHit(retargetingConf);
}
console.log('onConsent targetingEnabled:', targetingEnabled, retargetingConf);
});
window.addEventListener('cc:onChange', ({ detail }) => {
const { changedCategories } = detail;
if(!changedCategories.includes('targeting'))
return;
const targetingEnabled = CookieConsent.acceptedCategory('targeting') ? 1 : 0;
retargetingConf = {rtgId: 123456, consent: targetingEnabled};
if (window.rc && window.rc.retargetingHit) {
window.rc.retargetingHit(retargetingConf);
}
console.log('onChange targetingEnabled:', targetingEnabled, retargetingConf)
});
</script> Feel free to remove the |
Beta Was this translation helpful? Give feedback.
-
@orestbida I´ve been implementing GA4+AW scripts via GTAG after this one and I have a connected question - I have set it like this (found samewhere around in manual, issues like #110 and demos):
And it kind of implies me, that it works just as wrong as that my original retargeting code on top - on every page load, consent is set as denied at first and than changed. Or do I get it wrong? Cause I did not found any demo, that has it implemented with check on validConsent on load? |
Beta Was this translation helpful? Give feedback.
-
Hi, I can´t find a way how to set CookieConsent with this retargeting script - this is the base version:
It should run like this before consent is given(it sends default param consent: -1)
After consent is given(or not), there should be variable consent with 1 or 0:
I tried it like this:
It will set the consent after accepting the category, but no way I can find how to jump over the base script when consent is already set. This way, it always runs twice, first without consent and after that again, with consent 1 or 0 and that´s just wrong. So this is definitely not the way to do it, but I can´t find any other.
I have basic setup for V3 from manual ( https://cookieconsent.orestbida.com/essential/getting-started.html ), added rc.16 umd.js and cookieconsent-init.js scripts and init set like:
CookieConsent.run({ ... })
Anyone can help? I´m not much JS guy, anything I tried ended with "undefined this, undefined that", I´ve been messing with this for several hours.
Beta Was this translation helpful? Give feedback.
All reactions