Handling Guests in Kongregate Games

Since guests are not allowed to access many different parts of the API, each developer must decide how they want to treat them. This document will go over how to detect when a user converts from a guest to a registered user in-page, which can happen without your game being reloaded. This documentation is meant to be supplimental to all other API documentation, and it assumes you have a general knowledge of how our API works, and are interested in improving the experience for guests who play your game.

You can determine if the user is a guest initially by calling the isGuest() function on the Kongregate API services object:


Testing guest functionality

In order to test your game as a guest while it is still in the preview state, you must append a special guest_access_key parameter to your game URL. More information on obtaining this key, and how to use it, can be found here

Guest to user conversion

The AS2 or AS3 client API must be used in order to detect when a user signs in. There are two different methods possible for detecting the change: manual polling, or listening for an event.

Manual polling

This is often the most simple method for catching the username/user_id change, as you can do it on your own terms, and handle the change when you are ready.

You can check manually for the username change by calling the getUsername function on the kongregate.services object, and detecting the change. If the user starts out as a guest, and they sign-in, the function will return their new username, and you can retrieve their game_auth_token and user_id using the getGameAuthToken and getUserId functions.

User sign-in event

When a user signs in using the welcome box or the link from chat, your application will receive an event (if you have registered for it) and you can process it however you like. Once the user is signed in, they will be able to save data, submit statistics, etc.


Once the Kongregate client API has successfully loaded into your application, you may register an event listener to let you know when a player converts from a guest to a registered user:

// Listen for a guest->user conversion, which can happen without a refresh
kongregate.services.addEventListener("login", onKongregateInPageLogin);

private function onKongregateInPageLogin(event:Event){
  // Get the user's new login credentials
  var user_id:Number = kongregate.services.getUserId();
  var username:String = kongregate.services.getUsername();
  var token:String = kongregate.services.getGameAuthToken();
  // Log in with new credentials here

AS2 integration

Unfortunately, no official API is currently available for AS2, but the following code template (while a bit dirty) should suffice:

// Check to see if the user is a guest initially
var services = _global.kongregate.services;
var isGuest:Boolean = services.isGuest();

// Register an event listener if the user is a guest, otherwise we can skip it
if( isGuest ){

// This function handles internal Kongregate API messages, we use it to listen
// for the sign-in message so we can be notified when a user converts from a
// guest to a user. 
function myMessageHandler(msg):Void{
    // Make sure to only handle the "user.info" message
  if( msg.getOpcode() == "user.info"){
    // If we started as a guest and aren't anymore, a sign-in occured
    if( isGuest && !services.isGuest() ){
      // Don't process this message more than once
      isGuest = false;

      // At this point services.getUsername() will contain the new username,
      // services.getUserId() will contain the player's Kongregate user_id,
      // and services.getGameAuthToken() will contain the new auth_token

Showing the sign-in lightbox or register lightbox

You can use the Kongregate API to display a sign-in or register lightbox to the user. This functionality comes in handy for upselling the user to create a Kongregate account, for example if they want to purchase an item.

This will show as an overlay, exactly as if they had clicked the "sign-in" or "register" link in the chat UI:


If the user successfully signs in, or registers an account, you will receive the login event as described above which contains their new username and game_auth_token.

If you want to show the user registration lightbox, you can call: