SDK
A/B tests
Get a variant for a player, track conversions, and roll out the winner.
Running an A/B test from your plugin is two steps: read which variant a player is assigned to, and track a conversion when they do the winning action.
Read a variant
String variant = Analyse.getVariant(player.getUniqueId(), "new-spawn");if ("B".equals(variant)) {// teleport to new spawnplayer.teleport(newSpawnLocation);} else {// teleport to old spawn (or variant A)player.teleport(oldSpawnLocation);}
getVariant is deterministic: the same player always gets the same variant for a given test. That means you can call it as many times as you want without accidentally flipping their experience mid-session.
If the test doesn't exist, is inactive, or hasn't synced yet, getVariant returns null. Always treat that as "variant A" (the control) so your code still works.
Track a conversion
Analyse.trackConversion(player.getUniqueId(),player.getName(),"new-spawn", // the test key"first_purchase" // the conversion event);
A conversion means "this player did the thing we're testing for". Call it from wherever that action happens in your plugin.
You can call trackConversion multiple times for the same player (e.g. every purchase). Analyse records all of them and the dashboard handles deduplication for the conversion rate.
A full example
@EventHandlerpublic void onJoin(PlayerJoinEvent event) {Player player = event.getPlayer();UUID uuid = player.getUniqueId();// Show the variant-specific spawnString variant = Analyse.getVariant(uuid, "new-spawn");if ("B".equals(variant)) {player.teleport(newSpawn);} else {player.teleport(oldSpawn);}}@EventHandlerpublic void onPurchase(PurchaseEvent event) {// Count the first purchase as a conversion on the spawn testAnalyse.trackConversion(event.getPlayer().getUniqueId(),event.getPlayer().getName(),"new-spawn","first_purchase");}
Check if a test is active
if (Analyse.isTestActive("new-spawn")) {// run the test-aware code path} else {// run your default behavior}
Useful when you want to clean up test-specific code gracefully after a test ends.
List all active tests
for (ABTest test : Analyse.getActiveTests()) {getLogger().info("Active test: " + test.getKey());}
Tips
- Keep
getVariantin a stable place. If you call it from too many spots, it's harder to reason about. Call it once on join, store the result on the player, use it everywhere. - Don't modify conversion logic mid-test. Changing what "counts" as a conversion invalidates the stats.
- Give the test plenty of time. Most tests need at least a few hundred assignments per variant before the confidence hits 95%. That's days for a small server.