Skip to main content

Event Tracking

GameAnalytics features the following event types:

EventDescription
AdAds shown and clicked, fill rate.
BusinessIn-App Purchases supporting receipt validation on GA servers.
DesignSubmit custom event id’s. Useful for tracking metrics specifically needed for your game.
ErrorSubmit exception stack traces or custom error messages.
HealthAutomatically submits health metrics related to your game such as FPS.
ImpressionImpression data from different ad networks
ProgressionLevel attempts with Start, Fail & Complete event.
ResourceManaging the flow of virtual currencies - like gems or lives
tip

Read more about events here

Event ids are strings separated by colons defining an event hierarchy – like “kill:robot:large”.

danger

A bad implementation example. [level_name]:[weapon_used]:[damage_done] level_name could be 100 values, weapon_used could be 300 values and damage_done could be 1-5000 perhaps. This will generate an event hierarchy with: 100 * 300 * 5000 = 150M possible nodes. This is far too many. Also the damage should be put as a value and not in the event string. The processing will perhaps be blocked for a game doing this and cause other problems when browsing our tool. The maximum amount of unique nodes generated should be around 10k.

It is important to not generate an excessive amount of unique nodes possible in the event hierarchy tree.

Business

Business events are used to track (and validate) real-money transactions.

Many games are hacked and distributed illegally. Hacking an app will often involve faking/simulating all purchase requests. This will result in several Business events being sent to GameAnalytics for transactions that never occurred.

GameAnalytics provide the option of receipt validation for each purchase sent to GA servers. This process can ensure that revenue metrics reflect the actual spending in your game.

Some configuration is needed before receipt validation will be active.

tip

Read information about validation and requirements for different platforms here.

Getting receipts in Cocos2D

To get receipts from In-App purchases in Android and iOS please look this integration guide and especially look here as you need the IAP receipts to send with your business events. Android

Android Receipt

When submitting a Business Event supply the following from the IAP procedure:

  • receipt (INAPP_PURCHASE_DATA)
  • signature (INAPP_DATA_SIGNATURE)
tip

Read more about retrieving these needed fields at the Google documentation here.

Add a business event when an in-app purchase is completed (Google Play Store only supported at the moment).

// C++
gameanalytics::cocos2d::GameAnalytics::addBusinessEvent("USD", 1000, "item", "id", "cart", "[receipt]", "[signature]");
FieldTypeDescriptionExample
currencystringCurrency code in ISO 4217 format.USD
amountintegerAmount in cents.99 is 0.99$
itemTypestringThe type / category of the item.GoldPacks
itemIdstringSpecific item bought.1000GoldPack
cartTypestringThe game location of the purchase. Max 10 unique values.EndOfLevel
receiptbase64 stringThe transaction receipt. Null allowed.null
signaturebase64 stringThe transaction receipt signature. Null allowed.null
caution

If the receipt/signature is null (or is an invalid receipt) then it will be submitted to the GA server but will register as not validated.

Android receipt schema

{
"orderId": "<order_id>",
"packageName": "<package_name>",
"productId": "<product_id>",
"purchaseTime": 1484080095335,
"purchaseState": 0,
"purchaseToken": "<purchase_token>"
}
info

The encoding of the receipt will be done by the GameAnalytics native Android library.

iOS receipt

Add this event when the in-app purchase has been completed

// C++
gameanalytics::cocos2d::GameAnalytics::addBusinessEvent("USD", 1000, "item", "id", "cart", "[receipt]");
FieldTypeDescriptionExample
currencystringCurrency code in ISO 4217 format.USD
amountintegerAmount in cents.99 is 0.99$
itemTypestringThe type / category of the item.GoldPacks
itemIdstringSpecific item bought.1000GoldPack
cartTypestringThe game location of the purchase. Max 10 unique values.EndOfLevel
receiptbase64 stringThe transaction receipt. Null allowed.null
caution

If the receipt is null (or is an invalid receipt) then the GA servers will register that amount as not validated. Business event with auto fetch receipt (iOS7+)

Using an alternative method it is possible to let the SDK retrieve the receipt automatically when called directly after a successful in-app purchase. The code performed by the SDK is identical (almost) to the objective-c example above for iOS7+.

Using this method on iOS6.x devices will cause the business event to be ignored. When supporting iOS6 you should retrieve and specify receipt manually.

// C++
gameanalytics::cocos2d::GameAnalytics::addBusinessEventAndAutoFetchReceipt("USD", 999, "Weapon", "SwordOfFire", "Menu");

Using SDKBOX IAP (Android and iOS)

It is assumed that you have already set up and configured SDKBOX IAP correctly, if not please go here for more information on how to do this.

Make sure you have called these methods before making In-App purchases (where iapListener implements public sdkbox::IAPListener):

sdkbox::IAP::enableUserSideVerification(true);
sdkbox::IAP::setListener(iapListener);

Here is how to get receipts and to use to send business events so they get marked as valid events:

