Simple "Cookie Warning" Notification βœ”


(Serdar) #24

This plugin looks good:


(Serdar) #25

@Paritosh thank you so much for this awesome guide. :slight_smile:

Is there any way to show the cookie warning for EU visitors only? Because I never prefer using plugin.

Thanks again!


#26

To display notifications just in EU, you can use this method -

Step 1. By default, keep like this.

.cookies-warning {
    display: none;
}

Step 2. But, make an external CSS file europe.css to override the behavior for serving in target countries.

.cookies-warning {
    display: block !important;
}

Step 3. Create an edge rule to bypass cache for the path *example.com/europe.css.

Step 4. Create a whitelist rule for europe.css to serve in only selected countries.

# Display Cookies Notification for the selected countries
# See here: https://support.cloudflare.com/hc/en-us/articles/205072537-What-are-the-two-letter-country-codes-for-the-Access-Rules-
<FilesMatch "europe.css">
    RewriteEngine on
    RewriteCond %{HTTP:CF-IPCountry} !^(GB|DE)$
    RewriteRule ^(.*)$ – [R=404,L]
</FilesMatch>

Step 5. Add in the footer of your site.

<link rel="stylesheet" href="https://example.com/europe.css">

(Manashjyoti Athparia) #27

but this will only work with CF enabled i think


(Serdar) #28

This creates 404 error for non-european countries. It is a penalty for Google SEO?


#29

Nope, 404 doesn’t harm.


#30

Yes, true. If someone doesn’t want to use CF at primary domain, the other easy way is using subdomain with CF enabled at different server block.