<!-- source: docs/api/4_s2s/globalstatistics/incrementglobalstats.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics/incrementglobalstats -->

# IncrementGlobalStats

Atomically increment (or decrement) global statistics. Global statistics are defined through the brainCloud portal.

StatisticsData like

`{ "stat1" : 10, "stat2" : -5.5 }`

would increment stat1 by 10 and decrement stat2 by 5.5. For the full statistics grammar see the [statistics grammar section](/api/appendix/statisticsgrammar).

There are many more complex operations supported such as

`{ "stat1" : "INC_TO_LIMIT#9#30" }`

which increments stat1 by 9 up to a limit of 30.

| Service | Operation |
| ------- | --------- |
| globalGameStatistics | UPDATE_INCREMENT |

## Method Parameters

| Parameter  | Description                                          |
| ---------- | ---------------------------------------------------- |
| statistics | A collection containing the statistics to increment. |

## Usage

**C#:**

```csharp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**C++:**

```cpp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Obj-C:**

```objectivec
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Java:**

```java
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**JavaScript:**

```javascript
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Dart:**

```dart
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Roblox:**

```lua
-- N/A
```

**GDScript:**

```gdscript
N/A
```

**Lua:**

```lua
-- S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Cloud Code:**

```cfscript
var statistics = {
  "PLAYER_COUNT": 1
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();

var postResult = globalStatisticsProxy.incrementGlobalStats(statistics);
if (postResult.status == 200) {
    // Success!
}
```

**Raw:**

```r
{
    "service": "globalGameStatistics",
    "operation": "UPDATE_INCREMENT",
    "data": {
        "statistics": {
            "PLAYER_COUNT": 1
        }
    }
}
```

<details>
<summary>JSON Response</summary>

```json
{
    "data": {
        "statistics": {
            "PLAYER_COUNT": 16
        }
    },
    "status": 200
}
```

</details>


---

<!-- source: docs/api/4_s2s/globalstatistics/index.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics -->

# Global Statistics

The Global Statistics service allows you to retrieve and update your app's predefined statistics defined on the
[Global Statistics](https://portal.braincloudservers.com/admin/dashboard#/development/stats-game) page of the brainCloud portal.

Global Statistics must be pre-defined from the [Statistics Rules - Global Statistics page](https://portal.braincloudservers.com/admin/dashboard#/development/stats-game)
of the brainCloud portal.  If instead you need to create them dynamically at runtime, you can enable the Generate App Statistic Rule Enabled setting on the
[Advanced Settings page](https://portal.braincloudservers.com/admin/dashboard#/development/core-settings-advanced-settings) of your app in the brainCloud portal.

Global (or App) Statistics are similar to User Stats, except that they are stored centrally across all of an app's users.

### API Summary

### Global Statistics

* [ReadAllGlobalStats](/api/s2s/globalstatistics/readallglobalstats) - Returns all of the global statistics.
* [ReadGlobalStatsForCategory](/api/s2s/globalstatistics/readglobalstatsforcategory) - Reads a subset of global statistics belonging to the specified category (all if omitted).
* [ReadGlobalStatsSubset](/api/s2s/globalstatistics/readglobalstatssubset) - Reads a subset of global statistics as defined by the input JSON.
* [IncrementGlobalStats](/api/s2s/globalstatistics/incrementglobalstats) - Atomically increment (or decrement) global statistics.
* [ProcessStatistics](/api/s2s/globalstatistics/processstatistics) - Apply statistics grammar to a partial set of statistics.


---

<!-- source: docs/api/4_s2s/globalstatistics/processstatistics.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics/processstatistics -->

# ProcessStatistics

Apply statistics grammar to a partial set of statistics. Global statistics are defined through the brainCloud portal.

The operations available are much richer than the standard _increment_ operation available via `IncrementGlobalStats()`.

For example:

```
{
    "INNING": "INC#1",              // Increment by one
    "INNINGSREM": "DEC#1",          // Decrement by one
    "OUTS": "RESET",                // Reset to the defined initial value
    "POINTS": "INC_TO_LIMIT#5#30",  // Increment by 5, but to a max of 30
    "PLAYERS": "SET#8",             // Set to the specified value
    "HIGHESTHR": "MAX#3",           // Set to the specified value if larger
    "ESTIMATE": "MIN#5",            // Set to the specified value if smaller
    "GAME" : "5"                    // Missing stat grammar will treat the operation as an increment
}
```

The above example would:

-   Increment `INNING` by `1`
-   Decrement `INNINGSREM` by `1`
-   Reset `OUTS` to its pre-defined initial value
-   Increment `POINTS` by `5`, but to a maximum of `30`
-   Set `PLAYERS` to `8`
-   Set `HIGHESTHR` to `3`, or remain at current higher value
-   Set `ESTIMATE` to `5`, or remain at current lower value
-   Increment `GAME` by `5`

For the full statistics grammar see the [statistics grammar section](/api/appendix/statisticsgrammar).

| Service | Operation |
| ------- | --------- |
| globalGameStatistics | PROCESS_STATISTICS |

## Method Parameters

| Parameter  | Description                                        |
| ---------- | -------------------------------------------------- |
| statistics | A collection containing the statistics to process. |

## Usage

**C#:**

```csharp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**C++:**

```cpp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Obj-C:**

```objectivec
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Java:**

```java
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**JavaScript:**

```javascript
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Dart:**

```dart
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Roblox:**

```lua
-- N/A
```

**GDScript:**

```gdscript
N/A
```

**Lua:**

```lua
-- S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Cloud Code:**

```cfscript
var statistics = {
  "INNING": "INC#1",
  "INNINGSREM": "DEC#1",
  "OUTS": "RESET",
  "POINTS": "INC_TO_LIMIT#5#30",
  "PLAYERS": "SET#8",
  "HIGHESTHR": "MAX#3",
  "ESTIMATE": "MIN#5"
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();

var postResult = globalStatisticsProxy.processStatistics(statistics);
if (postResult.status == 200) {
    // Success!
}
```

**Raw:**

```r
{
    "service": "globalGameStatistics",
    "operation": "PROCESS_STATISTICS",
    "data": {
        "statistics": {
            "INNING": "INC#1",
            "INNINGSREM": "DEC#1",
            "OUTS": "RESET",
            "POINTS": "INC_TO_LIMIT#5#30",
            "PLAYERS": "SET#8",
            "HIGHESTHR": "MAX#3",
            "ESTIMATE": "MIN#5"
        }
    }
}
```

<details>
<summary>JSON Response</summary>

```json
{
    "data": {
        "statisticsExceptions": {
            "INNINGSREM": "minApplied"
        },
        "statistics": {
            "OUTS": 0,
            "HIGHESTHR": 4,
            "PLAYERS": 8,
            "INNINGSREM": 0,
            "INNING": 2,
            "POINTS": 11,
            "ESTIMATE": 5
        }
    },
    "status": 200
}
```

</details>


---

<!-- source: docs/api/4_s2s/globalstatistics/readallglobalstats.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics/readallglobalstats -->

# ReadAllGlobalStats

Method returns all of the global statistics.

| Service | Operation |
| ------- | --------- |
| globalGameStatistics | READ |

## Usage

**C#:**

```csharp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**C++:**

```cpp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Obj-C:**

```objectivec
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Java:**

```java
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**JavaScript:**

```javascript
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Dart:**

```dart
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Roblox:**

```lua
-- N/A
```

**GDScript:**

```gdscript
N/A
```

**Lua:**

```lua
-- S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Cloud Code:**

```cfscript
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();

var postResult = globalStatisticsProxy.readAllGlobalStats();
if (postResult.status == 200) {
    // Success!
}
```

**Raw:**

```r
{
    "service": "globalGameStatistics",
    "operation": "READ",
    "data": {}
}
```

<details>
<summary>JSON Response</summary>

```json
{
    "data": {
        "statistics": {
            "TotalXpEarned": 0,
            "_GAME_LOGINS": 805
        }
    },
    "status": 200
}
```

</details>


---

<!-- source: docs/api/4_s2s/globalstatistics/readglobalstatsforcategory.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics/readglobalstatsforcategory -->

# ReadGlobalStatsForCategory

Method retrieves the global statistics for the given category.

| Service | Operation |
| ------- | --------- |
| globalGameStatistics | READ_FOR_CATEGORY |

## Method Parameters

| Parameter | Description                     |
| --------- | ------------------------------- |
| category  | The global statistics category. |

## Usage

**C#:**

```csharp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**C++:**

```cpp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Obj-C:**

```objectivec
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Java:**

```java
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**JavaScript:**

```javascript
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Dart:**

```dart
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Roblox:**

```lua
-- N/A
```

**GDScript:**

```gdscript
N/A
```

**Lua:**

```lua
-- S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Cloud Code:**

```cfscript
var category = "generated";
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();

var postResult = globalStatisticsProxy.readGlobalStatsForCategory(category);
if (postResult.status == 200) {
    // Success!
}
```

**Raw:**

```r
{
    "service": "globalGameStatistics",
    "operation": "READ_FOR_CATEGORY",
    "data": {
        "category": "generated"
    }
}
```

<details>
<summary>JSON Response</summary>

```json
{
    "data": {
        "statistics": {
            "ESTIMATE": 5,
            "HIGHESTHR": 4,
            "INNING": 2,
            "INNINGSREM": 0,
            "INNINGnew": 1,
            "OUTS": 0,
            "PLAYERS": 8,
            "PLAYER_COUNT": 4,
            "PLAYER_COUNTa": 1,
            "POINT": 1,
            "POINTS": 11,
            "otherstat": 0
        }
    },
    "status": 200
}
```

</details>


---

<!-- source: docs/api/4_s2s/globalstatistics/readglobalstatssubset.md -->
<!-- url: https://docs-internal.braincloudservers.com/api/s2s/globalstatistics/readglobalstatssubset -->

# ReadGlobalStatsSubset

Reads a subset of global statistics.

| Service | Operation |
| ------- | --------- |
| globalGameStatistics | READ_SUBSET |

## Method Parameters

| Parameter  | Description                                     |
| ---------- | ----------------------------------------------- |
| statistics | A collection containing the statistics to read. |

## Usage

**C#:**

```csharp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**C++:**

```cpp
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Obj-C:**

```objectivec
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Java:**

```java
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**JavaScript:**

```javascript
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Dart:**

```dart
// S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Roblox:**

```lua
-- N/A
```

**GDScript:**

```gdscript
N/A
```

**Lua:**

```lua
-- S2S call: to view example, switch to the Cloud Code or Raw tab.
```

**Cloud Code:**

```cfscript
var statistics = [
    "ESTIMATE", "POINTS"
];
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();

var postResult = globalStatisticsProxy.readGlobalStatsSubset(statistics);
if (postResult.status == 200) {
    // Success!
}
```

**Raw:**

```r
{
    "service": "globalGameStatistics",
    "operation": "READ_SUBSET",
    "data": {
        "statistics": [
            "ESTIMATE", "POINTS"
        ]
    }
}
```

<details>
<summary>JSON Response</summary>

```json
{
    "data": {
        "statistics": {
            "POINTS": 11,
            "ESTIMATE": 5
        }
    },
    "status": 200
}
```

</details>
