1. Home
  2. Integrations
  3. Android Native Events Setup Guide
  4. Gaming Applications – Android

Gaming Applications – Android

We have provided a list of Events with their example usage that can be integrated for Gaming Applications. Please find them below:

1. Purchase Event

This is used to track the successful Purchase event in your Game.

You will need to call the below method of MTractionEventTracker Class to track the In-App Purchase event in your Application.

Public static void trackPurchase(Context context, Purchase purchase);
// Product List Array Definition
List productList = new ArrayList();

// Product Constructor Call
Product product1 = new Product(productIdentifier, productName, price, quantity);

  • Mandatory parameters (Product): 
    • Product Identifier – Unique Product Identifier
    • Product Name – Name of the Product
    • Price – Price of the Product
    • Quantity – Quantity of the Product being Purchased
  • Optional parameters (Product):
    • Brand – Brand Name of the Product
    • Product Discount – Discount applied for the Product
    • Category – Product Category
// Adding the product to the Product List
productList.add(product1);

// Purchase Constructor Call
Purchase purchase = new Purchase(userId, revenue, Purchase.PaymentMode.DEBIT_CARD, locale, transactionId, Purchase.Frequency.XXX, productList);

  • Mandatory parameters (Purchase): 
    • User Id – Unique User Identifier
    • Revenue – Total Revenue generated from this Purchase event
    • Purchase.PaymentMode.XXXXXX can take any of the predefined values for payment methods, [CREDIT_CARD or DEBIT_CARD or NET_BANKING or GIFT_CARD or PAYMENT_WALLET]
    • Locale – Currency code used for this purchase. We can get currency code information precisely in either of the following ways: 
      1. Default from device configuration:
        Locale locale = Locale.getDefault();

        Note: Recommended for more accuracy.

      2. Custom setting:
        Locale locale = new Locale("JA"/*Language Code*/, "JP" /*Country Code*/);

        Note: Click here to view the list of Country codes (ISO-3166) & Language codes (ISO-639).

    • Transaction Id – Unique Purchase Transaction Identifier
    • Purchase.Frequency.XXXXXX can take any of the predefined values for payment frequency, [ONCE or RECURRING] representing One Time Payment or Subscription based Payment respectively
    • Product List – Array of the list of products purchased
  • Optional parameters (Purchase):
    • Loyalty – Loyalty points applied on the Purchase
    • Overall Discount – Discount applied for the Purchase
    • Service Charge – Service Charge applied for the Purchase
    • Location – Geolocation of the Event

Sample Code

// Example Longitude & Latitude code (Long / Lat is optional)
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

// Product List Array Definition
List productList = new ArrayList();

// Example Product Constructor Call with the mandatory parameters
Product product1 = new Product(“12345”, “Gold Coins”, 5.99, 5);

// Examples for other parameters passed for the Product Class (These are optional)
product1.setBrand(“Game Credits - Coins”)
        .setCategory("Credits")
.setProductDiscount(5.00);

// Adding the product to the Product List
productList.add(product1);

// Example Purchase Constructor Call with the mandatory parameters
Purchase purchase= new Purchase(“123”, 24.65, Purchase.PaymentMode.DEBIT_CARD Locale.getDefault(), “1000123” , Purchase.Frequency.ONCE, productList);

// Examples for other parameters passed for the Purchase Class (These are optional)
purchase.setLoyalty(150.00)
.setOverallDiscount(5.00)
.setServiceCharge(4.99)
.setLocation(location.getLatitude(), location.getLongitude());

// trackPurchase method call
MTractionEventTracker.trackPurchase(this.getApplicationContext(), purchase);

2. Paid Subscription Deactivated Event

This is used to track when the Player has unsubscribed from any of the services of the Game.

You will need to call the below method of MTractionEventTracker Class to track the Subscription Deactivated event in your Application.

Public static void trackPaidSubscriptionDeactivated(Context context, PaidSubscriptionDeactivated pSubsDeactivate);
PaidSubscriptionDeactivated  pSubsDeactivate = new PaidSubscriptionDeactivated(userId);

  • Mandatory parameters (Paid Subscription Deactivated): 
    • User Id – Unique User Identifier
  • Optional parameters (Paid Subscription Deactivated): 
    • Page Name – Page that triggered the Event
    • Location – Geolocation of the Event

