All things Shopify and commerce
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
@Fraenck Hi thanks for posting here.
sorry about that we do not face any cookie banner in your store.
Hey Niels,
Im also facing the same Issue at the moment. Did you find a solution?
Cheers!
Fred
Same
Where can this code - Shopify.customerPrivacy?.shouldShowBanner() - be found?
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 🙂
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:
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:
So the function hasn't just been renamed as the documentation suggests.
Elsewhere in the documentation there is a direct contradiction:
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)?
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025