Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Shopify Community Downtime: The Shopify Community will be down December 5th for 15 minutes between 3pm and 4pm EST. Thank you for your understanding.

Cookie Auto Confirm all 3 option preferences

Cookie Auto Confirm all 3 option preferences

Dexen14
Visitor
2 0 0

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
    });
});

 

Reply 1 (1)

Dexen14
Visitor
2 0 0

hey