Jump to: navigation, search

How to Set Up IAP Tracking

Revision as of 18:54, 1 December 2015 by Admin (Talk | contribs) (Android)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to Set Up IAP Tracking

The proper implementation of IAP tracking is key to unlocking the full potential of Fuse's segmentation and targeting system. IAP tracking gives you the ability to analyze paying user behaviours, choose specific types of content for users based on their in-app spending (like IAP offers, rewarded video, and non-rewarded ads), and also provides feedback on whether the purchase is verified or not by the app store.

Once you have the SDK integrated and a Fuse session is started, you can call the in-app purchase tracking methods. There are variations on these methods depending on what platform you are using, so make sure that you’re passing all the correct parameters that are relevant for your platform. You can immediately see purchases being made via segments in the dashboard.

See the links below in the Integration section, and select your platform to get specific instructions.

iOS

NoteBubble.png

When registering in-app purchases, especially when testing IAP offers, make sure to use a US based iTunes account. Fuse requires USD prices by default, if the purchase is made using another currency it will be available in the Fuse dashboard for setting up targeted IAP offers.

When using Fuse to track IAPs in a native iOS application, you must first pass the response received by registering your product list to the FuseSDK method registerInAppPurchaseList.

Fetching Product List

When the product list is fetched from Apple's servers, a function needs to be called to provide the Fuse system with information on what products are available in your app. In your SKProductsRequestDelegate delegate, place the function call seen below in the productsRequest delegate function.

This must happen before purchases are registered and we suggest implementing it in the sessionStartReceived callback of your app.

  -(void)productsRequest:(SKProductsRequest*)request
    didReceiveResponse:(SKProductsResponse*) response
  {...
    [FuseSDK registerInAppPurchaseList:response];
  ...}

Register IAP Call

Once the product list has been registered, the registerInAppPurchase function needs to be called once it has been confirmed that the transaction has occurred successfully. Optimally, this should be done in the recordTransaction function in your SKPaymentTransactionObserver delegate.

  -(void) recordTransaction:(SKPaymentTransaction*)transaction{
    ...
    [FuseSDK registerInAppPurchase: transaction];
    ...
  }

Purchase Verification Callback

When an IAP is made, the Fuse server will verify the purchase with Apple's receipt validation system and notify the app using the following FuseDelegate callback:

  -(void) purchaseVerification(NSNumber*)_verified
    TransactionID:(NSString*)_tx_id
    OriginalTransactionID:(NSString*)_o_tx_id;

The _verified bit returns one of three values:

1: The purchase is suspected to be valid.

0: The purchase is suspected to be invalid.

-1: We did not attempt verification. This can be due to a network error or lack of connectivity.

Android

NoteBubble.png

Before your app goes live you must set up Google In-App Purchase Validation via the Fuse dashboard.

IAP-Validation-Android.png

To set up IAP Validation in the Fuse dashboard:

1. From any page in the Fuse dashboard, click on your username in the top right of the upper navigation bar.

2. Choose “Store Credentials” from the dropdown menu

3. Select the “Android” tab

4. In the “IAP Validation” section, click the “GET REFRESH TOKEN” button and follow the instructions


Fuse allows tracking of in-app purchases in real-time. To do this, use the following code block:

 import com.fusepowered.FuseSDK;
 import com.fusepowered.util.PurchaseState;
 import com.fusepowered.util.VerifiedPurchase;
 
 ...
  
  public void onIabPurchaseFinished(IabResult result, Purchase info) //This method will be automatically called
  {
    VerifiedPurchase verifiedPurchase = new VerifiedPurchase(Integer.toString(info.getPurchaseState()),
       info.getToken(), info.getSku(), info.getOrderId(), info.getPurchaseTime(), info.getDeveloperPayload());
  
    //If you know the price and currency then use this:
    FuseSDK.registerInAppPurchase(verifiedPurchase, 1.99, "USD");
  
    //Otherwise use
    FuseSDK.registerInAppPurchase(verifiedPurchase);
 }

A com.fusepowered.util.VerifiedPurchase object should be passed to the registerInAppPurchase method.

Unity

The Prime31 and Unibill plugins are both supported to make it easier to automatically track IAPs. Each can be enabled via the FuseSDK prefab component window (see Package Importing and Set Up). If not using a billing plugin, see below for steps to register in-app purchases.

iOS

To register the price and currency that a user is using to make iOS in-app purchases, use the following call:

  FuseSDK.RegisterIOSInAppPurchaseList(products);

After receiving the list of in-app purchases from Apple, this method can be called to record the localized item information.

products Object:

ATTRIBUTE TYPE DESCRIPTION
ProductId String The ID of the product used by the App Store.
Price Float The price of the product.
PriceLocale String The currency of the product's price.


To record an iOS in-app purchase in the Fuse system, use the following call;

        FuseSDK.RegisterIOSInAppPurchase(productId ,transactionId ,transactionReceipt, transactionState);

The parameters of this call are;

  • productId (string): The product ID of the purchased item.
  • transactionId (string): The transaction ID of the purchase supplied by Apple.
  • transactionReceipt (byte[]): The data payload associated with the purchase, supplied by Apple.
  • transactionState (IAPState): The transaction state of the purchase. Members are: PURCHASING, PURCHASED, FAILED, RESTORED.

If your app is using the Prime31 or Unibill plugin you do not need to call these functions!

Android

To record an Android in-app purchase in the Fuse system, make the following call:

  FuseSDK.RegisterAndroidInAppPurchase (purchaseState, purchaseToken, productId, orderId, purchaseTime, developerPayload, price, currency); 		

The parameters of this call are;

  • purchaseState (IAPState): The transaction state of the purchase. Members are: PURCHASED, CANCELED, REFUNDED
  • purchaseToken (string): The purchase token provided by Google Play.
  • productId (string): The product id of the item being purchased.
  • orderId (string): The order id of this transaction.
  • purchaseTime (long): Unix timestamp when purchase was made.
  • developerPayload (string): Developer payload provided by Google Play.
  • price(double): The price of the purchased item.
  • currency (string): The currency string identifier.

This function also has an overload where purchaseTime is of type DateTime.

If your app is using the Prime31 or Unibill plugin you do not need to call these functions!

Complete Integration Reference