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?
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:
Fetching ads client-side
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:
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:
- the cID is not assigned to the zone
- the cID is not targeted to the visitor
- the cID does not exist or is invalid
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: