Compare direct API integration and the Web SDK
Compare direct API integration and the Web SDK
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
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.
Request and render an ad
Request an ad
Send an empty JSON object as the ad request.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)
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 thead_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.
http://localhost:8000/quick-start.html in a web 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.
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 (HTTP204) 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.