void MyIAPListenerClass::onSuccess(sdkbox::Product const& p)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
gameanalytics::cocos2d::GameAnalytics::addBusinessEvent("USD", 1000, "item", "id", "cart", p.receipt.c_str(), p.receiptCipheredPayload.c_str());
#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS
gameanalytics::cocos2d::GameAnalytics::addBusinessEvent("USD", 1000, "item", "id", "cart", p.receiptCipheredPayload.c_str());
#endif
}

The Android receiptCipheredPayload contains the signature needed for the business events and iOS receiptCipheredPayload is the receipt.

tip

For more information on Business Events go here.

Ad Events

The GameAnalytics ad event needs to be called when certain events happen for the implemented ad sdk’s. An ad sdk has callback methods activating code when certain things are activated (like ad show or ad clicked).

To use the ad event it is need to call the GameAnalytics SDK when these delegates are called.

Rewarded Videos

Showing a rewarded video

If a rewarded video has failed to be shown due to some reason, you can track this by using the following method:

if (rewardedVideoAd != null && rewardedVideoAd.isLoaded())
{
// ...show ad
}
else
{
gameanalytics::cocos2d::GameAnalytics::addAdEvent(gameanalytics::cocos2d::EGAAdAction::FailedShow,
gameanalytics::cocos2d::EGAAdType::RewardedVideo,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

Tracking rewards

Once the player has finished watching the video, you can use the following method to register that the reward has been received:

void onRewarded(reward) {
// send ad event - reward recieved
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::RewardReceived,
gameanalytics::cocos2d::EGAAdType::RewardedVideo,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

And subsequently track that the rewarded ad has been closed:

void onRewardedVideoAdClosed() {
if(currentRewardedVideoPlacement != null)
{
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::Show,
gameanalytics::cocos2d::EGAAdType::RewardedVideo,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}
}

Interstitials

Showing an Interstitial Ad

If the ad has failed to load or be shown due to some reason, it is recommended to track it using the following method:

if (interstitialAd != null && interstitialAd.isLoaded()) {
interstitialAd.show();
}
else
{
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::FailedShow,
gameanalytics::cocos2d::EGAAdType::Interstitial,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

If the interstitial has been showed succesfully it can be tracked by using the next method:

void onAdOpened() {
// send ad event
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
adAction: GameAnalytics.EGAAdAction.Show,
gameanalytics::cocos2d::EGAAdType::Interstitial,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

Tracking Interstitial Clicks

You can track if an user has clicked an interstitial ad and has subsequently left the application to visit the advertiser's site with the following method:

void onAdLeftApplication() {
// send ad event
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::Clicked,
gameanalytics::cocos2d::EGAAdType::Interstitial,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

In similiar fashion to rewarded video ads & interstitial ads, you can track if the ad has been shown succesfully or not. The example below will show how you could track this:

void onAdLoaded() {
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::Show,
gameanalytics::cocos2d::EGAAdType::Banner,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
});
}

And if the banner has failed to load:

void onAdFailedToLoad(int errorCode) {
// OR .. if you don't want to track errors
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::FailedShow,
gameanalytics::cocos2d::EGAAdType::Banner,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}

Track banner clicks

You can track if an user has clicked a banner ad by sending a GAAdAction.Clicked event as shown below:

void onAdOpened() {
// send ad event
gameanalytics::cocos2d::GameAnalytics::addAdEvent(
gameanalytics::cocos2d::EGAAdAction::Clicked,
gameanalytics::cocos2d::EGAAdType::Banner,
"admob",
"[AD_PLACEMENT_OR_UNIT_ID]"
);
}
FieldTypeDescriptionExample
adActionenumA defined enum for ad action (for example clicked).GAAdAction.Clicked
GAAdAction.Show
GAAdAction.FailedShow
GAAdAction.RewardReceived
adTypeenumA defined enum for ad type (for example interstitial).GAAdType.Video
GAAdType.RewardedVideo
GAAdType.Playable
GAAdType.Interstitial
GAAdType.OfferWall
GAAdType.Banner
adSdkNamestringName of the Ad/Ad mediation SDK.admob
adPlacementstringIdentifier of ad in the game or the placement of it.level_complete_ad
adPlacementstringIdentifier of ad in the game or the placement of it.level_complete_ad
durationintOptional. Only used for video ads to track how long the user watched the video for.10
noAdReasonenumOptional. Used to track the reason for not being able to show an ad when needed (for example no fill).GAAdError.Unknown
GAAdError.Offline
GAAdError.NoFill
GAAdError.InternalError
GAAdError.InvalidRequest
GAAdError.UnableToPrecache
tip

For more information on Ad Events go here

Resource Events

Resource events are used to register the flow of your in-game economy (virtual currencies) – the sink (subtract) and the source (add) for each virtual currency.

caution

Before calling the resource event it is needed to specify what discrete values can be used for currencies and item types in the Configuration phase.

// C++
gameanalytics::cocos2d::GameAnalytics::addResourceEvent(gameanalytics::cocos2d::EGAResourceFlowType::Source, "Gems", 400, "IAP", "Coins400");

Source (add)

Source (add) gem currency from an in-app purchase.

// C++
gameanalytics::cocos2d::GameAnalytics::addResourceEvent(gameanalytics::cocos2d::EGAResourceFlowType::Source, "Gems", 400, "IAP", "Coins400");

Sink (subtract)

Sink (subtract) gem currency to source (buy) some amount of another virtual currency.

// C++
gameanalytics::cocos2d::GameAnalytics::addResourceEvent(gameanalytics::cocos2d::EGAResourceFlowType::Sink, "Gems", 100, "Boosters", "BeamBooster5Pack");

gameanalytics::cocos2d::GameAnalytics::addResourceEvent(gameanalytics::cocos2d::EGAResourceFlowType::Source, "BeamBooster", 5, "Gems", "BeamBooster5Pack");

Sink (subtract) 3 BeamBooster currency that were used during a level.

// C++
gameanalytics::cocos2d::GameAnalytics::addResourceEvent(gameanalytics::cocos2d::EGAResourceFlowType::Source, "Gems", 400, "IAP", "Coins400");
FieldTypeRequiredDescription
flowTypeenumyesAdd (source) or subtract (sink) resource.
currencystringyesOne of the available currencies set in GA_Settings (Setup tab).This string can only contain [A-Za-z] characters.
amountfloatyesAmount sourced or sunk.
itemTypestringyesOne of the available item types set in GA_Settings (Setup tab).
itemIdstringyesItem id (string max length = 32)

danger

Be careful to not call the resource event too often! In a game where the user collect coins fairly fast you should not call a Source event on each pickup. Instead you should count the coins and send a single Source event when the user either complete or fail the level.


tip

For more information on Ad Events go here

Progression Events

Progression events are used to track attempts at completing some part of a game (level, area). A defined area follow a 3 tier hierarchy structure (could be world:stage:level) to indicate what part of the game the player is trying to complete.

When a player is starting a progression attempt a start event should be added.

When the player then finishes the attempt a fail or complete event should be added along with a score if needed.

Add a progression start event.

GameAnalytics.addProgressionEventWithProgressionStatus(GAProgressionStatus.Start, "world01", "stage01", "level01");

It is not required to use all 3 if your game does not have them:

  • progression01
  • progression01 and progression02
  • progression01 and progression02 and progression03
// C++
gameanalytics::cocos2d::GameAnalytics::addProgressionEvent(gameanalytics::cocos2d::EGAProgressionStatus::Start, "world01", "stage01", "level01");

FieldTypeRequiredDescription
progressionStatusenumyesStatus of added progression (start, complete, fail).
progression01stringyes1st progression (e.g. world01).
progression02stringno2nd progression (e.g. level01).
progression03stringno3rd progression (e.g. phase01).
scoreintnoThe player’s score.
tip

For more information on Progression Events go here

Error Events

Error events are used to track errors in the game code. You can group the events by severity level and attach a message.

To add a custom error event call the following function:

// C++
gameanalytics::cocos2d::GameAnalytics::addErrorEvent(gameanalytics::cocos2d::EGAErrorSeverity::Debug, "Something went bad in some of the smelly code!");
FieldTypeDescriptionExample
severityenumSeverity of errorgameanalytics::cocos2d::EGAErrorSeverity::Debug
gameanalytics::cocos2d::EGAErrorSeverity::Info
gameanalytics::cocos2d::EGAErrorSeverity::Warning
gameanalytics::cocos2d::EGAErrorSeverity::Error
gameanalytics::cocos2d::EGAErrorSeverity::Critical
messagestringError message (can be null)“Error when entering level12”
tip

For more information on Error Events go here

Design Events

Every game is special. Therefore some tracking needs might not be covered by our other event types. The design event is available for you to add your own event-id hierarchy.

Please note that custom dimensions and progression filters will not be added on design and error events. Therefore you cannot (at the moment) filter by these when viewing design or error metrics.

// C++
gameanalytics::cocos2d::GameAnalytics::addDesignEvent("Kill:Sword:Robot");

It is also possible to add a custom float value to the event. This will (in addition to count) make the mean and sum aggregation available in the tool.

// C++
gameanalytics::cocos2d::GameAnalytics::addDesignEvent("Kill:Sword:Robot", 2.5);
FieldTypeDescriptionExample
eventIdstringThe eventId is a hierarchy string that can consist of 1-5 segments separated by ‘:’. Each segment can have a max length of 32.“StartGame:ClassLevel1_5”, “StartGame:ClassLevel6_10
valuefloatA float event tied to the eventId. Will result in sum & mean values being available.34.5
danger

It is important to not generate an excessive amount of unique nodes possible in the event hierarchy tree.

A bad implementation example: [level_name]:[weapon_used]:[damage_done], level_name could be 100 values, weapon_used could be 300 values and damage_done could be 1-5000 perhaps. This will generate an event hierarchy with: 100 * 300 * 5000 = 1.5M possible nodes.

This is far too many. Also the damage should be put as a value and not in the event string. The processing will perhaps be blocked for a game doing this and cause other problems when browsing our tool.

The maximum amount of unique nodes generated should be around 10k.

tip

For more information on Design Events go here