# Integrate the AdPlay Web SDK

Integrate the supplied AdPlay Web SDK into this existing application using only its public developer interface.

## Before editing

- Inspect repository instructions, the app framework, its entry points, layout, state and lifecycle conventions, and existing build or verification commands.
- Identify the intended ad placements from the app. If their purpose or placement mapping is unclear, ask before choosing one.
- Use the supplied `adplay-web-sdk-1.0.1.iife.js` bundle when present. Do not rebuild or modify the SDK bundle.

## Public SDK interface

Use the public exports as needed:

- `AdplayApiClient`
- `AdplayRenderer`
- `AdplayEngagementReporter`
- `selectCreative`

Use their public constructor options, methods, result states, callbacks, and placement handles. Do not inspect or document the SDK’s internal implementation; integrate through its public interface and documented behavior only.

## Application integration

- Load the bundle once from the appropriate application entry point, or import `@adplay/web-sdk` where the package is already available.
- Load ads when the ad-enabled experience opens. Avoid duplicate setup during component remounts or app navigation.
- Handle `loaded`, `empty`, and `error` results while keeping the host application usable.
- Use `selectCreative` with the intended ad type, placement, display mode, and banner slot where applicable. Display the single selected creative for weighted placements.
- Render Banner, Splash, Popup, or PopupButton creatives in containers owned and sized by the host app. Use the corresponding public renderer method.
- For PopupButton, handle `onPopupRequested(popup)` and display the supplied Popup using the host app's popup container and lifecycle.
- Create one `AdplayEngagementReporter` for the active experience and connect `reporter.handleEvent` to the renderer's `onEvent` callback. Do not manually duplicate SDK callbacks.
- Use `clickPolicy.allowedHosts` with only exact destinations approved by the application. Use an empty list when no destination is approved.
- Keep confidential credentials out of browser code. If the application requires protected credentials, use only its approved credential configuration and request function through the SDK's public `fetch` option. If no approved approach exists, ask the user; never place a secret in client code.
- Use assigned `appId`, `publisherId`, and `regionId` values only when the host app has them; otherwise retain the SDK defaults.
- Hide or destroy placement handles when placements are removed or replaced. Preserve the host app's responsive layout, accessibility, and fallback behavior.

## Scope and verification

The public display interface supports image Banner, Splash, Popup, and PopupButton placements. Do not add unsupported audio, video, or rewarded placements.

Follow the application's existing conventions. Keep changes focused. Run the app's existing relevant checks and verify empty results, unavailable ads, placement cleanup, and responsive behavior.
