In-App Events
- Vue d'ensemble
- Envoyer un événement
- In-app purchase validation (beta)
- In-app purchase validation (legacy)
Vue d'ensemble
Les événements in-app permettent d'analyser ce qui se passe dans votre application. Il est recommandé de prendre le temps de définir les événements que vous voulez mesurer pour pouvoir mesurer le ROI (Return On Investment) et la LTV (Lifetime Value).
L'enregistrement des événements in-app est effectué en appelant sendEvent
avec des paramètres de nom d'événement et de valeur. Consultez la documentation sur les Événements in-app pour plus de détails.
Vous trouverez plus d'informations sur l'enregistrement des événements ici.
Envoyer un événement
void sendEvent(string eventName, Dictionary<string, string> eventValues)
parameter | type | description |
---|---|---|
eventName | string | Le nom de l'événement |
eventValues | Dictionary<string, string> | Les valeurs de l'événement transmises avec l'événement |
Exemple :
Dictionary<string, string> eventValues = new Dictionary<string, string>();
eventValues.Add(AFInAppEvents.CURRENCY, "USD");
eventValues.Add(AFInAppEvents.REVENUE, "0.99");
eventValues.Add("af_quantity", "1");
AppsFlyer.sendEvent(AFInAppEvents.PURCHASE, eventValues);
Logging de revenu
You can send revenue with any in-app event. Use the AFInAppEvents.REVENUE
event parameter to include revenue in the in-app event. You can populate it with any numeric value, positive or negative.
La valeur de revenu ne doit pas contenir de séparateurs sous forme de virgules, de symbole monétaire ou de texte. Un événement de revenu doit être similaire à 1234.56, par exemple.
Currency code requirements when sending revenue events
-
Default currency: USD
-
Use a 3-character ISO 4217 code (an example follows).
-
Set the currency code by calling the API:
AppsFlyer.setCurrencyCode("ZZZ")
Example: In-app purchase event with revenue
This purchase event is for 200.12 Euros. For the revenue to reflect in the dashboard use the following.
using System.Collections.Generic;
Dictionary<string, string> purchaseEvent = new Dictionary<string, string> ();
purchaseEvent.Add(AFInAppEvents.CURRENCY, "EUR");
purchaseEvent.Add(AFInAppEvents.REVENUE, "200.12");
purchaseEvent.Add(AFInAppEvents.QUANTITY, "1");
purchaseEvent.Add(AFInAppEvents.CONTENT_TYPE, "category_a",);
AppsFlyer.sendEvent ("af_purchase", purchaseEvent);
Remarque
N'inscrivez pas de devise après la valeur du revenu.
Logging negative revenue
Record negative revenue using a minus sign.
- Revenue value is preceded by a minus sign.
- The event name has a unique value, "cancel_purchase". This lets you identify negative revenue events in raw data reports and in the Dashboard.
Example: App user receives a refund or cancels a subscription
using System.Collections.Generic;
Dictionary<string, string> purchaseEvent = new Dictionary<string, string> ();
purchaseEvent.Add(AFInAppEvents.CURRENCY, "USD");
purchaseEvent.Add(AFInAppEvents.REVENUE, "-200");
purchaseEvent.Add(AFInAppEvents.QUANTITY, "1");
purchaseEvent.Add(AFInAppEvents.CONTENT_TYPE, "category_a");
AppsFlyer.sendEvent ("cancel_purchase", purchaseEvent);
In-app purchase validation Beta
This API is currently in closed beta. Please contact AppsFlyer before using it.
Pour la validation de réception d'achat in-app, suivez les instructions propres à votre système d'exploitation.
Remarques
Appeler validateReceipt génère automatiquement un événement in-app af_purchase
, vous n'avez pas besoin d'envoyer cet événement vous-même.
La réponse de validation de l'achat est déclenchée dans AppsFlyerTrackerCallbacks.cs
class.
// for Android
`void validateAndSendInAppPurchase(AFPurchaseDetailsAndroid details, Dictionary<string, string> additionalParameters, MonoBehaviour gameObject)`
// for iOS
`void validateAndSendInAppPurchase(AFSDKPurchaseDetailsIOS details, Dictionary<string, string> extraEventValues, MonoBehaviour gameObject)`
using UnityEngine.Purchasing;
using AppsFlyerSDK;
public class AppsFlyerObject : MonoBehaviour, IAppsFlyerValidateAndLog
{
public static string kProductIDConsumable = "com.test.cons";
void Start()
{
AppsFlyer.initSDK("devKey", "devKey");
AppsFlyer.startSDK();
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
string prodID = args.purchasedProduct.definition.id;
string price = args.purchasedProduct.metadata.localizedPrice.ToString();
string currency = args.purchasedProduct.metadata.isoCurrencyCode;
string receipt = args.purchasedProduct.receipt;
var recptToJSON = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize(product.receipt);
var receiptPayload = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize((string)recptToJSON["Payload"]);
var transactionID = product.transactionID;
if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
{
#if UNITY_IOS
if(isSandbox)
{
AppsFlyeriOS.setUseReceiptValidationSandbox(true);
}
AFSDKPurchaseDetailsIOS details = AFSDKPurchaseDetailsIOS.Init(prodID, price, currency, transactionID);
AppsFlyeriOS.validateAndSendInAppPurchase(details, null, this);
#elif UNITY_ANDROID
AFPurchaseDetailsAndroid details = new AFPurchaseDetailsAndroid(AFPurchaseType.Subscription, "token", prodID, price, currency);
AppsFlyerAndroid.validateAndSendInAppPurchase(
details,
null,
this);
#endif
}
return PurchaseProcessingResult.Complete;
}
public void onValidateAndLogComplete(string result)
{
AppsFlyer.AFLog("onValidateAndLogComplete", result);
Dictionary<string, object> validateAndLogDataDictionary = AppsFlyer.CallbackStringToDictionary(result);
}
public void onValidateAndLogFailure(string error)
{
AppsFlyer.AFLog("onValidateAndLogFailure", error);
Dictionary<string, object> validateAndLogErrorDictionary = AppsFlyer.CallbackStringToDictionary(error);
}
}
Validation des achats in-app
Pour la validation de réception d'achat in-app, suivez les instructions propres à votre système d'exploitation.
Remarques
Appeler validateReceipt génère automatiquement un événement in-app af_purchase
, vous n'avez pas besoin d'envoyer cet événement vous-même.
La réponse de validation de l'achat est déclenchée dans AppsFlyerTrackerCallbacks.cs
class.
void validateAndSendInAppPurchase(string productIdentifier, string price, string currency, string tranactionId, Dictionary<string, string> additionalParameters, MonoBehaviour gameObject)
//To get the callbacks
//AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");
AppsFlyer.validateReceipt(string publicKey, string purchaseData, string signature, string price, string currency, Dictionary additionalParametes);
using UnityEngine.Purchasing;
using AppsFlyerSDK;
public class AppsFlyerObject : MonoBehaviour, IStoreListener, IAppsFlyerValidateReceipt
{
public static string kProductIDConsumable = "com.test.cons";
void Start()
{
AppsFlyer.initSDK("devKey", "devKey");
AppsFlyer.startSDK();
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
string prodID = args.purchasedProduct.definition.id;
string price = args.purchasedProduct.metadata.localizedPrice.ToString();
string currency = args.purchasedProduct.metadata.isoCurrencyCode;
string receipt = args.purchasedProduct.receipt;
var recptToJSON = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize(product.receipt);
var receiptPayload = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize((string)recptToJSON["Payload"]);
var transactionID = product.transactionID;
if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
{
#if UNITY_IOS
if(isSandbox)
{
AppsFlyeriOS.setUseReceiptValidationSandbox(true);
}
AppsFlyeriOS.validateAndSendInAppPurchase(prodID, price, currency, transactionID, null, this);
#elif UNITY_ANDROID
var purchaseData = (string)receiptPayload["json"];
var signature = (string)receiptPayload["signature"];
AppsFlyerAndroid.validateAndSendInAppPurchase(
"<google_public_key>",
signature,
purchaseData,
price,
currency,
null,
this);
#endif
}
return PurchaseProcessingResult.Complete;
}
public void didFinishValidateReceipt(string result)
{
AppsFlyer.AFLog("didFinishValidateReceipt", result);
}
public void didFinishValidateReceiptWithError(string error)
{
AppsFlyer.AFLog("didFinishValidateReceiptWithError", error);
}
}
Mis(e) à jour Il y a 7 mois