In-App Purchases
In-App purchase tracking will work only in connection with Adjust/AppsFlyer. To connect them, follow this guide for Adjust and this guide for AppsFlyer.
It's possible to track in-app purchase information and send info to Appodeal servers for analytics. It allows to group users by the fact of purchasing in-apps. This will help you to adjust the ads for such users or simply turn it off, if needed. To make this setting work correctly, please submit the purchase info via the Appodeal SDK.
Step 1. Validate In-App Purchases
If you are using your own Adjust account you need to complete Step 2 from our Event Tracking guide and create some required events on Adjust side.
To make this work correctly, please submit the purchase information via Appodeal SDK.
You need to follow the official Unity IAP guide to set up purchases and get purchase information.
- UPM Distribution
- Manual Distribution
#if UNITY_ANDROID
var additionalParams = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
var purchase = new PlayStoreInAppPurchase.Builder(PlayStorePurchaseType.Subs)
.WithAdditionalParameters(additionalParams)
.WithPurchaseTimestamp(793668600)
.WithDeveloperPayload("payload")
.WithPurchaseToken("token")
.WithPurchaseData("data")
.WithPublicKey("key")
.WithSignature("signature")
.WithCurrency("USD")
.WithOrderId("orderId")
.WithPrice("1.99")
.WithSku("sku")
.Build();
Appodeal.ValidatePlayStoreInAppPurchase(purchase, this);
#elif UNITY_IOS
var additionalParams = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
var purchase = new AppStoreInAppPurchase.Builder(AppStorePurchaseType.Consumable)
.WithAdditionalParameters(additionalParams)
.WithTransactionId("transactionId")
.WithProductId("productId")
.WithCurrency("USD")
.WithPrice("2.89")
.Build();
Appodeal.ValidateAppStoreInAppPurchase(purchase, this);
#endif
For Android:
Please make sure if you have created in-app product in Google Play Console → Monetize section to use:
PlayStorePurchaseType.InApp
for purchase type.PlayStorePurchaseType.Subs
for subscription.
For iOS:
Please make sure if you have created in-app product in App Store Connect to use:
AppStorePurchaseType.Consumable
orAppStorePurchaseType.NonConsumable
for purchase type.AppStorePurchaseType.AutoRenewableSubscription
orAppStorePurchaseType.NonRenewingSubscription
for subscription.
#if UNITY_ANDROID
var additionalParams = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
var purchase = new PlayStoreInAppPurchase.Builder(Appodeal.PlayStorePurchaseType.Subs)
.withAdditionalParameters(additionalParams)
.withPurchaseTimestamp(793668600)
.withDeveloperPayload("payload")
.withPurchaseToken("token")
.withPurchaseData("data")
.withPublicKey("key")
.withSignature("signature")
.withCurrency("USD")
.withOrderId("orderId")
.withPrice("1.99")
.withSku("sku")
.build();
Appodeal.validatePlayStoreInAppPurchase(purchase, this);
#elif UNITY_IOS
var additionalParams = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
var purchase = new AppStoreInAppPurchase.Builder(Appodeal.AppStorePurchaseType.Consumable)
.withAdditionalParameters(additionalParams)
.withTransactionId("transactionId")
.withProductId("productId")
.withCurrency("USD")
.withPrice("2.89")
.build();
Appodeal.validateAppStoreInAppPurchase(purchase, this);
#endif
For Android:
Please make sure if you have created in-app product in Google Play Console → Monetize section to use:
Appodeal.PlayStorePurchaseType.Subs
for purchase type.Appodeal.PlayStorePurchaseType.Subs
for subscription.
For iOS:
Please make sure if you have created in-app product in App Store Connect to use:
Appodeal.AppStorePurchaseType.Consumable
orAppodeal.AppStorePurchaseType.NonConsumable
for purchase type.Appodeal.AppStorePurchaseType.AutoRenewableSubscription
orAppodeal.AppStorePurchaseType.NonRenewingSubscription
for subscription.
Parameter | Description | Usage |
---|---|---|
purchaseType | Purchase type must be InApp or Subs | Adjust/AppsFlyer |
publicKey | Public key from Google Developer Console | AppsFlyer |
signature | Transaction signature (returned from Google API when the purchase is completed | Adjust/AppsFlyer |
purchaseData | Product purchased in JSON format (returned from Google API when the purchase is completed | AppsFlyer |
purchaseToken | Product purchased token (returned from Google API when the purchase is completed) | Adjust |
purchaseTimestamp | Product purchased timestamp (returned from Google API when the purchase is completed) | Adjust |
developerPayload | Product purchased developer payload (returned from Google API when the purchase is completed) | Adjust |
orderId | Product purchased unique order id for the transaction (returned from Google API when the purchase is completed) | Adjust |
sku | Stock keeping unit id | Adjust |
price | In-app event revenue | Adjust/AppsFlyer/Appodeal |
currency | In-app event currency | Adjust/AppsFlyer/Appodeal |
additionalParameters | Additional parameters of the in-app event | - |
transactionId | Some transaction id | Adjust/AppsFlyer |
productId | Some product id | Adjust/AppsFlyer |
For iOS
- All parameters are required
For Android
- Adjust In-app Purchase
- Adjust In-App Subscription
- AppsFlyer
- purchaseType
- purchaseToken
- developerPayload
- sku
- price
- currency
- additionalParameters
- purchaseType
- signature
- purchaseToken
- purchaseTimestamp
- orderId
- sku
- price
- currency
- additionalParameters
- purchaseType
- publicKey
- signature
- purchaseData
- price
- currency
- additionalParameters
Step 2. Callbacks
The callbacks are used to track successful and failed in-app purchases. To implement them, you need to follow the steps below:
- UPM Distribution
- Manual Distribution
- Subscribe to the desired In-App Purchase event using one of the options from this guide. (you can subscribe to any event you want)
- You can use callbacks as shown below:
public void SomeMethod()
{
AppodealCallbacks.InAppPurchase.OnValidationSucceeded += OnInAppPurchaseValidationSucceeded;
AppodealCallbacks.InAppPurchase.OnValidationFailed += OnInAppPurchaseValidationFailed;
}
#region InAppPurchaseValidation Callbacks
private void OnInAppPurchaseValidationSucceeded(object sender, InAppPurchaseEventArgs e)
{
Debug.Log("In-App Purchase Validation Succeeded");
}
private void OnInAppPurchaseValidationFailed(object sender, InAppPurchaseEventArgs e)
{
Debug.Log("In-App Purchase Validation Failed");
}
#endregion
- Extend your class with
IInAppPurchaseValidationListener
interface:
SomeClassName : IInAppPurchaseValidationListener {}
- Implement the required callback methods in your class:
#region InAppPurchaseValidation Callbacks
private void onInAppPurchaseValidationSucceeded(string json)
{
Debug.Log("In-App Purchase Validation Succeeded");
}
private void onInAppPurchaseValidationFailed(string json)
{
Debug.Log("In-App Purchase Validation Failed");
}
#endregion
Step 3. Generate Json File In Google Cloud (Android Only)
- Login to Google Cloud with your credentials.
- Select Google Play Console Developer project on the top left corner as shown below.
Please make sure to select Google Play Console Developer project at this step instead of your exact app project. Google Play Console only allows to link Google Play Console Developer cloud projects (later on step 3).
- Select Credentials → Create Credentials → select Service Account.
- Select Viewer as a role for Service Account and press Done.
- Go to your service account and press keys → Add key → choose JSON and send us the JSON file via email [email protected] or a live chat.
Step 4. Add Required Permissions In Google Play Console (Android Only)
- Go to the Google Play Console and log in.
- Go to Google Play Console → Manage developer accounts → Choose developer account → Setup → API Access and choose your Google Play Console Developer project from step 2 where you have created your Service Account.
If you are not able to see Google Play Console Developer project in the list then please update the webpage.
If the issue persists, make sure that your Google Play developer account (email) is the owner of the Google Cloud project. You can read more here.
- At the bottom there will be a list of service accounts that are available in this Google Cloud project. Select the one from which the JSON was sent.
- Press View Play Console permissions. In the App Permissions section select the necessary applications where in-app events will be used.
- Go to Account Permissions section and select all Financial Data permissions:
- View financial data
- Manage Orders and subscriptions
Step 5. Contact Us
After all completed steps contact our support team via email [email protected] or a live chat with the following information:
- Service account JSON file. (Android only)
- Purchases implementation logic in your app (when and where you call validate method and validate purchases)
- Send us the purchase testing access through Google Developer console to email [email protected]. (Android only)
- Your apk in zip for testing. (Android only)
- Allow us to test purchases in your app and send us the testflight to email [email protected]. (iOS only)
Step 6. Testing
After you have contacted our Support Team and provided all the required information you can test your app to make sure purchases are validated.
- Please go to your App Settings → Attribution Settings and change Adjust Environment from
Production
toSandbox
to be able to test validation and don't forget to press Save at the end of the page.
- Connect your device to your computer with the opened console (Android Studio logcat or iOS Console) and tag logs by purchase.
- Now you can open your App and make a test purchase, if you can see Valid Purchase in the console, then validation went successfully.
- If validation has failed, then please recheck all the steps above.
- After testing, change your Adjust Environment to
Production
in App Settings → Attribution Settings.