A/B test
A/B testing in Blings MP5 with code
Use this pattern when you want a small code snippet to choose a variant, pass it into the MP5 data fields, mirror it to UTM parameters, and keep the same viewer on the same version after refresh.
This is different from the no-code Flow Map A/B test node. The Flow Map A/B test node splits traffic inside the Flow Map UI. This article covers a code-based assignment pattern that writes a variant into params.data, so Studio, Flow Map conditions, and analytics can use that value.
The pattern does four things:
Uses a variant from the incoming data or URL when one is provided.
Otherwise reuses the variant stored in
localStorage.Otherwise randomly picks a variant and stores it.
Mirrors the variant into a UTM field for analytics and BI reporting.
Add a variant field to the MP5 data schema
In your Blings project, add a Dynamic Data field for the test variant. The examples below use abtest1.

The field must exist in your video data schema so you can reference it in:
Flow Map conditions for scene selection.
Studio connectors for text, media, links, and other content changes.
Analytics exports and dashboards.
Full demo code
Copy the code below into Blings Platform -> Integration -> Advanced code.
IntegrationTo run another test, call runStickyABTest again with a different testName and a different analytics slot:
How the variant is selected
The helper uses this priority order:
If
params.data[testName]already has a valid variant, it respects that value.If the viewer already has a valid stored value in
localStorage, it reuses that value.If neither exists, it randomly picks a variant from the list.
This lets you support both deterministic and automatic assignment:
Use deterministic assignment when a campaign link or backend already chooses the variant.
Use automatic assignment when the MP5 page should randomize a demo or web-link visitor.
For example, if your integration maps ?abtest1=free-trial into params.data.abtest1, the code will use free-trial and store it as the sticky value.
Save the selected variant on UTM for analytics
To make the selected version visible in analytics, copy the chosen variant into a UTM parameter.
After traffic arrives, your dashboards can break down performance by the selected test variant using utm_source, or any other UTM field you choose, such as utm_campaign or utm_content.
Stickiness
Without stickiness, the same viewer may see different versions after a refresh. That can break the user experience, make debugging harder, and pollute analytics.
With localStorage stickiness:
The first assigned variant is saved on the viewer's browser.
Refreshes keep showing the same version.
A valid incoming variant later overwrites the stored value and becomes the new sticky value.
Important limitations:
localStorageis device and browser specific. A viewer who switches devices or browsers may get a different variant.Clearing browser storage resets the assignment.
If you need the same variant across devices, store the chosen variant in your backend user profile and inject it into
params.data[testName]on load.
Where to use the variant inside Blings
Once params.data.abtest1 is set, you can use it anywhere Dynamic Data is available.
Scene selection with Flow Map conditions
Use a Flow Map condition when each variant should route viewers into a different scene or path. The code assigns abtest1; the Flow Map only reads it as a data condition.

For example:
abtest1 is 10off-> show a discount scene.abtest1 is free-trial-> show a trial scene.Otherwise-> show the control path.
For no-code traffic splitting inside Flow Map, use the Flow Map A/B test node instead.
Content selection in Studio
Use Studio when the variant should change copy, visuals, links, or other connector values inside the same scene.

Common examples:
Show different headline text.
Swap a product image or offer message.
Change button text or a CTA link.
Trigger different JavaScript or connector behavior.
Verification
Test each variant before launch.
Open the MP5 page with an explicit variant value, such as
?abtest1=free-trial, and confirm the expected content appears.Refresh the page and confirm the same variant remains visible.
Open an incognito window, or clear only this test key in the console:
Then reload and confirm a variant is assigned again.
Also check your analytics destination and confirm the selected value appears in the UTM field you configured.
Related documentation
Last updated

