Installation

In addition to being on our marketplace, you can use the Clay.io API to enhance your game with features like leaderboards, achievements and payment processing.

To install the API you just include this snippit of JavaScript:

<script type="text/javascript">
var Clay = Clay || {};
Clay.gameKey = "YOURGAMEKEY";
Clay.readyFunctions = [];
Clay.ready = function( fn ) {
    Clay.readyFunctions.push( fn );
};
( function() {
    var clay = document.createElement("script");
    clay.src = ( "https:" == document.location.protocol ? "https://" : "http://" ) + "clay.io/api/api.js"; 
    var tag = document.getElementsByTagName("script")[0]; tag.parentNode.insertBefore(clay, tag);
} )();
</script>

Modules (if you don't plan on using every feature, and want a smaller api.js file):

This just asynchronously loads our JavaScript API, and allows you to set a Clay.ready() function explained here.

To get a game key, you'll first need to add your game here. Once that is done you'll be able to find your game key by clicking "settings" from the developers page

You can also pass some options in Clay.options. The current options are

  • debug (boolean) - For information click here
  • hideUI (boolean) - The hideUI property, if set to true prevents any Clay.io UI from showing (a reason to set this to true is if your game is being played in a wrapper than doesn't include the DOM).
  • fail (function) - A function that is called if the Clay.io API fails to connect to the backend (say, if there is no internet access)
An example of these in action is:

// put this before the self-calling anonymous function
Clay.options = { debug: true, hideUI: true, fail: function() {
    console.log( "Couldn't connect" );
} };

Provide Feedback

We take customer support, and the quality of our developer tools and documentation very seriously. We want to hear how you think we can improve our documentation! Let us know if anything is missing, or unclear on this documentation page, and we'll get that fixed!

1369187048