SDK v3.2.0 removes DeltaDNA. See Upgrading from 3.0/3.1 for more information.
SDK v3.1.4 Includes a fix for Adjust Uninstall and Reinstall Tracking for iOS 13
SDK v3.1.2 Includes an Adjust Upgrade with support for Uninstall and Reinstall Tracking.

Configuring Your AIR Application Descriptor File

Add the Kongregate extensions to the extensions tag:

<extensions>
  <extensionID>com.kongregate.air.AndroidAppCompatV7</extensionID>
  <extensionID>com.kongregate.air.AndroidSupportV4</extensionID>
  <extensionID>com.kongregate.air.GooglePlayServices</extensionID>
  <extensionID>com.kongregate.air.KongregateAPI</extensionID>
</extensions>

For Android you will need to add you will need to add a handful of Andorid Manifest Additions for the Kongregate, SWRVE, and Adjust SDKs.

Building with the SDK

If you do not already have the AIR SDK, download it here.

You’ll need to compile your AIR/Flash swf with KongregateAPI.swc to have access to the java portion of the API. Make sure you update the paths and project names to match your project. Be sure to set external-library-path or library-path to the path where KongregateAPI.swc is located.

# For AIR
amxmlc -swf-version=20 -external-library-path+=/path/to/KongregateAPI.swc -output=MyProject.swf MyProject.mxml
# For Flash
mxmlc -swf-version=20 -library-path+=/path/to/KongregateAPI.swc -output=build/MyProjectWeb.swf MyProject.mxml

Android

Note: You need to set extdir to the path to where the .ane file and other external dependencies are located.

# Remove `air.` prefix from the package name
export AIR_NOANDROIDFLAIR=true
# Build APK with adt
adt -package -target apk-debug -storetype JKS -keystore ~/.android/debug.keystore \
    -storepass MY_PASSWORD build/MyProject.apk application.xml \
    MyProject.swf Default*.png ./assets/icon*.png \
    -extdir ../dependencies

iOS

Note: you’ll need to make sure to not only include the extdir, but also the path to the KongregateSDK.bundle and Swrve.bundle dependencies.

# Copy the bundles into a local directory
cp -r $KONGREGATE_SDK_PATH/ios/KongregateSDK.bundle build
cp -r $KONGREGATE_SDK_PATH/ios/Swrve.bundle build
# Build the IPA with adt
adt -package -target ipa-debug -provisioning-profile development.mobileprovision \
    -storetype PKCS12 -keystore private_key.p12 $IOS_KEYSTORE_ARGS \
    build/MyProject.ipa application.xml \
    MyProject.swf Default*.png ./assets/icon*.png \
    -C build KongregateSDK.bundle Swrve.bundle \
    -extdir ../dependencies

Web

To build a web version of your game, you can use a command like so:

mxmlc -swf-version=20 -library-path+=/path/to/KongregateAPI.swc -output=build/MyProjectWeb.swf MyProject.mxml

The AIR SDK will automatically load and initialize the Kongregate AS3 API. If you need to access AS3 API functionality that is not wrapped by this AIR SDK, then you can use the the web Kongregate API object once the READY event has been fired.

If you are hosting your game externally and wish to utilize analytics tracking, see this documentation.

Using the SDK

Initialization

Initialize the SDK as soon as possible after you app starts. See the AIR API Documentation for full documentation on the available settings.

// Modify the settings in the static `KongregateAPI.settings` object prior to initializing our SDK.
// Your producer will provide you with the correct values.
// Be sure to use the correct values for Android and iOS builds as well as Sanbox and Release
// Candidate builds.

// Swrve settings
KongregateAPI.settings.swrveAppId = KongregateConstants.swrveAppId;
KongregateAPI.settings.swrveApiKey = KongregateConstants.swrveApiKey;

// Adjust settings
KongregateAPI.settings.adjustEnvironment = "sandbox";  // change to production for release candidates
KongregateAPI.settings.adjustAppToken = "abcdef123456";
KongregateAPI.settings.adjustEventTokenMap = {
  "install": "abc123",
  "sale": "def456",
  "session": "hij789"
};

var mKongregate:KongregateAPI = KongregateAPI.initialize(
  root.stage,
  KongregateConstants.gameId,
  KongregateConstants.gameApiKey
);

IMPORTANT: Adjust and Swrve require different tokens/keys/ids for Android and iOS. Make sure they are set properly for your build. Swrve also has different IDs/Keys for Sandbox and Production mode, and Adjust has an environment setting that must be set for Sandbox Production.

Event Callbacks

You should set a callback listener for processing Kongregate events.

mKongregate.addEventListener(KongregateAPI.API_EVENT, function(e:APIEvent):void {
  switch(e.name) {
    case KongregateAPI.KONGREGATE_EVENT_READY:
      trace("Kongregate API ready!");
      mKongButton.visible = true;
      break;
    case KongregateAPI.KONGREGATE_EVENT_GAME_AUTH_CHANGED:
      updateUserInfo();
      break;
  }
});

User info & Services

You may access various information about the user.

var username:String = mKongregate.services.getUsername();

Statistics, Scores & Achievements

You may submit statistics through the client, if you game supports Kongregate Achievements. This may also be done server-to-server using our REST API.

mKongregate.stats.submit("HighScore", 1);

Mobile control & button

Call openKongregateWindow to open the mobile panel when the K button is clicked.

public function onKongregateButtonClicked(e:Event):void {
  if (mKongregate.platform == PlatformType.WEB) {
    trace("You cannot open the panel on web!");
    return;
  }
  mKongregate.mobile.openKongregateWindow();
}

Analytics

Primarily acts as a passthrough for Swrve and Adjust. See General Analytics Documentation for details on how to use the API and AIR API Documentation for ActionScript specifics.

// Get values and resources
var osVersion:String = mKongregate.analytics.getAutoProperties()[Analytics.FIELD_CLIENT_OS_VERSION];
var userId:String = mKongregate.analytics.getAutoProperties()[Analytics.FIELD_KONG_USER_ID];
var abTest:String = mKongregate.analytics.getResourceAsString(
  "com.kongregate.mobile.games.myGame.t05_coins", "test_attribute", "DEFAULT"
);

// Update user
mKongregate.analytics.gameUserUpdate({ "user_prop_1": "one" });

// Add an event
mKongregate.analytics.addEvent("swrve.test", { "some_key": "some_vlue" });

// Finish a promo
mKongregate.analytics.finishPromoAward("my_promo");

// Start a purchase
mKongregate.analytics.startPurchase("com.kongregate.mobile.yourgame.t05_hard", 1, {
    "type": "Gold Pack",
    "discount_percent": 12.5,
    "context_of_offer": "StoreFront"
  });

// Finish a purchase
if (mKongregate.platform == PlatformType.IOS) {
  mKongregate.analytics.finishPurchase(
    KongregateAPI.PURCHASE_SUCCESS,
    transactionId,
    gameFields
  );
} else if (mKongregate.platform == PlatformType.ANDROID) {
  mKongregate.analytics.finishPurchase(
    KongregateAPI.PURCHASE_SUCCESS,
    orderJson,
    gameFields,
    signature);
}

Mtx

Get user items and verify transactions.

// Listen for Items and request item list
mKongregate.addEventListener(KongregateAPI.API_EVENT, function(e:APIEvent):void {
  switch(e.name) {
    case KongregateAPI.KONGREGATE_EVENT_USER_INVENTORY:
      trace("Has sword: " + mKongregate.mtx.hasItem("sword"));
      break;
  }
});
mKongregate.mtx.requestUserItemList();

// Receipt verification
mKongregate.addEventListener(KongregateAPI.API_EVENT, function(e:APIEvent):void {
  switch(e.name) {
    case KongregateAPI.KONGREGATE_EVENT_RECEIPT_VERIFICATION_COMPLETE:
      trace("Received KONGREGATE_EVENT_RECEIPT_VERIFICATION_COMPLETE event");
      break;
  }
});
mKongregate.mtx.receiptVerificationStatus(txnId);

if (mKongregate.platform == PlatformType.IOS) {
  mKongregate.mtx.verifyTransactionId(txnId);
}

if (mKongregate.platform == PlatformType.ANDROID) {
  mKongregate.mtx.verifyGoogleReceipt(receipt, signature);
}

Sample Android Manifest Additions

Below is a sample of what your Android manifestAdditions tag might look like with the required additions for the Kongregate, Swrve and Adjust SDKs. You will need to update [YourGameName] and [YourPackageName] with values for your game.

Note: this does not include additions required for Push Notifications/Google Cloud Messaging. See Push Notifications Docs for more details on those APIs.

<android>
  <manifestAdditions>
    <![CDATA[
    <manifest android:installLocation="auto">
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
      <permission android:name="com.kongregate.permission.ReadSharedData2" android:protectionLevel="signature"/>
      <uses-permission android:name="com.kongregate.permission.ReadSharedData2"/>
      <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
      <application android:enabled="true">
        <activity
          android:name="com.kongregate.android.api.activities.KongregatePanelActivity"
          android:launchMode="singleTop"
          android:label="Kongregate"
          android:hardwareAccelerated="true"
          android:screenOrientation="sensorLandscape"
          android:configChanges="mcc|mnc|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize">
         </activity>
         <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
         <provider android:name="com.kongregate.android.api.providers.[YourGameName]SharedSecretProvider"
            android:authorities="com.kongregate.android.api.providers.[YourGameName]SharedSecretProvider"
            android:multiprocess="true"
            android:readPermission="com.kongregate.permission.ReadSharedData2"
            android:exported="true">
          </provider>
          <receiver android:name="com.kongregate.android.api.receivers.InstallReceiver" android:exported="true">
            <intent-filter>
              <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
            <meta-data
              android:name="foreward.adjust"
              android:value="com.adjust.sdk.AdjustReferrerReceiver"/>
            <meta-data
              android:name="foreward.swrve"
              android:value="com.swrve.sdk.SwrveInstallReferrerReceiver" />
          </receiver>
          <receiver android:name="com.kongregate.android.api.swrve.KongSwrvePushEngageReceiver"
            android:exported="true" />
          <service
            android:name="com.swrve.sdk.SwrveWakefulService"
            android:exported="false" />
          <activity
            android:name="com.swrve.sdk.messaging.ui.SwrveInAppMessageActivity"
            android:launchMode="singleTask"
            android:theme="@style/Theme.InAppMessage" >
          </activity>
          <receiver android:exported="false" android:name="com.swrve.sdk.SwrveWakefulReceiver">
              <intent-filter>
                  <action android:name="[YourPackageName].swrve.SwrveWakeful" />
              </intent-filter>
          </receiver>
      </application>
    </manifest>
  ]]>
  </manifestAdditions>
</android>

AIR API Docs

AIR API Documentation