{"__v":14,"_id":"56af73a08be2ea0d00b48890","category":{"__v":3,"_id":"56af6d6ecc4cbd0d00ce2c88","pages":["56af6e8460a37a0d00ed87ac","56af71e58be2ea0d00b48887","56af73a08be2ea0d00b48890"],"project":"56abbf55f25f160d00e17f4e","version":"56abbf55f25f160d00e17f51","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-01T14:36:30.275Z","from_sync":false,"order":2,"slug":"concepts","title":"Kongregate APIs & Concepts"},"parentDoc":null,"project":"56abbf55f25f160d00e17f4e","user":"56abbec30b9e0b0d00616274","version":{"__v":12,"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-01T15:02:56.255Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":15,"body":"## Sending Statistics\n\nAny event in your game can be submitted to Kongregate as a score. This allows you to use Kongregate's leaderboards, and if the game qualifies we can use those stats to make put achievements on the game. In general, we recommend having 3 - 5 statistics in your game to track.\n\nAll statistics must be non-negative integers. So, 0, 42, and 613341 are all fine, but -5 and 1.542 won't work. If you have a carefully timed game that records milliseconds, you'll want to multiply the time by 1000 when submitting to our server. So 1.542 seconds would need to be submitted as 1542 milliseconds.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Gotcha Alert\",\n  \"body\": \"The maximum value of a stat is BIG_INT (9.223 x 10<sup>18</sup>). If you have a game with ludicrously-large numbers (**cough** idle games **cough**), we recommend taking a log of your number (and then perhaps multiply by 1000) to make them work with scoreboards.\"\n}\n[/block]\nStatistics should generally be submitted to the system at the time that they change (like leveling up) or a fairly frequent checkpoints (level/battle completed). Additionally, major stats should be submitted once on each session start. This way if there is an error or glitch during something like a level up a player can refresh the page to force the stat to resubmit.\n\n### Types\n\n*   **Max:** The value on the server will be replaced if the new value is higher, for example a high score, battles won, user level, etc.\n*   **Min:** The value on the server will be replaced if the new value is lower, for example the lowest time for completing a lap.\n*   **Add:** The new value will be added to the value stored on the server, for example total number of coins collected. This can be used for statistics which are cumulative. That said, it is more susceptible to error due to connection problems and failed submissions, so we recommend this only if the game or your server doesn't track stats that can be submitted as \"max\" or \"min\" stats.\n*   **Replace:** The new value will always overwrite the value on the server, this can be useful for statistics that need to go either up or down, such as a player ranking.\n\nIn most cases, the best choices for stats to submit are progress-based stats. Things like player level, quests completed, towns captured, matches won, high score on a level, units collected, fastest time on a track, etc. that increase as the player continues in the game. Submit these as numerical stats (i.e. send us the level, not just a \"1\" when the player hits level 20) and we'll have the most flexibility when working to design badges for your game.\n\n### Initialized Statistic\n\nFor social/MMO games, and games with high system requirements or large downloads, we recommend submitting a stat to us called \"initialized\" or \"loaded\" that sends a \"1\" each time the game loads successfully. This must be done very early, generally at the title screen or no later than character selection/creation (if that happens first thing) - it cannot be post-tutorial or after the first level. We can use this stat to ensure that ratings for the game are by people who meet the game's minimum system requirements, which will help give you a more accurate rating. Let us know if you have set up a statistic like this so we can set it up as a filter. This service is currently only available for virtual-goods-enabled games.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"As this may modify the game's rating, any games using this service will be excluded from weekly and monthly contests.\"\n}\n[/block]\n### Creating your statistics\n\nAfter you come up with your list of statistics, you need to set them up on the server. This can be done by adding /statistics onto the URL for your game in your browser window. \n\nFor example: _www.kongregate.com/games/my-username/my-game/statistics_ \n\nThis will take you to the statistics editor page, which can only be viewed by the owner of a game. Note: You can also view the statistics editor on the edit game page.\n\n![](https://cdn1.kongcdn.com/images/docs/dev-statistics.png)\n\nGive each statistic a name, description, and choose it’s type. You can also select statistics you wish to show up in the leaderboards by checking the \"Display in Leaderboards\" option.\n\nOnce you have created all your statistics on the server, it is time to integrate the API into your game.\n\n### Submitting statistics\n\nYou can use either the Client or Server API to submit statistics to the server:\n\n*   [Statistics Client API](doc:client-api-stats-submit) \n*   [Statistics Server API](doc:server-api-statistics)\n\n### Retrieving statistics\n\n*   [High Scores Server API](doc:server-api-high-scores) \n\n### Testing statistic submissions\n\nYou can see statistic submissions go through in a Javascript console (Chrome, Firebug, etc.) if you add `?debug_level=4` to the game's URL. The exact syntax changes depending on whether you're using client or server stats, but you should see them submit either way.\n\n### Some helpful integration tips from Greg (creator of badges)\n\nHere are some general tips you can follow to reduce the chances that I’ll whine to you over email about changing something.\n\n**1\\. Please add a “max” stat that’s something like “GameComplete 1” that submits when your game is completed.**\n\nThis is a no-brainer stat that allows me to add a badge for simply completing your game. The stats API is the same as our high scores API, but not everything has to be a \"high score\" -- you can simply submit binary conditions for whether or not something has been accomplished.\n\n**2\\. Connect to our servers as soon as the game is loaded.**\n\nIf you do not connect to our servers, you cannot send any data! It's a very common mistake for developers to skip this crucial first step.\n\n**3\\. RESUBMIT ALL DATA RETROACTIVELY ON GAME LOAD!!**\n\n<span style=\"font-style:italic\">This point cannot be emphasized enough!</span> You need to submit all data to us <span style=\"font-style:italic\">twice</span>: first, when the specific event actually occurs, and then again when the game is reloaded.\n\nThis is because if players have already completed the badge task before the badge is created, or they complete the required task during a connection blip, then we will have no way of awarding the badge. Just keep resubmitting old data to us! Don't worry about our servers -- they can handle it! If there is a technical reason why you cannot resubmit old data on game load, you can instead resubmit this data at some other infinitely recurring interval (eg, completing a level again, accessing a menu screen, dying, etc.).","excerpt":"","slug":"concepts-statistics","type":"basic","title":"Statistics & High Scores"}

Statistics & High Scores


## Sending Statistics Any event in your game can be submitted to Kongregate as a score. This allows you to use Kongregate's leaderboards, and if the game qualifies we can use those stats to make put achievements on the game. In general, we recommend having 3 - 5 statistics in your game to track. All statistics must be non-negative integers. So, 0, 42, and 613341 are all fine, but -5 and 1.542 won't work. If you have a carefully timed game that records milliseconds, you'll want to multiply the time by 1000 when submitting to our server. So 1.542 seconds would need to be submitted as 1542 milliseconds. [block:callout] { "type": "warning", "title": "Gotcha Alert", "body": "The maximum value of a stat is BIG_INT (9.223 x 10<sup>18</sup>). If you have a game with ludicrously-large numbers (**cough** idle games **cough**), we recommend taking a log of your number (and then perhaps multiply by 1000) to make them work with scoreboards." } [/block] Statistics should generally be submitted to the system at the time that they change (like leveling up) or a fairly frequent checkpoints (level/battle completed). Additionally, major stats should be submitted once on each session start. This way if there is an error or glitch during something like a level up a player can refresh the page to force the stat to resubmit. ### Types * **Max:** The value on the server will be replaced if the new value is higher, for example a high score, battles won, user level, etc. * **Min:** The value on the server will be replaced if the new value is lower, for example the lowest time for completing a lap. * **Add:** The new value will be added to the value stored on the server, for example total number of coins collected. This can be used for statistics which are cumulative. That said, it is more susceptible to error due to connection problems and failed submissions, so we recommend this only if the game or your server doesn't track stats that can be submitted as "max" or "min" stats. * **Replace:** The new value will always overwrite the value on the server, this can be useful for statistics that need to go either up or down, such as a player ranking. In most cases, the best choices for stats to submit are progress-based stats. Things like player level, quests completed, towns captured, matches won, high score on a level, units collected, fastest time on a track, etc. that increase as the player continues in the game. Submit these as numerical stats (i.e. send us the level, not just a "1" when the player hits level 20) and we'll have the most flexibility when working to design badges for your game. ### Initialized Statistic For social/MMO games, and games with high system requirements or large downloads, we recommend submitting a stat to us called "initialized" or "loaded" that sends a "1" each time the game loads successfully. This must be done very early, generally at the title screen or no later than character selection/creation (if that happens first thing) - it cannot be post-tutorial or after the first level. We can use this stat to ensure that ratings for the game are by people who meet the game's minimum system requirements, which will help give you a more accurate rating. Let us know if you have set up a statistic like this so we can set it up as a filter. This service is currently only available for virtual-goods-enabled games. [block:callout] { "type": "info", "title": "Note", "body": "As this may modify the game's rating, any games using this service will be excluded from weekly and monthly contests." } [/block] ### Creating your statistics After you come up with your list of statistics, you need to set them up on the server. This can be done by adding /statistics onto the URL for your game in your browser window. For example: _www.kongregate.com/games/my-username/my-game/statistics_ This will take you to the statistics editor page, which can only be viewed by the owner of a game. Note: You can also view the statistics editor on the edit game page. ![](https://cdn1.kongcdn.com/images/docs/dev-statistics.png) Give each statistic a name, description, and choose it’s type. You can also select statistics you wish to show up in the leaderboards by checking the "Display in Leaderboards" option. Once you have created all your statistics on the server, it is time to integrate the API into your game. ### Submitting statistics You can use either the Client or Server API to submit statistics to the server: * [Statistics Client API](doc:client-api-stats-submit) * [Statistics Server API](doc:server-api-statistics) ### Retrieving statistics * [High Scores Server API](doc:server-api-high-scores) ### Testing statistic submissions You can see statistic submissions go through in a Javascript console (Chrome, Firebug, etc.) if you add `?debug_level=4` to the game's URL. The exact syntax changes depending on whether you're using client or server stats, but you should see them submit either way. ### Some helpful integration tips from Greg (creator of badges) Here are some general tips you can follow to reduce the chances that I’ll whine to you over email about changing something. **1\. Please add a “max” stat that’s something like “GameComplete 1” that submits when your game is completed.** This is a no-brainer stat that allows me to add a badge for simply completing your game. The stats API is the same as our high scores API, but not everything has to be a "high score" -- you can simply submit binary conditions for whether or not something has been accomplished. **2\. Connect to our servers as soon as the game is loaded.** If you do not connect to our servers, you cannot send any data! It's a very common mistake for developers to skip this crucial first step. **3\. RESUBMIT ALL DATA RETROACTIVELY ON GAME LOAD!!** <span style="font-style:italic">This point cannot be emphasized enough!</span> You need to submit all data to us <span style="font-style:italic">twice</span>: first, when the specific event actually occurs, and then again when the game is reloaded. This is because if players have already completed the badge task before the badge is created, or they complete the required task during a connection blip, then we will have no way of awarding the badge. Just keep resubmitting old data to us! Don't worry about our servers -- they can handle it! If there is a technical reason why you cannot resubmit old data on game load, you can instead resubmit this data at some other infinitely recurring interval (eg, completing a level again, accessing a menu screen, dying, etc.).