All Products
Search
Document Center

Mobile Platform as a Service:Configure a preset ad space

Last Updated:Jun 04, 2026

Retrieves ad space information for an H5 page built on the mPaaS H5 container. You can retrieve a single ad space or multiple ad spaces in a batch. To intercept ad space and ad information before display, use an ActionExecutor.

Before you begin

If you are new to the smart delivery component, configure H5 ad spaces directly from the component's console (server-side). For more information, see Create an ad space.

Retrieve a single ad space

Call getCdpSpaceInfo on your H5 page to retrieve ad space information:

AlipayJSBridge.call('getCdpSpaceInfo', {
  spaceCode: 'space-code1',
  extInfo: {
    tradeNo: '123'
  },
  immediately: false,
  multiCallback: true
}, function (result) {
  console.log(result);
});

Parameters:

  • spaceCode: The ad space code. Get this code from the backend.

  • extInfo: Extended information in key-value format.

  • immediately: An optional Boolean parameter. Set to true to fetch data directly from the server, bypassing the cache. Defaults to false.

  • multiCallback: Set to true to receive two sequential callbacks per call. Set to false to receive only one callback.

Note

When multiCallback is false or omitted, your service logic receives a single result callback. If a caching mechanism is active, the ad may not appear on the user's first visit—it appears only on the second visit. When multiCallback is true, smart delivery triggers two callbacks: the first returns cached data (if available), and the second returns the Remote Procedure Call (RPC) result.

Retrieve ad spaces in batches

Call getCdpSpaceInfos on your H5 page to retrieve multiple ad spaces in a single request:

AlipayJSBridge.call('getCdpSpaceInfos', {
  spaceCodes: ['space-code1', 'space-code2'],
  extInfo: {
    tradeNo: '123'
  },
  immediately: false,
  multiCallback: true
}, function (result) {
  console.log(result);
});
/**
 * Cdp ad service interface
 *
 */
public abstract class CdpAdvertisementService extends ExternalService {

    /**
     * Initializes all ad information.
     *
     * @param extInfo  Extended information.
     * @param callBack The callback.
     */
    public abstract void initialized(Map<String, String> extInfo, IAdGetSpaceInfoCallBack callBack);

    /**
     * Queries an ad space by its ID. The query result is returned asynchronously through the onSuccess(SpaceInfo spaceInfo) callback.
     * If no local cache exists, the result of the RPC query is returned in one callback.
     * If a local cache exists and has not expired, the local query result is returned in one callback.
     * If a local cache exists and has expired, the local query result is returned in one callback, and the updated result is returned in another callback after the RPC is complete.
     * The onFail() interface is called only if the RPC fails.
     *
     * @param spaceCode The ad space ID. You need to request it from the delivery platform.
     * @param callback  The callback interface.
     */
    public abstract void getSpaceInfoByCode(String spaceCode, IAdGetSingleSpaceInfoCallBack callback);

    /**
     * Queries an ad space by its ID. The query result is returned asynchronously through the onSuccess(SpaceInfo spaceInfo) callback.
     * If no local cache exists, the result of the RPC query is returned in one callback.
     * If a local cache exists and has not expired, the local query result is returned in one callback.
     * If a local cache exists and has expired, the local query result is returned in one callback, and the updated result is returned in another callback after the RPC is complete.
     * The onFail() interface is called only if the RPC fails.
     *
     * @param spaceCode   The ad space ID. You need to request it from the delivery platform.
     * @param extInfo     Extended parameters.
     * @param immediately Returns only the RPC result.
     * @param callback    The callback interface.
     */
    public abstract void getSpaceInfoByCode(String spaceCode, Map<String, String> extInfo, boolean immediately, final IAdGetSingleSpaceInfoCallBack callback);

    /**
     * Queries ad spaces in batches by a list of ad space IDs. The query result is returned asynchronously through the onSuccess(List<SpaceInfo> adSpaceInfo) callback.
     * If no local cache exists, the result of the RPC query is returned in one callback.
     * If a local cache exists and has not expired, the local query result is returned in one callback.
     * If a local cache exists and has expired, the local query result is returned in one callback, and the updated result is returned in another callback after the RPC is complete.
     * The onFail(List<String> adSpaceCodes) interface is called only if the RPC fails.
     *
     * @param spaceCodeList A list of ad space IDs. You need to request them from the delivery platform.
     * @param extInfo       Extended parameters.
     * @param immediately   Returns only the RPC result.
     * @param callback      The callback interface.
     */
    public abstract void batchGetSpaceInfoByCode(List<String> spaceCodeList, Map<String, String> extInfo, boolean immediately, final IAdGetSpaceInfoCallBack callback);

    /**
     * TODO Reserved H5 interface.
     * Queries and displays an ad. Currently, this is only called by AdH5Plugin.
     *
     * @param activity   The current page.
     * @param parentView The parent view.
     * @param url        The URL.
     * @param h5Param    The parameter.
     */
    public abstract void checkAndShowAdInH5(final Activity activity, ViewGroup parentView, String url, String h5Param);

    /**
     * Removes the ad view for a specified spaceCode.
     *
     * @param activity  The page from which to remove the ad.
     * @param spaceCode The ad ID.
     */
    public abstract void removeAdvertisement(Activity activity, String spaceCode);

    /**
     * Gets the action executor. Returns null if not set.
     *
     * @return The action executor.
     */
    public abstract ActionExecutor getActionExecutor();

    /**
     * Sets the action executor.
     *
     * @param executor The action executor.
     */
    public abstract void setActionExecutor(ActionExecutor executor);

    /**
     * Sets the user ID.
     *
     * @param userId The user ID.
     */
    public abstract void setUserId(String userId);

    /**
     * Gets the user ID.
     *
     * @return The user ID.
     */
    public abstract String getUserId();

    /**
     * The callback class for getting ad spaces.
     */
    public interface IAdGetSpaceInfoCallBack {
        /**
         * Successfully retrieved ad space information.
         *
         * @param adSpaceInfo A list of ad spaces.
         */
        void onSuccess(List<SpaceInfo> adSpaceInfo);

        /**
         * Failed to retrieve ad space information.
         *
         * @param adSpaceCodes A list of requested ad space codes.
         */
        void onFail(List<String> adSpaceCodes);
    }

    /**
     * The callback class for getting a single ad space.
     */
    public interface IAdGetSingleSpaceInfoCallBack {
        /**
         * Successfully retrieved ad space information.
         *
         * @param spaceInfo The ad space information.
         */
        void onSuccess(SpaceInfo spaceInfo);

        /**
         * Failed.
         */
        void onFail();
    }
}

ActionExecutor

ActionExecutor intercepts ad space and ad information before display. Return true from interceptAction to suppress the ad space and its content. Return false to let the client display them normally.

/**
 * Action handler
 *
 */
public interface ActionExecutor {

    /**
     * Specifies whether to intercept the action.
     * @param spaceInfo The ad space information.
     * @param spaceObjectInfo The ad information.
     * @param url The action URL.
     * @return Returns true to intercept the action, or false to not intercept it.
     */
    boolean interceptAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);

    /**
     * Executes the action.
     *
     * @param spaceInfo The ad space information.
     * @param spaceObjectInfo The ad information.
     * @param url The action URL.
     * @return Returns 1 for success. Other values indicate an error.
     */
    int executeAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);
}