Skip to main content
Run a web example that requests an image banner, renders it, and records a click. You will follow the ad tracking identifier from the ad response through event delivery, then confirm the click count in Ad Manager. In this exercise, you click the banner to confirm that its landing page opens, then send one click event from the terminal. See Ad Event and Log Integration to send events automatically when users click on a web page.
A2 supports direct Decision API calls and Web SDK integration. The direct API path is the default in these documents because it works in app and server environments and gives you control over request and response handling.The Web SDK uses the browser DOM and localStorage, so the same integration does not run in an app or server environment. Available SDK bundles and settings can vary by environment; confirm the bundle and options provided for your A2 environment before implementation. A guide to installing and using the Web SDK is in preparation.

Before you begin

This exercise doesn’t need an access token. Prepare the following before you start.
  • A2 address: See API Access and Authentication.
  • Ad unit: The ad unit, the area where the ad appears, must have an allocated ad with an image banner creative that can currently serve. Use a verification ad unit so that you can tell your results apart from other traffic.
  • Ad settings: The ad must be selectable by an empty {} request with no custom targeting, and the allocation’s Impression Tracking Mode must be On Ad Response (the default).
  • Ad Manager account: An Admin or Operator account is required to find the ad unit ID and view AdUnit Analytics.
  • Tools: curl, a text editor, a web browser, and Python 3 to run a local web server
If you don’t have an ad unit ready, ask your ad operations team for one. For setup, see Create and Manage Placements, Allocation Request, and Allocation Review. When the ad unit is ready, find the ID to use in requests.
1

Select the ad unit

In Ad Manager, go to Inventory > Ad Units and select the ad unit to use.
2

Open Settings

Select the Settings tab on the ad unit detail page.
3

Copy the ad unit ID

Copy the ID shown under Basic Information.
With On Ad Response, A2 records an impression when it selects an ad and builds the response, so the example doesn’t send a separate impression event. See Ad Event and Log Integration for other tracking modes. Before you start, go to Analytics > Inventory Analytics > AdUnit Analytics in Ad Manager and note today’s click count for the selected ad unit. Replace these two values in the examples.

Request and render an ad

Request an ad

Send an empty JSON object as the ad request.
When A2 selects an ad, it returns HTTP 200 with the ad response. For an image banner, find the image and landing URL in ad.display.banner, and the ad tracking identifier for events in the top-level ext.ad_log.
Response (excerpt)
HTTP 204 is a successful response that means no ad was available. Do not parse the response body as JSON; check the ad configuration.

Render the image banner

The example below sends a new ad request. It may return a different ad from the earlier curl request, so use the ad_log of the ad shown on the web page for the click event. Save the following as quick-start.html and replace baseUrl and tagid.
Run a local web server in the directory where you saved the file, then open http://localhost:8000/quick-start.html in a web browser.
If the curl request succeeds but the page shows a request failure message, see When requests fail only in the browser. ad_log appears only when the banner image is displayed. If no ad is returned or the request or image load fails, check the message in the ad area and don’t continue to the click event step. When the image appears, click the banner once, confirm that the landing page opens, and copy the displayed ad_log.

Send a click event

Replace <ad_log> with the ad_log you copied from the web page and send the click event once.
After receiving HTTP 200, verify actual collection in the next section.

Verify the result

In Ad Manager, go to Analytics > Inventory Analytics > AdUnit Analytics, select the ad unit you used, and set the date range to today. Confirm that the click count is one higher than the value you noted before the exercise. An impression is recorded for each curl or web page ad request that returned an ad, so the impression count can increase by that number. Requests that receive a no-ad response (HTTP 204) aren’t recorded as impressions. With the default settings, click events are usually reflected within a minute. After about a minute, reload the page in your browser to check, and don’t resend the click event to check. If the count still hasn’t changed after reloading, see When an event request succeeds but reporting doesn’t reflect it.

Next steps

1

Expand the service implementation

Use Ad Serving Integration and Ad Event and Log Integration to implement creative rendering and impression, click, and conversion handling.
2

Verify completion

Use the checklist in Integration Verification and Troubleshooting to verify API responses and analytics updates.
When using an authenticated API, see API Access and Authentication first for token issuance and storage.