Event Tracking
GameAnalytics features the following event types:
Event | Description |
---|---|
Ad | Ads shown and clicked, fill rate. |
Business | In-App Purchases supporting receipt validation on GA servers. |
Design | Submit custom event id’s. Useful for tracking metrics specifically needed for your game. |
Error | Submit exception stack traces or custom error messages. |
Health | Automatically submits health metrics related to your game such as FPS. |
Impression | Impression data from different ad networks |
Progression | Level attempts with Start, Fail & Complete event. |
Resource | Managing the flow of virtual currencies - like gems or lives |
Read more about events here
Event ids are strings separated by colons defining an event hierarchy – like “kill:robot:large”
.
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.
Read information about validation and requirements for different platforms here.
Getting receipts
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
)
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).
var devicePlatform = device.platform;
if (devicePlatform === "Android") {
// Android - Google Play
GameAnalytics.addBusinessEvent({
currency: "USD",
amount: 100,
itemType: "boost",
itemId: "megaBoost",
cartType: "shop",
receipt: "",
signature: "",
});
}
if (devicePlatform === "iOS") {
// iOS - with receipt
GameAnalytics.addBusinessEvent({
currency: "USD",
amount: 100,
itemType: "boost",
itemId: "megaBoost",
cartType: "shop",
receipt: "",
});
// iOS - with autoFetchReceipt
GameAnalytics.addBusinessEvent({
currency: "USD",
amount: 100,
itemType: "boost",
itemId: "megaBoost",
cartType: "shop",
autoFetchReceipt: true,
});
}
Field | Type | Description | Example |
---|---|---|---|
currency | string | Currency code in ISO 4217 format. | USD |
amount | integer | Amount in cents. | 99 is 0.99$ |
itemType | string | The type / category of the item. | GoldPacks |
itemId | string | Specific item bought. | 1000GoldPack |
cartType | string | The game location of the purchase. Max 10 unique values. | EndOfLevel |
receipt | base64 string | The transaction receipt. Null allowed. | null |
signature | base64 string | The transaction receipt signature. Null allowed. | null |
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.
The encoding of the receipt will be done by the GameAnalytics native Android library.
iOS receipt
Field | Type | Description | Example |
---|---|---|---|
currency | string | Currency code in ISO 4217 format. | USD |
amount | integer | Amount in cents. | 99 is 0.99$ |
itemType | string | The type / category of the item. | GoldPacks |
itemId | string | Specific item bought. | 1000GoldPack |
cartType | string | The game location of the purchase. Max 10 unique values. | EndOfLevel |
receipt | base64 string | The transaction receipt. Null allowed. | null |
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.
// iOS - with autoFetchReceipt
GameAnalytics.addBusinessEvent({
currency: "USD",
amount: 100,
itemType: "boost",
itemId: "megaBoost",
cartType: "shop",
autoFetchReceipt: true,
});
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.
For more information on Business Events go here.
Custom Event Fields
It is possible to use a set of key-value pairs to add extra fields but it will only be available through raw data export. Here is an example of how to use it:
var fields = {
test: 100,
test_2: "hello_world",
};
GameAnalytics.addBusinessEvent({
currency: "USD",
amount: 100,
itemType: "boost",
itemId: "megaBoost",
cartType: "shop",
autoFetchReceipt: true,
customFields: JSON.stringify(fields),
});
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.addAdEvent({
adAction: GameAnalytics.EGAAdAction.FailedShow,
adType: GameAnalytics.EGAAdType.RewardedVideo,
adSdkName: "admob",
adPlacement: "[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:
function onRewarded(reward) {
// send ad event - reward recieved
GameAnalytics.addAdEvent({
adAction: GameAnalytics.EGAAdAction.RewardReceived,
adType: GameAnalytics.EGAAdType.RewardedVideo,
adSdkName: "admob",
adPlacement: "[AD_PLACEMENT_OR_UNIT_ID]",
});
}
And subsequently track that the rewarded ad has been closed:
function onRewardedVideoCompleted() {
if (that.get().currentRewardedVideoPlacement != null) {
GameAnalytics.addAdEvent({
adAction: GameAnalytics.EGAAdAction.Show,
adType: GameAnalytics.EGAAdType.RewardedVideo,
adSdkName: "admob",
adPlacement: "[AD_PLACEMENT_OR_UNIT_ID]",
});
}
}