FeaturesยปCustom Events


Custom Events

Discover how to track custom events with Analyse.

Starting from version 2.0.0, Analyse has been supercharged with the ability to track custom events using the /analyse track command. This command is your all-access pass to track anything you like, from a player casting their vote on a server, to the triumphant moment a player completes a quest.

Tracking Via Command

To start tracking a custom event, just call into action the /analyse track command along with these trusty sidekicks:

/analyse track <player> <event> <value>
  • <player> - The player who's the star of the event.
  • <event> - The event's name, like the title of a thrilling adventure.
  • <value> - The JSON metadata that provides the juicy details of the event.

Imagine you want to celebrate when a player unlocks a rare cosmetic on your server. You could give this command a whirl:

/analyse track Siri cosmetics:unlock {"name": "Wings of Destiny", "rarity": "epic"}

And how about when a player successfully trades with a villager? Try this:

/analyse track Steve villager:trade {"trade_item": "Emerald", "trade_quantity": 5}

That's the gist of it! But, if you're more of a developer, you can also utilise the Analyse SDK to smoothly track custom events.

Tracking Via SDK

For those that like to roll up their sleeves and get coding, you can also send custom events to Analyse using the track method from the AnalysePlayer interface. This method takes an instance of PlayerEvent - or even multiple instances if you're feeling adventurous.

Check out this example:

PlayerEvent playerEvent = new PlayerEvent("mine_diamond", "MyAwesomePlugin")
    .withMetadata("block_location", "Underground Fortress")
    .withMetadata("tool_used", "Diamond Pickaxe")
    .withMetadata("mining_speed", 3);

In this case, the PlayerEvent class scoops up an id and an origin as parameters. The ID is like a backstage pass, a unique identifier for the event, while the origin is the name of your plugin orchestrating the event. The origin helps Analyse recognise the plugin sending the event, and it's showcased in your Analyse dashboard.

Adding a bit of extra color to the event? No problem! Use the withMetadata method. It takes a key and a value, giving back the PlayerEvent instance. This allows you to string together multiple calls to the method, adding as much detail as you want.

Want to know more about that? Swing by our SDK documentation for the full story.