Skip to content
Peekbird

Speed, CSP and single-page apps

Peekbird changes your page before visitors see it, and otherwise keeps out of its way. This page says exactly when it hides your page, how its file is cached, what your Content Security Policy needs, and what to know about single-page apps.

How tests avoid flicker

The snippet loads synchronously, first in your page's <head>, with your site's experiments built into the file: deciding who gets which variation waits on no network request. CSS is in place before the page is first drawn, and visual changes and variation code change elements as the browser adds them.

Whether the page is hidden meanwhile depends on the tests a visitor is in:

  • Tests whose variations have only CSS, or only style and hide changes from the visual editor, don't hide the page, unless they wait for a location (below).
  • Split-URL tests, and tests where a variation has JavaScript or other visual changes (text, content, pictures, links, moves, added content), hide the whole page until its HTML has loaded. Everyone in the test is hidden, the control too, so every variation loads the same way and the hiding can't tilt the results.
  • A split-URL variation keeps the page hidden while the browser goes to its page.
  • If a test has a location audience, on a visitor's first page view of the day the page stays hidden until their location is known, whatever the test changes.

Visitors outside a test's pages, audience or traffic share aren't hidden by it. Whatever happens, the page is shown once the Anti-flicker timeout (ms) in Site settings has passed: 2,000 by default, from 0 to 10,000. 0 turns hiding off.

When the original page can still show

  • The snippet loads asynchronously, through Google Tag Manager, or below other scripts: the page can show before it runs. The install check warns about each.
  • Your site waits for consent only where the law requires it (see Consent): on a visitor's first page view, and about once a day after, Peekbird looks up where they are before anything runs, for up to 2 seconds, and the page isn't hidden during that wait.
  • A visitor has to agree first: tests start when they agree, on the page they're already looking at.
  • Testers with a QA or preview link: the page can stay hidden for up to 3 seconds while the newest version of your file loads.

File size and caching

The file holds only what your site uses: from about 4.5 KB compressed to about 15 KB with experiments, visual changes, analytics and recordings all on, plus what your experiments contain. Being synchronous, it holds up the page while it downloads, as any script in the <head> does. The recorder, for visits being recorded, and automatic events load separately, once the page has loaded and the browser is idle.

The file is cached for 60 seconds by Peekbird's CDN and by your visitors' browsers, so a change reaches visitors within about a minute. For 10 minutes after that, a cache may serve its older copy once more while it fetches the new one. If Peekbird's servers can't be reached, the file lets caches keep serving their last copy for up to 24 hours.

If the snippet is blocked

  • If an ad blocker or the network stops the file, visitors see your page as it is: no variation, nothing tracked or recorded, and they're not in your results.
  • Your own calls to Peekbird wait in a plain list that nothing reads, so your page's code doesn't break. That's what this line, before each call in our code samples, is for:
window.peekbird = window.peekbird || [];
  • If only collect.peekbird.com is blocked, a visitor in a test still sees their variation, but nothing they do arrives, so they're not in your results either.
  • If a variation's code throws an error, the page is still shown, and the experiment's page lists the error.

Content Security Policy

If your site sends a Content Security Policy, add these sources to it:

DirectiveAddFor
script-srchttps://cdn.peekbird.comThe snippet, and the modules it loads from there: the recorder, automatic events, the install check and the visual editor.
connect-srchttps://collect.peekbird.com https://cdn.peekbird.comEvents, recordings and location lookups go to collect; the visual editor's saves, the install check and testers' version check go to cdn.
img-srchttps://cdn.peekbird.comPictures uploaded in the visual editor.
style-src'unsafe-inline'The snippet adds style elements, without a nonce: for variations' CSS, style and hide changes, and hiding the page while a test applies. Without it, none of those work.

A policy with only what Peekbird needs, besides your own site, ready to copy:

Content-Security-Policy: script-src 'self' https://cdn.peekbird.com; connect-src 'self' https://collect.peekbird.com https://cdn.peekbird.com; img-src 'self' https://cdn.peekbird.com; style-src 'self' 'unsafe-inline'
  • Nothing needs 'unsafe-eval', workers or blob: addresses: variation code is built into the file as ordinary functions, never run from text.
  • With nonces and 'strict-dynamic', give the snippet's tag your nonce: the modules it loads are then allowed too.
  • If an image change uses a picture from another site, or your variation code loads something, allow that as well.

Trusted Types

Trusted Types isn't supported yet. On a site that enforces it (require-trusted-types-for 'script'), the browser blocks:

  • Content and Added changes from the visual editor, which put HTML into the page.
  • The modules the snippet loads: there are no recordings, automatic events or install check, and the visual editor can't open.
  • QA and preview links, when the copy of your file the page got isn't the newest.

Experiments with CSS, JavaScript, and text, style, hide, picture, link and move changes still work, and so do goals and analytics. Your variations' own JavaScript is held to your site's Trusted Types rules like any other code.

Single-page apps

On React, Next.js, Vue and other apps that change pages without reloading, Peekbird works per full page load for now:

  • Which experiments apply is decided when a page loads, and isn't checked again when the app changes route. A visitor who reaches a tested page through your app's own links doesn't get the test there. One who leaves it that way keeps its variation's CSS and changes, which apply to any matching element on the next screen.
  • Page views are sent on full page loads only, so Analytics counts fewer page views than visitors see. Goals are matched to the address the page loaded with: a page visit goal doesn't fire for a page reached without a load.
  • A visit ends 30 minutes after its last full page load. Moving around inside the app doesn't extend it, so one long visit can count as two.

Until Peekbird checks again on route changes:

  • Run experiments on pages visitors reach with a full load: landing pages, or pages your app links to with ordinary links.
  • Write variation CSS and selectors that only match the tested page, for example under a class only that page's main element has.
  • Count steps inside the app with an event from your code (see Other events), not a page visit goal.

See what your visitors see.

Start free in a few minutes: one snippet, every feature. Move to a bigger plan when you need more tracked visits.