Help

Script reference

The init options, the onDecision callback, ready(), and the Content Security Policy directives the script needs.

The script is served from https://s.geoiphub.com/v1/traffic.js and adds one global, geoiphub.

geoiphub.init(options)

Starts the script. Call it once per page load. It returns true when the script started, and false when the options are invalid (for example a missing websiteKey). A second call does nothing and returns true.

geoiphub.init({
  websiteKey: "sk_your_website_key",
  mode: "full",
  consent: () => true,
  onDecision: (decision) => {},
});

Prop

Type

The script also accepts wsUrl, eventUrl, probeUrl, probe4Url, probe6Url and stunUrl. Leave them unset. They exist for our own testing.

The onDecision callback

You don't need it: the script shows the block screen on its own. Use it when your page should react as well, for example to stop a form from sending or to record the event in your analytics.

Stop a form on block
let blocked = false;

geoiphub.init({
  websiteKey: "sk_your_website_key",
  onDecision: (decision) => {
    blocked = decision === "block";
  },
});

form.addEventListener("submit", (e) => {
  if (blocked) e.preventDefault();
});
  • It is called at most once per page load, with "allow" or "block".
  • If no decision arrives within 12 seconds, or the connection to our service fails, it is called with "allow".
  • An error thrown inside your callback is caught and ignored.
  • On "block", the block screen is shown whatever your callback does.

geoiphub.ready()

Returns a promise that resolves once the session is open and the device details were sent, or after a few seconds at most. Handy for checking an install in the browser console.

await geoiphub.ready();
// { sid: "3f9c2a1b-…", transport: "ws", fp: true, mode: "full" }
FieldMeaning
sidThe session id. The first 8 characters are the Reference on the block screen.
transportws (live connection), http (plain HTTPS fallback) or none (not connected; see Troubleshooting).
fptrue once the device details were sent.
modeThe mode the script runs in.

geoiphub.version is the script version. geoiphub.strictOmits lists the fields strict mode leaves out.

Content Security Policy

If your site sends a Content-Security-Policy header, add these sources:

DirectiveAddWhy
script-srchttps://s.geoiphub.comLoads traffic.js.
connect-srchttps://s.geoiphub.com wss://s.geoiphub.comThe live connection and the HTTPS fallback.
worker-srcblob:One consistency check runs in a short-lived worker. Without it, only that check is skipped.
Example header
Content-Security-Policy: script-src 'self' https://s.geoiphub.com; connect-src 'self' https://s.geoiphub.com wss://s.geoiphub.com; worker-src 'self' blob:

Good to know:

  • The script also makes a WebRTC address check against a public STUN server (UDP port 3478 or 19302). CSP connect-src does not cover it, so there is nothing to add for it. If a network or a browser setting blocks WebRTC, that one check is skipped and the visit is still scored.
  • The block screen needs no style-src change. Under a strict style-src without 'unsafe-inline', only its short fade-in is dropped and the browser logs one report.
  • If you set script-src with a nonce or 'strict-dynamic', give the <script> tag that loads traffic.js your nonce.

Network requests the script makes

All to our edge network, except the WebRTC address check, and never to your server.

RequestPurpose
wss://s.geoiphub.com/v1/cThe live connection: device details, behaviour batches, round-trip pings and the decision.
https://s.geoiphub.com/v1/eFallback when a WebSocket can't connect, and the last behaviour batch when the page closes.
https://s.geoiphub.com/v1/pA small request that completes the connection details the browser sends with ordinary requests.
A public STUN serverWebRTC address check. Data only, no camera or microphone. The browser asks the server for its own public address and reports it to us.

None of them send cookies of your site, the query string of the page or anything a visitor types. See Privacy and data.

On this page