View as Markdown

Unmasked IP Sharing

Not supported in the EU. Ezoic never shares a visitor's IP address with Google for visitors located in the European Union, the wider European Economic Area, the United Kingdom, or Switzerland, or for visitors whose location can't be determined. You can call ezstandalone.setUnmaskedIP() on every page; for these visitors Ezoic ignores the value and nothing is sent to Google.

Overview

Some browsers hide or mask visitors' IP addresses from known ad-tech providers such as Google. Ad requests with a masked IP typically see fewer bids and lower revenue.

Your own web server still sees each visitor's real ("unmasked") IP address. With ezstandalone.setUnmaskedIP(), you can pass that address to Ezoic, and Ezoic forwards it to Google Ad Manager with your ad requests.

This feature is part of a Google Ad Manager beta and is only available to eligible Ezoic accounts. On sites that aren't eligible, calling the function has no effect.

If Ezoic serves your pages directly (for example, through a nameserver or Cloudflare integration), Ezoic already sees your visitors' IP addresses and forwards them automatically. You don't need to add any code. This function is for sites integrated with EzoicAds JavaScript.

Usage

Call ezstandalone.setUnmaskedIP() with the visitor's IP address before you call ezstandalone.showAds():

<script>
    window.ezstandalone = window.ezstandalone || {};
    ezstandalone.cmd = ezstandalone.cmd || [];
    ezstandalone.cmd.push(function () {
        ezstandalone.setUnmaskedIP("203.0.113.42"); // the visitor's IP, written into the page by your server
        ezstandalone.showAds(101, 102, 103);
    });
</script>

The function accepts an IPv4 or IPv6 address as a string. Passing null or an empty string clears a previously set value. Invalid values are ignored and logged as a warning in the browser console.

If you call it after showAds(), the IP applies only to ad requests made after that point, such as showAds() calls for new placements or ads loaded on later pageviews in a single-page application.

Getting the visitor's IP onto the page

The value must be the visitor's IP address as seen by your server. It must not be your server's own address, or the address of a proxy, load balancer, or CDN that sits in front of it. Most sites write the IP into the page when it is rendered.

For example, in PHP:

<script>
    window.ezstandalone = window.ezstandalone || {};
    ezstandalone.cmd = ezstandalone.cmd || [];
    ezstandalone.cmd.push(function () {
        ezstandalone.setUnmaskedIP(<?php echo json_encode($_SERVER['REMOTE_ADDR']); ?>);
        ezstandalone.showAds();
    });
</script>

If your site sits behind a CDN, proxy, or load balancer, REMOTE_ADDR (or its equivalent in your server language) will be that service's IP address rather than the visitor's. Read the header your provider uses for the original client IP instead, for example CF-Connecting-IP on Cloudflare or the first address in X-Forwarded-For from a load balancer you trust.

Page caching: if your pages are cached and served to multiple visitors, a server-rendered IP will be wrong for everyone after the first visitor. Exclude the value from your cache, or load it from an uncached first-party endpoint before calling showAds().

If your pages are cached, you can fetch the IP from a first-party endpoint on your own domain that returns the requesting visitor's IP:

ezstandalone.cmd.push(function () {
    fetch("/visitor-ip", {cache: "no-store"})
        .then(function (response) { return response.text(); })
        .then(function (ip) { ezstandalone.setUnmaskedIP(ip.trim()); })
        .catch(function () {})
        .finally(function () { ezstandalone.showAds(); });
});

When the IP is not sent

Ezoic only forwards the IP to Google when all of the following are true. Otherwise the value is ignored.

  • The visitor is not located in the EU, the EEA, the UK, or Switzerland, and their location can be determined. Ezoic checks both the location of the visitor's connection and the location of the IP address you pass.
  • Your site is eligible for the Google Ad Manager beta.
  • Personalized ads are allowed. The IP is not sent if you have called ezstandalone.setDisablePersonalizedAds(true), if non-personalized ads are forced for your site, or if the visitor has opted out of the sale or sharing of their personal information.
  • The value is a valid, public IP address. Private and reserved addresses such as 10.0.0.1 or 127.0.0.1 are ignored.

Google also never passes the IP address on to buyers for non-personalized or restricted data processing ad requests.