Skip to documentation

Snippet

Last updated: September 24, 2026.

Install the Palette snippet to recruit your own site visitors into studies and run inline microstudies.

  1. Copy your tag from Workspace settings, Recruit.
  2. Paste it before the closing body tag on every page you want to include.
  3. Load the page and confirm the Recruit keys table receives its first ping.

One snippet installation per workspace serves studies across all of its projects.

<script src="https://api.palettelabs.ai/hosting/snippet/palette.js" data-key="pk_live_..." async></script>

Test and live keys

Each workspace has a matched pair of keys, both visible in the Recruit keys table. Use the pk_live_ key on your production site: it only accepts responses from the Allowed origins you set when you mint the pair, so responses from anywhere else are blocked. Use the pk_test_ key on staging or localhost: it accepts localhost on any port, so you can verify the install locally without configuring origins first. Swap the key in the tag's data-key attribute for the environment you are on; the rest of the tag is identical.

Confirming it's live

Once the snippet loads on a page it pings Palette, and the Install column in Workspace settings, Recruit reflects what it sees for that key:

  • Installed on your-site.com means a ping arrived in the last five minutes. The snippet is live.
  • Last seen 20m ago — check your site means the most recent ping is older than five minutes. The tag may have been removed, or that page just has not been visited lately.
  • Waiting for first ping… means the key has never been seen. Confirm the tag is on a page that has loaded in a browser since you added it.
  • Seen on your-site.com — not in this key's allowed origins; responses are blocked means the snippet loaded, but the page's origin is not in the live key's Allowed origins, so responses will not be accepted. Add the origin to the key to clear it.

Segmenting invites with identify()

Once installed, the snippet can already target invites by page and by sample rate. To show an invite only to certain visitors — say, users on your Pro plan, or admins — tell Palette who the current visitor is by calling identify(). The snippet has no other way to know a visitor's plan, role, or account age: that information lives in your app, so you pass it in.

identify() is a queued command. Define the queue and push your call before the snippet tag; because the tag is async, the queue holds your call until the snippet boots and replays it. The first argument is your own id for the logged-in visitor — render it per user, never a hardcoded string — and the second is a flat object of the traits you want to segment on:

<script>
  window.Palette = window.Palette || [];
  // Pass your own id for the logged-in visitor and the traits to segment on.
  // Render it per user - don't hardcode one id.
  window.Palette.push(["identify", currentUser.id, { plan: currentUser.plan, role: currentUser.role }]);
</script>
<script src="https://api.palettelabs.ai/hosting/snippet/palette.js" data-key="pk_live_..." async></script>

Then author the match in the study's Recruit card, under Segment: add a condition like plan is pro. The snippet evaluates that rule in the visitor's browser against the traits you passed, and shows the invite only when it matches.

Traits are deliberately simple:

  • Up to 50 traits per visitor, with scalar values only — text, numbers, true/false, or null. Objects and arrays are ignored, and extra traits are dropped. Trait names may be up to 64 characters, values up to 512.
  • Everything compares as text, case-sensitively: 1.0 reads as "1", true as "true", and null as "null" — so seats is 5 matches a trait passed as the number 5.
  • A visitor is shown the invite only when every trait the rule references is present and matches — a visitor missing a referenced trait never sees the invite. Traits last for a single page load, so call identify() again after navigation or login. If an invite is not showing, confirm your call ran on that page and carried the trait name your rule uses.
  • Trait names beginning with behavior. are reserved for metrics Palette collects on its own (page views, scroll depth) — you can segment on those without passing anything.

Keep secrets out of traits. Your Segment rule ships to every visitor as part of the snippet's public configuration and is readable by anyone who inspects your site. Segment on coarse, non-secret attributes — plan tier, role, signup cohort — and never put a token, email, or anything sensitive in a trait name or value.