> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 中繼資料統計資料

> 將中繼資料附加至 PlayFab 統計資料，以在數值旁攜帶內容詳細資料，豐富排行榜項目和玩家進度資料。

# 將內容資料新增至統計資料

在本教學課程中，我們將說明如何在每次更新統計資料時新增內容資訊。在某些情況下，只儲存統計資料是不夠的。遊戲工作室可能會新增一些有關玩家如何執行特定動作的詳細資料，或者遊戲中可能有與統計資料相關的功能。

我們將繼續使用我們的競技射擊遊戲。在此範例中，遊戲獲得巨大的成功，但面臨一項挑戰。有太多人抱怨有人使用外部元件「入侵」遊戲，這些元件會移除武器的後座力並改善瞄準輔助。因此，現在我們的任務是追蹤更多有關遊戲中所使用之所有元件和網路資訊的資訊。

## 建立統計資料

為了示範如何處理此案例，我們將採用[統計資料的進階運用](/zh-TW/services/playfab/player-progression/statistics/doing-more-statistics)頁面中的統計資料定義。從此定義中，我們將了解如何將中繼資料新增至統計資料中新增的每一列。

```C# theme={null}
public static async Task CreateStatisticDefinitionAsync(PlayFabAuthenticationContext context, string statName)
{
    PlayFabProgressionInstanceAPI statsAPI = new PlayFabProgressionInstanceAPI(context);
    CreateStatisticDefinitionRequest statDefinitionRequest = new CreateStatisticDefinitionRequest()
    {
        Name = statName,
        AuthenticationContext = context,
        EntityType = "title_player_account",
        VersionConfiguration = new VersionConfiguration()
        {
            MaxQueryableVersions = 1,
            ResetInterval = ResetInterval.Manual,
        },
        Columns = new List<StatisticColumn>()
        {
            new StatisticColumn()
            {
                Name = "Distance",
                AggregationMethod = StatisticAggregationMethod.Max,
            },
             new StatisticColumn()
            {
                Name = "Caliber",
                AggregationMethod = StatisticAggregationMethod.Min,
            }
        },
    };
    
    PlayFabResult<PlayFab.LeaderboardsModels.EmptyResponse> createStatDefResult = await statsAPI.CreateStatisticDefinitionAsync(statDefinitionRequest);
}
```

就本教學課程而言，從此範例中要掌握的重要元素是統計資料的結構。如您所見，它有多個資料行，允許多個值。但我們的重點是如何將內容資訊新增至每一列。

### 將中繼資料新增至每個統計資料

我們想知道玩家是否有任何影響遊戲的未經授權硬體，或任何其他可能提升玩家表現的惡意軟體。反作弊系統能夠取得所有這些資訊。我們只需要為遠距離射擊統計資料附加這些資訊。

為了執行此動作，我們將使用 UpdateStatistics API。我們可以在這裡查看 SDK 範例：

```C# theme={null}
public static async Task UpdateStatisticForPlayer(PlayFabAuthenticationContext context, string statName, string entityId, int score)
{
    PlayFabProgressionInstanceAPI statsAPI = new PlayFabProgressionInstanceAPI(context);
    UpdateStatisticsRequest updateStatRequest = new UpdateStatisticsRequest()
    {
        Entity = new PlayFab.LeaderboardsModels.EntityKey()
        {
            Id = entityId,
            Type = EntityType
        },
        AuthenticationContext = context,
        Statistics = new List<PlayFab.LeaderboardsModels.StatisticUpdate>() 
        {
            new PlayFab.LeaderboardsModels.StatisticUpdate() 
            {
                Name = statName,
                Scores = new List<string> { score.ToString()},
                Metadata = "Anticheat data"
            }
        }
    };

    PlayFabResult<UpdateStatisticsResponse> updateResult = await statsAPI.UpdateStatisticsAsync(updateStatRequest);
}
```

我們在這裡看到的主要概念是在 `StatisticUpdate` 中使用 `Metadata` 參數，它指的是除了值本身之外要更新的內容資料。在這裡，我們可以新增對開發人員有意義的任何資訊，在此案例中為反作弊資料。

透過這些範例，我們現在已準備好追蹤頂尖玩家的所有相關資訊，讓遊戲版主能夠更好地決定要禁止誰。

## 結論

在本教學課程中，我們學到了如何執行下列作業：

* 建立多資料行統計資料。
* 將中繼資料新增至統計資料。

## 另請參閱

* [建立基本統計資料](/zh-TW/services/playfab/player-progression/statistics/create-basic-statistics)。
* [統計資料的進階運用](/zh-TW/services/playfab/player-progression/statistics/doing-more-statistics)。
* [季節性統計資料](/zh-TW/services/playfab/player-progression/statistics/seasonal-statistics)。
* [交易式寫入](/zh-TW/services/playfab/player-progression/statistics/transactional-writes)
* [API 參考](/zh-TW/services/playfab/player-progression/statistics/api-reference)。
* [限制](/zh-TW/services/playfab/player-progression/statistics/limits-statistics)。
* [配額](/zh-TW/services/playfab/player-progression/statistics/quota-statistics)


## Related topics

- [PlayFab 統計資料概觀](/zh-TW/services/playfab/player-progression/statistics/index.md)
- [統計資料計量](/zh-TW/services/playfab/pricing/meters/statistics-meters.md)
- [統計資料的進階運用](/zh-TW/services/playfab/player-progression/statistics/doing-more-statistics.md)
- [事件型統計資料初探](/zh-TW/services/xbox-services/player-data/stats-leaderboards/event-based/config/live-stats-first-glance.md)
- [PlayFab 玩家進度文件](/zh-TW/services/playfab/player-progression/index.md)
