Note This article only applies if you are using Stats 2013 or Achievements 2013.
For titles configured on XDP using Data Platform 2013, this article will walk you through configuring an event and stat on XDP, and then adding code to your title to send events and update stats.
The following examples use the Xbox Developer Portal (XDP) to configure the Xbox Live experience for the game.
After your company has an agreement to create products for Xbox One, you can begin to configure your content in the XDP. If your company is not yet set up with XDP access and you are developing a game, contact your Microsoft account manager; if you are developing an application, contact Xbox App Partner Requests (xboxapps@microsoft.com); and if you are working with the ID@Xbox program contact ID Setup (idsetup@microsoft.com).
The ID@Xbox program enables qualified game developers of all sizes to unleash their creativity by self-publishing digital games on Xbox One, giving studios the tools and support needed to maximize their success. Visit http://www.xbox.com/en-us/Developers to learn more.
Once you have access to XDP, you will need Microsoft to create a product group for your game. Your Microsoft account manager can assist with this process.
Once a product group has been created for your game, you can use XDP to configure Xbox Live for your game. The Xbox Live configuration for your game is also referred to as its Service Configuration.
The following steps will navigate to the location in XDP where you can add the events, stats, achievements, and leaderboards for your game:
Service configurations are defined at the sandbox level. If you export your product to another sandbox, you will also need to export your service configuration.
In XDP, before we can define the rules that implement the player experiences we want to achieve, we need to identify and define the events which will drive those experiences.
Since achievements and leaderboards are based on user stats, we can look at the stats that we will define in order to see what events our title will need to send.
To power the experiences we will define in this example, we will use an event that we send at the end of each lap in a race.
We’ll call this event LapCompleted, and it will be the event that we’ll use to drive our customized experiences. In order to power those experiences, we’ll also define the following fields as part of our LapCompleted event:
Now, we’ll define this event in XDP:



Now that we have defined the player experiences, we can start creating the Stat Rules that implement those experiences. Since we’re using Lap Time for all three scenarios (Featured Stats, Achievements, and Leaderboards) we’ll go ahead and configure that first.
This stat will show up as a Featured Stat (also known as a Hero Stat) and will also be used for a Global Leaderboard with additional metadata.
The game fires in-game events when certain actions happen in the game and are considered to be the raw data for creating stats. At least one stat should be created or updated by every event (generating multiple stats in a single event will be covered in the Player Stats topic).
On the Events & Stat Rules page, select the LapCompleted event from the list of events.
Click New (to the right of Stat Rules) to create a new Stat Rule. The new stat rule will be based on the selected event.

Enter FastestLap for the Stat Rule Name.
Since we want other apps and titles, such as the Windows 10 Xbox Live app, to be able to access stats created by this rule, check the Open read access to any title box.
Stat Rules have logic that defines how the event will create or update the stat. Since we want to track the fastest lap, we only want to update the stat value if the new Lap Time is lower than the existing fastest lap time.
To do this, select LapTime as the Parameter, and Min as the operator:

Finally, we need to make sure that the event contains all the extra data (known as Stat context or metadata) that we need for this specific stat: the player’s car, track, and weather conditions.
Select CarModel and click Add Event Field to add the field to the metadata.
Repeat this for the WeatherCondition and TrackId fields:

Click the Add Stat Rule button to create the stat rule.
Now that the stat rule is complete, we want the stat to show up in the GameHub’s Achievement tab so we have to configure a Featured Stat (known as a Hero Stat in XDP).

Using the same Lap Time stat, we can configure a leaderboard so that every player can see how their lap time ranks against all other players across the world.

As player stats get updated, the leaderboard will also be updated to reflect any change in the rankings.
If there are already existing player stats when the leaderboard is created, it may take several hours before the new leaderboard is updated with the pre-existing stats.
We want players to really go all out and challenge themselves to find a track and car combination that let’s them finish a lap in under a minute. This is how we would go about and configure the Achievement.



Now that we’ve defined the LapCompleted event that Xbox Live will use to update our user scenarios, we need to add code to our title in order to send the event when a player completes a racing lap in the game.
For Xbox One console games, you’ll need to create wrapper functions to send the event from your code. You do this by downloading a manifest file from XDP, and then using a tool to create a custom header file for you.
Once you have authenticated your player and created an XboxLiveContext object for the player, you can get a handle to the EventsService class from the XboxLiveContext.EventsService property.
The EventsService class contains the overloaded WriteInGameEvent() method, which is the method you’ll use to write the game event. In C++, the equivalent method is called write_in_game_event().
If your game event doesn’t need any additional data for your user scenarios (for example, a “FoundSecretLair” event), you can use the simple form of the WriteInGameEvent method, which takes a single event name as the only parameter:
WriteInGameEvent("FoundSecretLair"); (WinRT)write_in_game_event("FoundSecretLair"); (C++)Note The event names are not case sensitive. However, the name of the event must match the exact spelling of the event that you defined in your service configuration. If your title writes an event that does not match any stat rules that are defined for your configuration, the Xbox Live service silently ignores the event, and your title recieves no notification that the event was ignored.
In order to include data with your event, you’ll need to use the second version of the API, which includes two additional parameters. The first parameter is the set of dimension values for your event, and the second parameter is the set of measurement values:
WriteInGameEvent("LapCompleted", dimensions, measurements); (WinRT)write_in_game_event("LapCompleted", &dimensions, &measurements); (C++)In WinRT, these sets of values are defined as PropertySet values. In C++, the sets are defined as web::json::value objects.
The following example demonstrates a WinRT example of a method that writes the LapCompleted event, along with contextual data about the event:
public void WriteLapCompleted(
Microsoft.Xbox.Services.XboxLiveContext xboxLiveContext,
int lapTime,
string carModel,
string weatherCondition,
int trackId )
{
string xuid = xboxLiveContext.User.XboxUserId;
try
{
var measurements = new Windows.Foundation.Collections.PropertySet();
measurements.Add("LapTime", lapTime);
var dimensions = new Windows.Foundation.Collections.PropertySet();
dimensions.Add("CarModel", carModel);
dimensions.Add("WeatherCondition", weatherCondition;
dimensions.Add("TrackId", trackId);
xboxLiveContext.EventsService.WriteInGameEvent("LapCompleted", dimensions, measurements);
}
catch (Exception e)
{
// Handle errors
}
}