event.data

Type [String][api.type.string]
Event adsRequest
Revision Release 2026.3728
Keywords ads, advertising, AdMob, adsRequest, data
See also adsRequest
admob.*

Overview

A JSON-formatted string which contains the following fields:

Precision Types

The precision field indicates the accuracy of the reported adValue:

Value Name Description
0 Unknown The value is not known. Returned for test ads.
1 Estimated An estimate based on median eCPM from the ad network or mediation group. Most common in production.
2 Publisher Provided A manually configured CPM value from mediation group settings.
3 Precise Exact revenue reported by the ad network. Only some networks support this.

Example

local json = require("json")

local function adListener( event )

    if ( event.phase == "revenue" ) then
        local data = json.decode( event.data )

        -- Revenue data
        print( data.adUnitId )       -- "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY"
        print( data.adValue )        -- "0.005"
        print( data.currencyCode )   -- "USD"
        print( data.precision )      -- 1

    elseif ( event.phase == "reward" ) then
        local data = json.decode( event.data )

        -- Reward data
        print( data.rewardItem )     -- "coins"
        print( data.rewardAmount )   -- 100

    elseif ( event.phase == "failed" ) then
        local data = json.decode( event.data )

        -- Error data
        print( data.errorCode )      -- e.g. 3
        print( data.errorMsg )       -- e.g. "No fill"
    end
end