Install the snippet
Your snippet is one line. Find it in your dashboard under your site's Install & data, where it has your site's own key:
<script src="https://cdn.peekbird.com/s/YOUR_SITE_KEY.js"></script>Paste it as high as possible in the page's <head>, before other scripts, on every page. It loads synchronously on purpose: that's what stops visitors from seeing the original page flash before a variation applies. It holds only what your site uses (about 4–15 KB compressed) and is served from a CDN.
Testing only in your own server's code, with an SDK? Then nothing has to change the page before it shows: load it with async and the page never waits for it (see Server-side SDKs). Split-URL tests, and tests from the visual editor or with code in the page, need it as above.
Custom website
- Open the template or layout that renders the <head> of every page.
- Paste the snippet directly after the opening <head> tag, before any other scripts.
- Deploy, then open any page. Install & data in your dashboard turns green within a few seconds.
Shopify
The simplest way is the Peekbird app: it adds the snippet and tracks orders, with no code. See Peekbird for Shopify. To add the snippet by hand instead:
- In Shopify admin, go to Online Store → Themes, then … → Edit code on your live theme.
- Open
layout/theme.liquid. - Paste the snippet right after
<head>and save.
Shopify runs no store scripts on its checkout, so orders need one more step: a checkout pixel, in Purchases.
WordPress
- Install a header-scripts plugin such as WPCode, or edit your theme's
header.php. - Add the snippet to the header section, as early as possible.
- If you use a caching plugin, clear its cache so pages include the snippet.
React, Next.js and other single-page apps
Add the snippet as a plain script tag in the document head, not a deferred or lazy-loaded one:
// Next.js (app/layout.tsx)
<html>
<head>
<script src="https://cdn.peekbird.com/s/YOUR_SITE_KEY.js"></script>
</head>
<body>{children}</body>
</html>Experiments apply on full page loads, and page views are sent on full page loads only. Client-side route changes don't re-check which tests apply yet; read what that means for your tests before you start one.
Google Tag Manager
Tag Manager loads after the page starts rendering, so visitors can see the original page flash before a variation applies: fine for tracking and recordings, not recommended for experiments.
- Create a Custom HTML tag containing the snippet.
- Trigger it on Initialization – All Pages and set its tag firing priority high.
Several subdomains
By default each subdomain counts on its own: a visitor going from shop.com to app.shop.com starts a new visit there. To follow them across, as one visitor in one visit (the same variation, one session in analytics, one recording from the home page to sign-up), all of these need to hold:
- This site's snippet on each subdomain you want to track, on every page you want in the visit. Subdomains without it are left alone. A page without it isn't recorded or counted, so the recording skips it. A Peekbird site of its own for each subdomain keeps them apart, whatever you set.
- Each of those subdomains in the site's Domains, in Site settings.
- Cookie domain set to the part they share, with a dot in front:
.shop.com. Not one subdomain, likeapp.shop.com: that leaves shop.com out. Site settings says so, and offers the shared part. - All on HTTPS. Cookies made on an HTTPS page aren't read on an HTTP one.
A visitor's cookie choice then applies on all of them too.
Mind what the other subdomain shows. On an app, record the sign-up and sign-in pages, not the pages behind them, which show your customers' data: leave the snippet off those pages, or leave those parts out of recordings with peekbird-block (see Privacy controls). A single-page app keeps recording after sign-in until the page reloads, so load the signed-in part as a fresh page.
It's your choice, per site: leave Cookie domain empty to keep them apart.
Checking and previewing
Add these to any page address on your site:
?peekbird_debug=1logs every decision in the browser console.?peekbird_qa=1runs experiments that are still in QA.?peekbird_force=experiment:variationforces a variation.?peekbird_record=1records your visit, whatever the sample rate.?peekbird_country=DEacts as if you were in that country, to check location audiences.
Set any of them to 0 to turn it off. Visits with any of them but debug are QA visits: they never count in results, analytics or your plan's usage. QA and preview has the details, and the install check.