Sample Code

// Example Longitude & Latitude code (Long / Lat is optional)
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

// Example Constructor call with User ID (User ID is mandatory)
PaidSubscriptionDeactivated pSubsDeactivate = new PaidSubscriptionDeactivated(“123”);

// Examples for other parameters passed with the event (These are optional)
pSubsDeactivate.setPageName(“My Account”)
.setLocation(location.getLatitude(), location.getLongitude());

// trackPaidSubscriptionDeactivated method call
MTractionEventTracker.trackPaidSubscriptionDeactivated(this.getApplicationContext(), pSubsDeactivate);

3. Level Achieved Event

This is used to track Player’s progress in the game when he has successfully completed a level.

You will need to call the below method of MTractionEventTracker Class to track the Level Achieved Event in your Application.

Public static void trackLevelAchieved(Context context, LevelAchieved lvlAchieved);
LevelAchieved  lvlAchieved = new LevelAchieved(userId, level, score);

  • Mandatory parameters (Level Achieved): 
    • User Id – Unique User Identifier
    • Level – Level Reached by the Player
    • Score – Score accumulated by the Player
  • Optional parameters (Level Achieved): 
    • Rank – Player’s Rank

Sample Code

// Example Constructor Call with the mandatory parameters
LevelAchieved lvlAchieved = new LevelAchieved(“123”, 5, 4650);

// Examples for other parameters passed with the event (These are optional)
lvlAchieved.setRank(5);

// trackLevelAchieved method call
MTractionEventTracker.trackLevelAchieved(this.getApplicationContext(), lvlAchieved);

4. Achievement Unlocked Event

This is used to track the Game Player’s progress when he has completed any milestones to move to the next level of the game.

You will need to call the below method of MTractionEventTracker Class to track the Achievement Unlocked event in your Application.

Public static void trackAchievementUnlocked(Context context, AchievementUnlocked achvUnlocked);
AchievmentUnlocked  achvUnlocked = new AchievmentUnlocked(userId, identifier);

  • Mandatory parameters (Achievement Unlocked Event): 
    • User Id – Unique User Identifier
    • Identifier – Unique Identifier of the Level reached by the Player
  • Optional parameters (Achievement Unlocked Event):
    • Description – Details about the Achievement
    • Category – Category of the Achievement

Sample Code

// Example Constructor Call with the mandatory parameters
AchievmentUnlocked  achivementUnlocked = new AchievmentUnlocked(“123”, ”L10”);

// Examples for other parameters passed with the event (These are optional)
achivementUnlocked.setDescription(“Storm Trooper”)
.setCategory(“Novice”);

// trackAchievmentUnlocked method call
MTractionEventTracker.trackAchievmentUnlocked(this.getApplicationContext(), achivementUnlocked);

5. Tutorial Completed Event

This is used to track the event triggered when the Player has completed any tutorials in the Game.

You will need to call the below method of MTractionEventTracker Class to track the Tutorial Completed event in your Application.

Public static void trackTutorialCompleted(Context context, TutorialCompleted tutorialCompleted);
TutorialCompleted tutorialCompleted = new TutorialCompleted(userId, TutorialCompleted.SuccessFlag.XXX, identifier);

  • Mandatory parameters (Tutorial Completed): 
    • User Id – Unique User Identifier
    • TutorialCompleted.SuccessFlag.XXXXXX can take any of the flag values, [TRUE OR FALSE] based on the successful evaluation (if available) of the tutorial in the Game.
    • Identifier – Unique Tutorial Identifier

Sample Code

// Example Product Constructor Call with the mandatory parameters
TutorialCompleted tutorialCompleted= new TutorialCompleted(“123”, TutorialCompleted.SuccessFlag.TRUE, “10008”);

// trackTutorialCompleted method call
MTractionEventTracker.trackTutorialCompleted(this.getApplicationContext(), tutorialCompleted);
Was this article helpful to you? Yes No

How can we help?