Javascript
For a complete overview of features in the Javascript SDK check out the docs regarding those. For getting started read on.
Install
Setup
Server setup
Configure the client
Get the visitor ID
In the request handler it's possible to generate a visitor ID with the function;
It's recommended to save this value in a cookie so it's possible to keep track of specific visitors and server them the same version of the AB test for each request. This could look like this;
We're not marking the cookie HttpOnly
, this way we can read the value from
the client and use it for analytic tracking
Get the visitor value
Now that we know who the visitor is on the server we can get them a value for AB test that we're running;
Serverless
Running serverless you need to also set the test value in a response cookie, the next request the same user makes to your serverless function it might hit a different instance which has no recollection of the given value.
Serverfull
When having a long running server, you can utilize the cache within the SDK, this way setting the response cookie is not required. However if you want to send analytic events from the client your probably still want to.
Client setup
Configure the client
Sync loading
Async loading
Get the visitor ID
Now that the client is setup it's time to get the config and setup the visitor. This will grab the values from the cookies and use them internally in the client.
(optional) Consume the test value
Getting the value for a test in the client is usually only needed for client side test where you can skip the Server setup. However it can happen that for a server test you want a tiny adjustment in some client side logic.
Post an analytic message
Last up is pushing analytic messages, these are required for the monitoring. Make sure you're sending the events that are configured in the test setup to be able to get the conversion value.