Hello, can you help me please by triggerin that 3 options with marketing, analytics and functions to be auto checked when somebody press accept for cookie?
I did a code with chatgpt but i dont know if it is correct and I dont know where should i put it
document.addEventListener('DOMContentLoaded', function () {
const observer = new MutationObserver(function (mutations, me) {
const bannerDialog = document.querySelector('.shopify-pc__banner__dialog');
if (bannerDialog) {
const cookiePreferences = bannerDialog.querySelectorAll('input[type="checkbox"]');
cookiePreferences.forEach(function (checkbox) {
if (!checkbox.checked) {
checkbox.click();
}
});
const acceptButton = bannerDialog.querySelector('button.shopify-pc__banner__btn-accept');
if (acceptButton) {
acceptButton.click();
}
me.disconnect();
}
});
observer.observe(document, {
childList: true,
subtree: true
});
});