Iubenda logo
Start generating

Documentation

Table of Contents

How to prevent Ad blockers from reducing your cookie consent collection

If you rely on personalized ads to monetize your website content, ad blockers can be an issue: they can block your cookie banner and thus disrupt the collection of cookie consents.

In this guide, we will show you how to set up a CDN reverse proxy with URL substitution, avoiding the consent rate on your website being affected, and how to cache cdn.iubenda.com on a custom domain ensuring full continuity in case of iubenda CDN problems. Let’s see how to do it! 👉

Important disclaimer

This document and the included configuration are intended for expert personnel only or any person in charge of administrating the infrastructure where the proxy is being installed.

They are not intended for someone not in charge of the networking or anyone attempting to find temporary solutions or workarounds, hoping it will “just work.”

Too many possible issues could arise in the interactions with all combinations of systems and software versions, settings, and other running components to build a comprehensive guide to cover them all.

Setting up a CDN Reverse Proxy

Instructions

This document provides instructions and configurations to set up an NGINX reverse proxy that:

  • Proxies static CDN contents towards cdn.iubenda.com from a custom URL
  • Does URL substitution in the served documents.
  • Does NOT forward the client IP with the usual headers X-Forwarded-For and X-Real-Ip
  • Serves cached assets in case the iubenda’s CDN runs into issues of any type.
Notes
  • Requires ngx_http_sub and ngx_http_proxy modules to be enabled. They are usually installed by default.
  • Use your domain of choice instead of cdn.customer.com in both server_name and sub_filter directives.
  • Add proper SSL configuration as required.
  • Make sure /tmp/cache exists and has the correct ownership: (i.e., chown nginx:nginx /tmp/cache), or change it to a location and file of choice.

Configuration Example

Important

Please note that the Privacy Controls and Cookie Solution native country detection (parameter countryDetection:true) won’t work with this configuration and the location of the end-user will always be considered as the one of the server where the reverse-proxy is installed is located.

If you are using different settings based on the location of your users, you will have to rely on your own geolocation system to load the correct configuration.

The configurations below are examples of a typical virtual host on Port 80. Configuration must be completed with SSL parameters, depending on the chosen settings.

# iubenda CDN local proxy configuration
# Version 1.1 - Included compression support

proxy_cache_path /tmp/cache levels=1:2 keys_zone=tmpcache:100m max_size=200m 
inactive=180m;

server {
  listen                      80;
  server_name                 cdn.customer.com;

  access_log                   /var/log/nginx/cdn-customer-access.log;
  error_log                    /var/log/nginx/cdn-customer-error.log;

  location / {
    # Link rewriting
    sub_filter 'cdn.iubenda.com' 'cdn.customer.com';
    sub_filter_types *;
    sub_filter_once off;
    
    # Enables compression
    gzip on;
    gzip_static off;

    # Enables cache for this location
    proxy_cache tmpcache;

    # Delivers cached stale files instead of relaying the error to the client.
    proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
    proxy_cache_background_update on;
    
    # Proxy cache valid for 30 min
    proxy_cache_valid 200 301 302 304 30m;
    proxy_pass https://cdn.iubenda.com/;
    proxy_set_header Accept-Encoding "";
  }
}

SDK Configuration Examples

If you’re using our SDK, in order to use your reverse proxy setup, you can follow these configuration examples:

For Android:

IubendaCMPConfig config = IubendaCMPConfig.builder() 
 .siteId("XXXXX") //use your siteId
 .cookiePolicyId("YYYYY") //use your cookiePolicyId
 .proxyUrl("https://iubenda.example-client-domain.com/cs/mobile.htm") //use your own reverse-proxy URL
 .build();

For iOS:

let config = IubendaCMPConfiguration()
config.siteId = "XXXXX" //use your siteId
config.cookiePolicyId = "YYYYY" //use your cookiePolicyId
config.proxyUrl = “https://iubenda.example-client-domain.com/cs/mobile.htm" //use your own reverse-proxy URL
IubendaCMP.initialize(with: config)

Please note that this configuration is available from version 2.6.0 of our SDK (for both Android and iOS).

Please reach out to us via email at business@iubenda.com if you need any further assistance or clarification. We’re happy to help.