Tracking Events
Tracking Custom In-App Actions
The steps below provide instructions for tracking in-game events. FIRST_RUN
, OPEN
and TIME_SPENT
events are tracked automatically.
To track in-game actions add the following line:
- Android (Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().trackAction("YOUR_CUSTOM_EVENT_NAME", data);
#import "WappierSDK.h"
[WappierSDK trackInAppAction:@"YOUR_CUSTOM_EVENT_NAME" withData:data];
data should be a NSJSONSerializable object
Wappier.Instance.TrackAction("YOUR_CUSTOM_EVENT_NAME", data);
WappierSDKWrapper::getInstance()->trackAction("YOUR_CUSTOM_EVENT_NAME", data);
where data is an std::map <const char*, const char*>
YOUR_CUSTOM_EVENT_NAME can have any custom value including the following special characters:
*0-9, A-Z, a-z, # $ % = @ ! { } ( ) [ ] < > ` ~ & ? . : ; _ | ^ + –*
You can pass any Object in the second parameter of trackAction (e.g., List, HashMap<String,Any>, etc.).These actions are directly correlated with the gameplay style of each game and they are the main source of points for the user. Here you may find some common examples of tracked actions:
Event Name | Occurence | Tracked when | Data |
---|---|---|---|
LEVEL_COMPLETED | Repetitive | The user completes a level or stage in the game | levelNumber:3 |
BATTLE_WON | Repetitive | Win a match versus A.I. | |
HERO_LVL_UP | Repetitive | The hero leveled up. Extra Data: the exact level number and the number of win in pvp battles | characterLevel:7 ,pvpWins:35 |
Tracking Purchase Events
The PURCHASE
event is sent every time a user purchases one of your application’s in-app items.
In order to track in-app purchases performed in your game, add the following line:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().trackPurchase(
revenue,
"currencyCode",
"googleOrderId",
"productId",
"purchaseToken",
"purchaseType",
data
);
[WappierSDK trackPurchaseWithRevenue:revenue
currency:@"currencyCode"
transactionId:@"transactionId"
productId:@"productId"
receiptData:@"receiptData"
purchaseType:@"purchaseType"
data:data];
Wappier.Instance.TrackPurchase(
revenue,
"currencyCode",
"(Android)googleOrderId / (iOS)transactionId",
"productId",
"(Android)purchaseToken / (iOS)receiptData",
"purchaseTypeId",
data
);
WappierSDKWrapper::getInstance()->trackPurchase(
revenue,
"currencyCode",
"transactionId",
"productId",
"receiptData",
"purchaseType",
data
);
The following code snippet suggests a way to track a purchase event:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
if (purchase.getSku().equals(..SKU id..)) {
HashMap<String, String> data = new HashMap<>();
data.put("key1", "value1");
data.put("key2", "value2");
Wappier.getInstance().trackPurchase(
1.80,
"EUR",
purchase.getOrderId(),
purchase.getSku(),
purchase.getToken(),
purchase.getType(),
data
);
}
};
// Callback for when a purchase is finished
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self trackPurchase:transaction];
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
};
}
- (void)trackPurchase:(SKPaymentTransaction *)transaction {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
NSString *receipt_data = [receipt base64EncodedStringWithOptions:0];
NSDictionary *data = @{
@"key1" : @"value1",
@"key2" : @"value2"
};
[WappierSDK trackPurchaseWithRevenue:1.99
currency:@"EUR"
transactionId:transaction.transactionIdentifier
productId:@"com.wappier.2048.diamonds"
receiptData:receipt_data
data:data];
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier);
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("dataKey", "dataValue")
try
{
var result = validator.Validate(e.purchasedProduct.receipt);
if (Application.platform == RuntimePlatform.Android)
{
Wappier.Instance.TrackPurchase(
1.99,
"EUR",
productReceipt.transactionID,
productReceipt.productID,
"receipt",
"type”,
data);
}
}
else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
foreach (IPurchaseReceipt productReceipt in result)
{
Wappier.Instance.TrackPurchase(
1.99,
"EUR",
productReceipt.transactionID,
productReceipt.productID,
"receipt",
"type”,
data);
}
}
}
}
#endif
return PurchaseProcessingResult.Complete;
}
const char* dataKey = "key1"
const char* dataValue = "value1"
map<const char*, const char*> data = {
{ dataKey, dataValue }
};
WappierSDKWrapper::getInstance()->trackPurchase(
revenue,
"currencyCode",
"transactionId",
"productId",
"receiptData",
"purchaseType",
data
);
Alternatively, if the current user is in a pricing target group and the product id argument is a proxy SKU, then you can instead use this function to report to wappier’s SDK the related original SKU:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().trackPurchase(
revenue,
"currencyCode",
"googleOrderId",
"productId",
"purchaseToken",
"purchaseType",
"originalSku",
data
);
[WappierSDK trackPurchaseWithRevenue:revenue
currency:@"currencyCode"
transactionId:@"transactionId"
productId:@"productId"
originalProductId:@"originalProductId"
receiptData:@"receiptData"
purchaseType:@"purchaseType"
data:data];
Wappier.Instance.TrackPurchase(
revenue,
"currencyCode",
"(Android)googleOrderId / (iOS)transactionId",
"productId",
"(Android)purchaseToken / (iOS)receiptData",
"purchaseTypeId",
"originalId",
data
);
WappierSDKWrapper::getInstance()->trackPurchase(
revenue,
"currencyCode",
"transactionId",
"productId",
"originalProductId",
"receiptData",
"purchaseType",
data
);
An optional map of extra data can be passed in the above methods in argument data.
Mandatory Fields
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Value | Type | Description | Example |
---|---|---|---|
revenue | Double | Total numeric amount for the purchase | 19.99 |
currencyCode | String | The local currency code of the transaction | USD |
googleOrderId | String | The GPA-formatted order ID of the transaction | GPA-1234.1234.1234.12345 |
productId | String | The product identifier, which is defined on your Google Developer Console | com.xxxx.yyyy.gems |
purchaseToken | String | A token that uniquely identifies a purchase for a given item and user pair | This alphanumeric string is 150-200 characters long |
purchaseType | String | A virtual good type that allows us to further differentiate the types of items that users buy from your game | Gems |
Value | Type | Description | Example |
---|---|---|---|
revenue | Double | Total numeric amount for the purchase | 19.99 |
currencyCode | Char | The local currency code of the transaction | USD |
transactionId | Char | The 15-digit transaction identifier of the transaction | 100100172639019 |
productId | Char | The product identifier, which is defined on your iTunesConnect dashboard | com.xxxx.yyyy.gems |
receiptData | Char | The receipt saved in user’s device after making an in-app purchase | This alphanumeric string is 150-200 characters long |
data | HashMap<Any,Any> | (Optional) pass information to the request | Gems |
Value | Type | Description | Example |
---|---|---|---|
revenue | Double | Total numeric amount for the purchase | 19.99 |
currencyCode | String | The local currency code of the transaction | USD |
transactionId (for Android transactions) | Char | The GPA-formatted order ID of the transaction | GPA-1234.1234.1234.12345 |
transactionId (for iOS transactions) | Char | The 15-digit transaction identifier of the transaction | 100100172639019 |
productId | Char | The product identifier of the in app product | com.xxxx.yyyy.gems |
receiptData (for Android transactions) | Char | A token that uniquely identifies a purchase for a given item and user pair | This alphanumeric string is 150-200 characters long |
purchaseToken (Android only) | String | A token that uniquely identifies a purchase for a given item and user pair | This alphanumeric string is 3000+ characters long |
receipt (iOS only) | String | The receipt saved in user’s device after making an in-app purchase | This alphanumeric string is 3000+ characters long |
data | Dictionary | (Optional) Variable to allow user pass information to the request |
Value | Type | Description | Example |
---|---|---|---|
revenue | Double | Total numeric amount for the purchase | 19.99 |
currencyCode | Char | The local currency code of the transaction | USD |
transactionId (for Android transactions) | Char | The GPA-formatted order ID of the transaction | GPA-1234.1234.1234.12345 |
transactionId (for iOS transactions) | Char | The 15-digit transaction identifier of the transaction | 100100172639019 |
productId | Char | The product identifier of the in app product | com.xxxx.yyyy.gems |
receiptData (for Android transactions) | Char | A token that uniquely identifies a purchase for a given item and user pair | This alphanumeric string is 150-200 characters long |
receiptData (for iOS transactions) | Char | The receipt saved in user’s device after making an in-app purchase | This alphanumeric string is 3000+ characters long |
purchaseType | Char | A virtual good type that allows us to further differentiate the types of items that users buy from your game | Gems |
data | HashMap<Char, Char> | (Optional) Variable to allow user pass information to the request |
Tracking Store Impression
The wappier optimization SDK provides custom methods to track the behavior of users in an in-game store.
When the user enters the app’s store view, you can call trackStoreImpression
by providing the store name and a list of your products:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
final List<StoreItem> storeItemList = new ArrayList<>();
for (SkuDetails skuDetails : list) {
StoreItem storeItem = new StoreItem.Builder()
.withSku(skuDetails.getSku())
.withCurrency(skuDetails.getPriceCurrencyCode())
.withPrice(10)
.withInitialPrice((double) skuDetails.getPriceAmountMicros() / 1000000)
.withPromo("Promo")
.build();
storeItemList.add(storeItem);
}
Wappier.getInstance().trackStoreImpression("Gem_Store", storeItemList);
XNStoreItem *item1 = [[XNStoreItem alloc] initWithSku:@"sku1"
currency:@"USD"
initialPrice:@(142)
price:@(145)
andPromoText:@""];
XNStoreItem *item2 = [[XNStoreItem alloc] initWithSku:@"sku3"
currency:@"USD"
initialPrice:@(142)
price:@(145)
andPromoText:@"MostPopular"];
XNStoreItem *item3 = [[XNStoreItem alloc] initWithSku:@"sku2"
currency:@"USD"
initialPrice:@(142)
price:@(145)
andPromoText:@"BestBuy"];
[WappierSDK trackStoreImpressionWithStoreName:@"GoldStore"
availableItems:@[item1, item2, item3]];
Wappier.Instance.TrackStoreImpression(storeName, storeItems);
WappierSDKWrapper::getInstance()->trackStoreImpression(storeName, storeItems);
StoreItem
is a WappierSDK builder that keeps the product's info from Google/Apple API.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
StoreItem storeItem = new StoreItem.Builder()
.withSku("PRODUCT_SKU")
.withCurrency("PRODUCT_CURRENCY"))
.withPrice(10)
.withInitialPrice(20)
.withPromo("MOST_POPULAR")
.build();
XNStoreItem *item1 = [[XNStoreItem alloc] initWithSku:@"sku1"
currency:@"USD"
initialPrice:@(142)
price:@(145)
andPromoText:@""];
XNStoreItem storeItem = new XNStoreItem()
.withSku("PRODUCT_SKU")
.withCurrency("PRODUCT_CURRENCY"))
.withPrice(10)
.withInitialPrice(20)
.withPromo("MOST_POPULAR");
WPStoreItem *storeItem = new WPStoreItem()
storeItem
->withCurrency("PRODUCT_CURRENCY")
->withInitialPrice(20)
->withPrice(10)
->withPromoText("MOST_POPULAR")
->withSku("PRODUCT_SKU");
XNStoreItem
is a WappierSDK class to describe Store Items:
Value | Description |
---|---|
sku | Current sku (already provided by Google Purchace API) |
currency | The currency of your product |
price | The actual price paid |
initialPrice | The initial pre-discount price in Micros |
PromoText | An optional promo text |
When the user exits from an in-game store you can call trackStoreExit
by providing the store name:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().trackStoreExit("store");
[WappierSDK trackStoreExitWithStoreName:@"GoldStore"];
Wappier.Instance().TrackStoreExit("store");
WappierSDKWrapper::getInstance()->trackStoreExit("store");
You are able to track the attempts of a user to purchase an in-app item by providing the current StoreItem
:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
StoreItem storeItem = new StoreItem.Builder()
.withSku("PRODUCT_SKU")
.withCurrency("PRODUCT_CURRENCY"))
.withPrice(10)
.withInitialPrice(20)
.withPromo("MOST_POPULAR")
.build();
Wappier.getInstance().trackPurchaseIntent(storeItem);
XNStoreItem *item = [[XNStoreItem alloc] initWithSku:sku
currency:@"USD"
initialPrice:@(142)
price:@(145)
andPromoText:@"BestBuy"];
[WappierSDK trackPurchaseIntentForItem:item];
XNStoreItem storeItem = new XNStoreItem
.withSku("PRODUCT_SKU")
.withCurrency("PRODUCT_CURRENCY"))
.withPrice(10)
.withInitialPrice(20)
.withPromo("MOST_POPULAR");
Wappier.Instance.TrackPurchaseIntent(storeItem);
WPStoreItem *storeItem = new WPStoreItem()
storeItem
->withCurrency("PRODUCT_CURRENCY")
->withInitialPrice(20)
->withPrice(10)
->withPromoText("MOST_POPULAR")
->withSku("PRODUCT_SKU");
WappierSDKWrapper::getInstance()->trackPurchaseIntent(storeItem);
Tracking Currency Balance
The wappier Optimization SDK provides a currency balance system to track the changes in a user’s economy:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().trackBalance("Gem", 10, 5000, "CHEST_OF_GOLD");
[WappierSDK trackBalanceWithType:@"gold"
amount:2
currentBalance:42
andReason:@"ExtraLife"];
Wappier.Instance.TrackBalance("Gem", 10, 5000, "CHEST_OF_GOLD");
WappierSDKWrapper::getInstance()->trackBalance("Gem", 10, 5000, "CHEST_OF_GOLD");
Value | Description |
---|---|
balanceType | The currency identifier (e.g., DIAMONDS , GOLD , etc.) |
amount | The amount of the balance change (can be positive or negative) |
currentBalance | The current total balance after the amount of change has been applied |
reason | The reason for which the amount of currency was modified |