This demo shows some Shared Storage API use cases.
The following use-cases have been added:
- Creative selection by frequency
- A/B testing
- Creative rotation
- Known customer
Visit https://shared-storage-demo.web.app to see the demo.
The ad rendered in a fenced frame must be served from an HTTPS origin. However the Firebase emulator does not support HTTPS localhost. Therefore, we will use nginx
to setp up a reverse proxy.
We need to setup nginx to respond to port 4437 that proxies content from port 3007.
- Install
mkcert
by following the instructions for your operating system. - Run
mkcert -install
. - Create a folder to store the certificates in. In this example, we will use
mkdir ~/certs
. - Navigate to the certificate folder:
cd ~/certs
. - Run
mkcert localhost
.
For an in-depth explanation of this section, see the "How to use HTTPS for local development" article.
Setup reverse proxy with nginx
- Install
nginx
(Mac, Linux, Windows). - Find the
nginx
configuration file location based on your operating system (If you usedhomebrew
on Mac, it is under/Users/[USER-NAME]/homebrew/etc/nginx/nginx.conf
). - Add the 4437
server
block into thehttp
block in the config. Replace[USER-NAME]
with the path that your certificate is stored in:
http {
# HTTPS server
server {
listen 4437 ssl;
ssl_certificate /Users/[USER-NAME]/certs/localhost.pem;
ssl_certificate_key /Users/[USER-NAME]/certs/localhost-key.pem;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:3007/;
proxy_read_timeout 90;
}
}
}
- Stop the
nginx
server withnginx -s stop
- Restart the
nginx
server withnginx
The above nginx
configuration proxies https://localhost:4437
to http://localhost:3007
(Content producer server).
- Setup Firebase tools
git clone https://github.com/googlechromelabs/shared-storage-demo
cd shared-storage-demo
npm install
npm run dev
To run this demo, enable the experiment flag chrome://flags/#privacy-sandbox-enrollment-overrides.
Then, open Google Chrome from the command line with the additional flags below to disable the need for attestations when running locally.
--enable-privacy-sandbox-ads-apis --disable-features=EnforcePrivacySandboxAttestations
And visit http://localhost:3000
for the main page
npm run deploy