Setting Up an Experiment with Assignment: Server
Learn the steps that let your backend decide a Server-side experiment: the visitor ID, a server key, a flag key, variant keys and payloads, and the code.
3 min read
With Assignment: Server, your backend decides which variant each visitor gets. The experiment's settings tab shows a setup checklist in this order and ticks each step once it is done. Pertento will not start the experiment until the visitor ID is on, the flag key is set and every variant has a key.
1. Turn on the visitor ID
Go to Websites, open the website's settings and switch on Visitor ID. The page and your server have to agree on who the visitor is, so Server cannot be chosen while it is off. See Anonymous Visitor ID.
2. Create a server key
Go to Websites and click Server keys on the website's row. An Owner or Admin creates the key, and it is shown once, so put it straight into your backend's environment, for example as PERTENTO_SERVER_KEY. See Server keys: creating, rotating and revoking.
3. Choose Server and set the flag key
Create an experiment of type Server-side. On its settings tab, under Assignment, choose Server, then give the experiment a flag key. The flag key is the name your code asks for, such as new-checkout.
A flag key is 1 to 64 lowercase letters, digits and hyphens, starting with a letter or digit, and no two experiments on a website can share one.
4. Give every variant a key
Go to Variants, open the menu on each variant and choose Edit key and payload. The key is what your code switches on, such as one-page. It follows the same rules as the flag key and has to be unique within the experiment.
The payload is optional JSON of up to 8 KB that your code receives with the decision: a button text, a price table, a set of options. It keeps the values a variant needs with the variant rather than in your code.
5. Choose what it buckets on, and who is enrolled
Bucket on decides what the variant is tied to: the Visitor ID, one per browser, or a Customer ID, your own ID for a signed-in customer, so they see the same variant on every device. Attribute rules narrow who is enrolled. Both are explained in Attribute rules and bucketing on a customer ID.
6. Add the code, then start
The settings tab shows the code for this experiment with its real flag key and variant keys filled in: the SDK call, the seed script and an HTTP example. In short:
const decision = await pertento.getVariant('new-checkout', { visitorId });
if (decision.variantKey === 'one-page') {
// render the one-page checkout
}
const seed = pertento.seedScript([decision], visitorId); // into <head>, before the Pertento scriptUntil the experiment starts, every decision is control, so the code can go live first. Then start the experiment. See Installing the Pertento server SDK, or the HTTP API for a backend without the SDK.
Notes
- Variant weights work as on any experiment: visitors are split by weight, and the same ID always gets the same variant. See Traffic allocation and variant weights.
- The assignment, the flag key, the variant keys and Bucket on can only be changed while the experiment is a draft.