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.
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" }| Field | Meaning |
|---|---|
sid | The session id. The first 8 characters are the Reference on the block screen. |
transport | ws (live connection), http (plain HTTPS fallback) or none (not connected; see Troubleshooting). |
fp | true once the device details were sent. |
mode | The 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:
| Directive | Add | Why |
|---|---|---|
script-src | https://s.geoiphub.com | Loads traffic.js. |
connect-src | https://s.geoiphub.com wss://s.geoiphub.com | The live connection and the HTTPS fallback. |
worker-src | blob: | One consistency check runs in a short-lived worker. Without it, only that check is skipped. |
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-srcdoes 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-srcchange. Under a strictstyle-srcwithout'unsafe-inline', only its short fade-in is dropped and the browser logs one report. - If you set
script-srcwith a nonce or'strict-dynamic', give the<script>tag that loadstraffic.jsyour nonce.
Network requests the script makes
All to our edge network, except the WebRTC address check, and never to your server.
| Request | Purpose |
|---|---|
wss://s.geoiphub.com/v1/c | The live connection: device details, behaviour batches, round-trip pings and the decision. |
https://s.geoiphub.com/v1/e | Fallback when a WebSocket can't connect, and the last behaviour batch when the page closes. |
https://s.geoiphub.com/v1/p | A small request that completes the connection details the browser sends with ordinary requests. |
| A public STUN server | WebRTC 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.