Display Ad Server
Serve ads in standard fixed-size units
Native Ad Server
Build native ads into your web page or app
VAST Video Server
Serve MP4 video ads as pre-rolls
Display Ad Server
Native Ad Server
VAST Video Ad Server
content_pasteRelease Notes
error_outlineNetwork Status
Terms of Service
Security Policy
Ad Tags
auto_storiesMacros for Ad Serving
auto_storiesAMP HTML Ads
Best Practices
auto_storiesEvaluating 3P Ad Tags for Speed
Campaign Setup
auto_storiesFlight Dates, Quantity & Pacing
auto_storiesCampaign Tiers
Getting Started
auto_storiesGetting Started with AdGlare
auto_storiesAdGlare Glossary
Good To Know
auto_storiesAdblock Detection Script
auto_storiesRevive vs AdGlare
auto_storiesThe Importance of Async Ad Tags
auto_storiesAd Server Pricing
auto_storiesVideo Ad Server with VAST Support
License & Billing
auto_storiesCDN Bandwidth & Fees
auto_storiesDownload Invoice PDFs
auto_storiesCancel License
auto_storiesReplace Credit Card
auto_storiesUpgrade Plan
Native Ads
auto_storiesNative Ads API
auto_storiesConversion Tracking
auto_storiesMetrics & Dimensions
auto_storiesExporting Data
auto_storiesCustom Formulas
auto_storiesFrequency Capping (GDPR)
auto_storiesKeyword Targeting
auto_storiesKey/Value Targeting
auto_storiesGeotargeting Locations
auto_storiesBrowser/OS/Device Targeting
auto_storiesWhite Labeled Ad Serving
auto_storiesBot Filtering for Ads
auto_storiesLazy-Loading Ads
auto_storiesKeeping Ads On The Screen
auto_storiesAdding a 3rd Party Tag
auto_storiesMove to different Folder

Native Ad Server via a JSON ad serving API

menu_book Knowledge Base chevron_right Native Ads
AdGlare Ad Server

Native Ads allow you to seamlessly integrate ads into your website using the same style and layout. To do so, you first need a native ad server like AdGlare. The "ad tag" in this case is a URL that returns a JSON response containing a list of ads. You can then parse this response and generate the ad unit using your own set of CSS styles.

As a publisher, you may be interested in native ads if you:
  • need to show ads in a mobile application
  • require ads to seamlessly integrate into your website's layout
  • want to get around ad blockers

Fetching JSON Ads: client-side or server-side?

You can consider to fetch the ads directly from the visitor's browser by making a (jQuery) GET request. After parsing the JSON response, you can generate the ad's HTML code via JavaScript and inject it into the DOM of the page. However, you can also opt to make the ad call via your own server: a so called server-to-server request. AdGlare allows you to pass on the user's profile for targeting purposes, like the IP address, user-agent, country, etc.

Create Ads server-side to get around Ad Blockers

Fetching ads server-side is a 99% effective method to get around Ad Blockers. And that's a big advantage these days. The client's browser doesn't contact any ad server, since the ads are directly integrated into the HTML of the page. To make that 100% effective, you should download the banner image via your own server, base64-encode it and use Data URIs on the IMG elements.

1 Setting up JSON Ad zones and campaigns

Log in to your AdGlare ad server portal and create a new campaign and zone using the JSON Ad campaign type. Upload or write your ads on the Campaigns Creatives tab. Then, get the endpoint URL for your JSON Ad zone via the page Zones Invocation Code.

2 Parsing the response

After obtaining the endpoint URL, you can make a GET request to fetch an ad. Your endpoint URL will look like:

If a campaign has been found, after applying targeting rules, the engines will respond with a JSON-encoded string of information about the ad. Parse the string into an object and your dataset will have the following format:

    "response": {
        "success": 1,
        "campaigns": [{
            "cID": "240257669",
            "crID": "943558423",
            "creative_type": "image",
            "creative_data": {
                "click_url": "http://...",
                "image_url": "http://..."
            "width": "468",
            "height": "60"
Impressions can be automatically logged when requesting the ad, and clicks are logged after calling click_url.

Fetching ads client-side

If you would like to fetch the JSON data client-side (i.e. via the visitor's browser), you can use jQuery to make an XHR request and automatically parse the result into a JSON JavaScript object. Here's an example:

<script> var zone_invocation_url = ""; $.getJSON(zone_invocation_url, function(data) { var cID = data.response.campaigns[0].cID; var click_url = data.response.campaigns[0].creative_data.click_url; // .... and so on // create your ad based on these variables }); </script>

Fetching ads server-side

Alternatively, if you prefer to fetch the ads server-side (i.e. via your own server), you can use cURL() and json_decode() to get the object. Here's a PHP example:

//define the endpoint URL $zone_invocation_url = ""; //fetch the data via cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $zone_invocation_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); //parse data into an array $arr = json_decode($data,true); //get variables $cID = $arr['response']['campaigns'][0]['cID']; $click_url = $arr['response']['campaigns'][0]['creative_data']['click_url'];
Note that adding the user's IP address to the URL is required, as in the example above.

Preferred cID order

You can ask the engines to return a certain campaign, instead of picking a random one. To do so, add the query parameter &preferred_cIDs= to the invocation URL. Here's an example:
Note that if...
  • the cID is not assigned to the zone
  • the cID is not targeted to the visitor
  • the cID does not exist or is invalid
... the engines will simply ignore it, and continue their quest to find a targeted campaign. You can also provide a list of cIDs by separating them with a semicolon:;987654321
All cIDs will be tested in the exact order as provided, and the first one passing targeting rules will be returned.

Sending the visitor's IP address

If you make the ad calls server-side, you can add the user's IP address in the X-Forwarded-For HTTP header. Without this header, your server's IP address will be used for geo-lookups and reporting.

Sending the User Agent

The User Agent is used to target campaigns based on the visitor's language, device type, OS, etc. Append the User Agent as a base64 encoded string to your GET request:

Sending the page's URL

This variable is used for Domain- and URL Targeting. It should be the page's actual URL on which the ad will be shown. Append the value URL encoded/escaped:

Sending the visitor's GPS Coordinates

This variable is used for GPS Position Targeting. Provide the coordinates as follows:

JSONP Callbacks

The engines can wrap the JSON response in your JavaScript callback function. In that case the MIME type is set to application/javascript. The callback variable name is sanitized for security reasons. You can use the following callback parameters to trigger a JSONP response:

  • &callback=
  • &jsonp=
  • &jsonpCallback=
  • &jsonCallback=
More information about JSONP can be found in this Wikipedia article.

External Resources

Share This

emoji_peopleMore about AdGlare

Since 2013, AdGlare powers the ad serving stack of hundreds of brands and publishers worldwide. With ideas and suggestions coming from Publishers, AdOps and Marketeers like you, we're proud to offer one of the most up-to-date ad servers in the market. We adhere to IAB's LEAN Ads Program and Google's Coalition for Better Ads.

Are you a publisher or brand? Reach out to see how we can help you.