Native Ad Server solution via AdGlare's JSON ad serving API

Native Ads are popular these days. They allow you, as a publisher, to seamlessly integrate ads into your website using the same style and layout. A truly native ad server let you request the ads via a JSON ad serving API, so you can parse the response and generate the Ad HTML using your own set of styles. And that's exactly what AdGlare offers.

You may be interested in native ad serving if you:
  • need to show ads in a mobile App
  • require ads to seamlessly integrate into your website's layout
  • want to get around ad blockers (see section below)
  • need to pass custom key/value pairs to the ads

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.

Using S2S JSON techniques 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. Feel free to contact us for a geek-talk.


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:
https://yourname.engine.adglare.net/?123456789

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,
        "campaign": {
            "cID": "240257669",
            "crID": "943558423",
            "creative_type": "image",
            "creative_data": {
                "click_url": "http://...",
                "image_url": "http://..."
            },
            "width": "468",
            "height": "60"
        }
    }
}
Impressions are automatically logged upon requesting the ad, and clicks are logged after calling the 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 = "https://yourname.engine.adglare.net/?123456789";
    $.getJSON(zone_invocation_url, function(data) {
        var cID = data.response.campaign.cID;
        var click_url = data.response.campaign.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 = "https://try.engine.adglare.net/?585884456";

//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 a JSON object
$json = json_decode($data);

//get variables
$cID = $json->response->campaign->cID;
$click_url = $json->response->campaign->creative_data->click_url;


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:
https://yourname.engine.adglare.net/?123456789&preferred_cIDs=123456789
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 seperating them with a semicolon:
https://yourname.engine.adglare.net/?123456789&preferred_cIDs=123456789;987654321;56787654
All cIDs will be tested in the exact order as provided, and the first one passing targeting rules will be returned.


Passing on the visitor's IP address

If you make the ad calls server-side, you could to pass on a the user's IP address in order for geotargeting to work correctly. To do this, append the following key/value pair to your GET request:
https://yourname.engine.adglare.net/?123456789<b>&user_ip=123.123.123.132</b>



Passing on 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:
https://yourname.engine.adglare.net/?123456789<b>&useragent=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQ...</b>



Passing on 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:
https://yourname.engine.adglare.net/?123456789&referer=http%3A%2F%2Fdomain.com%2Fabc

Share this article




Permalink