How to fix a persistent cookie consent banner issue?

Fraenck
Visitor
2 0 1

Hi!

 

We've recently (since yesterday) run into an issue with our cookie banner.

We're using Impact 4.8 on https://fraenck.com.

The theme-supplied cookie banner pops up on every page, even though the cookies have been either accepted or denied.

We've tried using the built in Shopify cookie banner; this one correctly disappears after setting the cookie preference (but we'd prefer to be able to use the more theme-appropriate cookie banner).

After digging into the code, it seems like

Shopify.customerPrivacy?.shouldShowBanner()

always returns true, regardless of set cookie preferences.

I've currently implemented a workaround where we also check

 

Shopify.customerPrivacy?.getTrackingConsent() == "no_interaction"

 

but I'd assume the above code (that shipped with the theme) should be sufficient?

 

Any assistance would be greatly appreciated,

 

Niels

Replies 6 (6)

ProtoMan44
Shopify Partner
146 13 23

@Fraenck Hi thanks for posting here.
sorry about that we do not face any cookie banner in your store.

- A thirsty developer passionate about supporting the community. If you'd like to, you can buy me a

Coffee

.
- Your Shopify Solution Specialist Get a Quote at Dev444- Whatsapp +92-3046185085
Crafting exceptional e-commerce experiences to elevate your online presence. Let's build your success story together!

FNDBrothers
Visitor
1 0 0

Hey Niels,

 

Im also facing the same Issue at the moment. Did you find a solution? 

 

Cheers!

 

Fred

Errie
Shopify Partner
2 0 0

Same

amgillesp
Shopify Partner
1 0 0

Where can this code - Shopify.customerPrivacy?.shouldShowBanner() - be found?

 

Waliday
Shopify Partner
1 0 0

I find the documentation not super clear on this subject but it seems that the shouldShowBanner function returns true depending on whether you are in a region eligible for user consent like the EU for example, so it is normal that this always returns you true.

What you need to do is check whether consent already exists for a user, yes if he accepted and no if he refused. in the case where all the consents are empty then there and only there you must trigger the appearance of your cookie.

 

  function areVisitorConsentsEmpty(consents) {
    for (let key in consents) {
      if (consents.hasOwnProperty(key)) {
        if (consents[key] !== '') {
          return false;
        }
      }
    }
    return true;
  }

  function initCookieBanner() {
    const currentVisitorConsent = window.Shopify.customerPrivacy.currentVisitorConsent();

    const visitorConsentsEmpty = areVisitorConsentsEmpty(currentVisitorConsent);
    const shouldShowBanner = window.Shopify.customerPrivacy.shouldShowBanner();

    if(shouldShowBanner && visitorConsentsEmpty) {
      showBanner();
    }
  }

 
I hope that that will be able to help you 🙂

Richard687
Shopify Partner
19 1 11

You're absolutely right that the documentation of the Customer Privacy API is a bit of a tangle. As far as I can see, either the documentation is incorrect and directly contradicts itself, or Shopify have introduced a bug in the API (or both)...

 

We currently use shouldShowGDPRBanner() to detect whether or not to show the banner to the customer. This works fine. It returns true only if the customer is in an eligible region and consent has not been set.

 

When we switch to shouldShowBanner(), it always returns true if the customer is in an eligible region. This is strange, because the documentation says:

 

Richard687_0-1716392393739.png

 

Therefore we should be able to just change shouldShowGDPRBanner() to shouldShowBanner() and everything should work fine. However, like @Fraenck, we're finding that shouldShowBanner() always returns true, even when shouldShowGDPRBanner() returns false:

 

 

Richard687_1-1716392497462.png

 

So the function hasn't just been renamed as the documentation suggests.

 

Elsewhere in the documentation there is a direct contradiction:

 

Richard687_2-1716392879529.png

 

First of all it says it "doesn't indicate if consent has already been given" then contradicts this by saying it returns "true if consent isn't already set".

 

I wonder if someone from Shopify could clarify the correct behaviour and whether the documentation and/or the API needs to be update. If shouldShowBanner() no longer checks if consent has already been set, what is the correct way to check via the API if it has been set (without having to write our own boilerplate)?