appsflyer.logPurchase()

Type Function
Return value none
Revision Release 2024.3703
Keywords analytics, attribution, AppsFlyer, logPurchase
See also appsflyer.getVersion()
appsflyer.*

Overview

AppsFlyer’s SDK provides server verification for in-app purchases. This method automatically generates an af_purchase in-app event.

Important

For a list of possible return values for validating receipts, please refer to Apple’s documentation here.

Syntax

appsflyer.logPurchase( productData )
productData (required)

Table. Table containing key-value parameters. In-App Events provide insights on what is happening in your app. It is recommended to take the time and define the events you want to measure to allow you to track ROI (Return on Investment) and LTV (Lifetime Value).

You may specify your own custom key-value parameters (optional). Values should be of type String.

Parameter Reference

The productData table for iOS includes following parameters for logging IAP purchases:

productId (required)

String. The product ID/name for the IAP purchase.

currency (required)

String. The currency of the IAP transaction.

transactionId (required)

String. The transaction ID. This parameter applies to Apple App Store transactions only and is mandatory when logging an Apple IAP receipt. It expects the data from event.transaction.identifier found in the in-app purchase transaction callback.

price (required)

String. The unit price of the IAP item. The price parameter should contain the total revenue associated to the validated purchase event.

parameters (optional)

Table. Table containing additional key-value parameters.

The productData table for Android includes following parameters for logging IAP purchases:

publicKey (required)

String. API Key, the developer gets this from the Google portal.

signature (required)

String. The transaction signature. The developer gets it from google api when purchase succeeded. This parameter applies to Google Play transactions only and is mandatory when logging a Google IAP receipt. It expects the data from event.transaction.signature found in the in-app purchase transaction callback.

purchaseData (required)

String. Purchase data is the actual product purchased in json format. The developer gets it from google api when purchase succeeded.

price (required)

String. The unit price of the IAP item. The price parameter should contain the total revenue associated to the validated purchase event.

currency (required)

String. The currency of the IAP transaction.

parameters (optional)

Table. Table containing additional key-value parameters.

Examples

iOS
local appsflyer = require( "plugin.appsflyer" )

local function appsflyerListener( event )
    -- Handle events here
end

-- Initialize plugin
appsflyer.init( appsflyerListener,
    {
        appID = "YOUR_APP_ID",
       devKey = "YOUR_DEV_KEY"
    }
)

appsflyer.logPurchase(
    {
       productId = "111",
       price = "100",
       currency = "USD",
       transactionId = "222",
       parameters = { first = "1", second = "2" }
    }
)
Android
local appsflyer = require( "plugin.appsflyer" )

local function appsflyerListener( event )
   -- Handle events here
end

-- Initialize plugin
appsflyer.init( appsflyerListener,
    {
       appID = "YOUR_APP_ID",
       devKey = "YOUR_DEV_KEY"
    }
)

appsflyer.logPurchase(
    {
       publicKey = "111",
       signature = "222",
       purchaseData = "333",
       price = "100",
       currency = "USD",
       parameters = { first = "1", second = "2" }
    }
)