Tobias
August 28, 2024, 6:01pm
1
Hi there - I am wondering if there is an updateHandler for the New Component CC. In the old «free» FsCC there was the possibility to do this with:
window.FsCC.consentController.on('updateconsents', (consents) => {});
Is there any similar handler for the new one?
I need such a handler to destroy the Google Map container in the Dom if the Cookie Consent Categories are limited by the user.
I tried to catch things with an onsubmit or onclick handler. But This disturbs the FS Component CC script in some way.
Hey @Tobias ! The API has now changed, from the old window.fsCC
to window.fsComponents.push([COMPONENT_NAME, callback])
In this case the callback below should be what you are looking for.
<script>
// you can attach to Finsweet components window object
window.fsComponents = window.fsComponents || [];
window.fsComponents.push([
'consent',
(instance) => {
console.log('Consent instance:', instance);
instance?.consentController?.on('updateconsents', (data) => {
console.log('consents and consent modes updated: ', data);
});
},
]);
</script>
Let me know if you face any other issues or need any help!
1 Like
Tobias
August 30, 2024, 7:20pm
3
Hi @Support-Luis - Big thanks! You hit it again
That is the missing piece of code. I just check, if some of the consents is set to false and then trigger a page reload if necessary. This way the FS code stays in lead. It is a bit lazy but works like a charme. Best Tobias
1 Like
Tobias
March 2, 2025, 10:15am
4
Hi @Support-Luis
I have a follow up question to this: With the solution above I can get consent data with updating the consents. How can I get the current consents data while DOM is loaded? I could not figure out, where the data is stored in the instance object. Can you help another time? BIG THANKS in advance.
Tobias
Hey @Tobias ! You can get the stored consents directly from the instance like I do below.
const stored = instance.getStore();
console.log(stored);
In context, using a button to trigger this function call
<script>
window.fsComponents = window.fsComponents || [];
window.fsComponents.push([
'consent',
(instance) => {
instance?.consentController?.on('updateconsents', (data) => {
console.log('consents and consent modes updated: ', data);
});
const btn = document.getElementById('log-consent');
btn.addEventListener('click', (e) => {
const stored = instance.getStore();
console.log(stored);
});
},
]);
</script>
The above will log the object shown below.
I hope this helps!
1 Like
Tobias
March 7, 2025, 7:50pm
6
@Support-Luis – That is marvelous! Thank you once again for your help. It is very very appreciated.
Kind Regards
Tobias
1 Like