extension-admob icon indicating copy to clipboard operation
extension-admob copied to clipboard

Added optional `userId` and `customData` support for rewarded AD

Open blendjam opened this issue 8 months ago • 4 comments
trafficstars

This currently supports android devices only. Any help from moderators is welcomed.

blendjam avatar Mar 21 '25 11:03 blendjam

Looks good.

This currently supports android devices only

iOS documentation: https://developers.google.com/admob/ios/rewarded#validate-ssv

britzl avatar Mar 26 '25 06:03 britzl

Adding support for userId is breaking as load_rewarded expects userId to be passed as argument.

blendjam avatar Mar 26 '25 14:03 blendjam

Adding support for userId is breaking as load_rewarded expects userId to be passed as argument.

You're right. It would be better to either have userId and customData as optional extra arguments or provide them in an options table:

local options = {
    user_id = "user_id",
    custom_data = "my custom data",
}
admob.show_rewarded("unit_id", options)

The below change should be enough to treat the values as optional:

static int Lua_LoadRewarded(lua_State* L)
{
    DM_LUA_STACK_CHECK(L, 0);
    if (lua_type(L, 1) != LUA_TSTRING) {
        return DM_LUA_ERROR("Expected string, got %s. Wrong type for Rewarded UnitId variable '%s'.", luaL_typename(L, 1), lua_tostring(L, 1));
    }
    const char* unitId_lua = luaL_checkstring(L, 1);

    char* userId_lua = 0;
    if (lua_gettop(L) > 1)
    {
        userId_lua =  luaL_checkstring(L, 2);
    }

    char* customData_lua = 0;
    if (lua_gettop(L) > 2)
    {
        customData_lua = luaL_checkstring(L, 3);
    }

    LoadRewarded(unitId_lua, userId_lua, customData_lua);
    return 0;
}

britzl avatar Mar 31 '25 08:03 britzl

Thanks! Could you please also update the script_api:

https://github.com/defold/extension-admob/blob/master/extension-admob/api/admob.script_api

britzl avatar Oct 28 '25 08:10 britzl