Ad Code

Ad code (or ad tag) is a piece of JS code that our ad server uses to serve ads. Each zone of every website on your Adserver.Online account has its unique ad code. You need to place this code on your website(s) to display ads.

Ad Code Example

<ins class="aso-zone" data-zone="34919"></ins>
<script data-cfasync="false" async src="https://media.aso1.net/js/code.min.js">

This code works asynchronously, so it doesn't block page loading.

Configuration

The codes (all at once) on a page can be configured using a special JS script placed in the HEAD section:

<script> 
   var _aso = _aso || {};
   _aso.option1 = true;
   _aso.option2 = false;
</script>

Available options

  • no_ad_dups – if true, then the same banner won't be displayed on the same page more than once. False by default.
  • no_campaign_dups – if true, then the campaign (any banners of it) won't be displayed on the same page more than once. False by default.
  • tcf – if true (by default), the ad code will try to find the installed consent management platform (CMP) and retrieve the visitor's consent. If GDPR does not apply to you, you can set it to false to make ads load a little bit faster.

Clicks Tracking in Third-party Systems

If you need to publish our ad code in a third-party ad system, you could use the "data-redirector" parameter to configure click tracking. Otherwise, you will see zero clicks in our stats reports.

You must examine 3rd-party documentation to find needed macros.

For example, in Google Ad Manager (GAM), you should use %%CLICK_URL_UNESC%% macros.

<ins class="aso-zone" data-zone="xxx" data-redirector="%%CLICK_URL_UNESC%%"></ins>
<script data-cfasync="false" async src="https://media.aso1.net/js/code.min.js">

More info about how to publish our code in Google Ad Manager (GAM).

Third-party Ad Codes Republishing

To republish third-party ad codes in our system, you should use HTML/JS banners.

Custom Attributes

If you need to pass some custom data to the ad-serving engine for custom targeting or other purposes, you should use the following piece of JS code in the HEAD section:

<script>
var _aso = _aso || {};
_aso.attr = {
tags: ["tag1", "tag2"],
keywords: ["cats", "dogs"],
hb_bid: 10,
gender: "male"
};
</script> 

There are reserved attributes' names: refid, refid1, refid2, refid3, refid4, refid5, refid6, refid7, refid8, refid9. If you pass them, they will become available inside an ad server in the form of placeholders {refid}, {refid1}, {refid2}, {refid3}, {refid4}, {refid5}, {refid6}, {refid7}, {refid8}, {refid9}.

For example:

<script>
var _aso = _aso || {};
_aso.attr = {
refid: "foo",
refid1: "bar"
};
</script> 

Auto refreshing

Our ad code supports auto-refreshing for banner zones. You should set the refresh interval (in seconds) in the zone's Advanced options to enable it.

Custom Renderer for Native Banners

On our platform, the native banner contains data fields such as headlines, icons, etc, and appearance-related parameters such as colors, fonts, templates, etc.

By default, the native banner is rendered using a server template configured on the banner form. However, a custom JS renderer can also be configured on the client side.

First, you must modify the ad code by adding a data-renderer attribute to the ins tag. It must contain a renderer function name. For example,

<ins class="aso-zone" data-zone="xxx" data-renderer="myRenderer"></ins>

Then, you have to create the function myRenderer, which will receive data from our ad code, render it in HTML, and insert it into the page DOM.

Renderer function example:

<script>
function myRenderer(ad) {
var ins = document.getElementById(ad.element),
div = document.createElement('div'),
html;

html = '<a href="' + ad.clickUrl + '">' + ad.data.headline + '</a>';
html += '<img src="' + ad.data.imageUrl + '">' + ad.data.body
div.innerHTML = html;
ins.parentNode.replaceChild(div, ins);
}
</script>

Javascript API

Callbacks

Our ad code supports two JS callbacks: onload is called when an ad is displayed, and onempty when the ad server doesn't find an ad to display in a zone. These callbacks can be configured separately per ad code or as a global configuration.

Global callbacks

<script>
var _aso = _aso || {};
_aso.onload = function(params) {
console.log('Ad', params.idad, 'is loaded');
},
_aso.onempty = function(params) {
console.log('Zone', params.idzone, 'is empty');
},
</script>

Zone callbacks

To configure callbacks, you have to change your ad code as shown:

<ins class="aso-zone" data-zone="xxx" data-onload="onloadCallback" data-onempty="onemptyCallback"></ins>

The corresponding JS function must be defined:

<script>
function onloadCallback(params) {
console.log("Ad loaded:", params);
}

function onemptyCallback(idzone) {
console.log("No ads for zone #", idzone);
}
</script>

NB: callback function name must not contain _ (underscore) character. Only alphanumeric characters are allowed.

Dynamic loading

If a usual ad code is not suitable for you, such as if you want to show ads in a single-page application (SPA), you can load ads programmatically. 

To do that, you should call _ASO.loadAd function.

The function arguments are HTML Element ID (string), Zone ID (integer), async loading (must be true), and params (array).

Usage example:

_ASO.loadAd("el", 34919); /* HTML ID, Zone ID */

Calling with extra parameters:

_ASO.loadAd("el", 34919, true, {
attr: {
tags:["a", "b"],
keywords: ["cars"]
},
onempty: "onEmpty",
onload: "onLoad"
});

Check out the demo at https://adserver.online/demost/js_api.html

Passing parameters through an ad server to a landing page

We have a couple of scripts to help you pass parameters from the URL where ads (banners) are displayed to a landing page when a visitor clicks on them.

1.  UTM labels

Firstly, you should add this snippet to the HEAD section of all the pages on your site:

<script src="https://media.aso1.net/js/tags/utm2attr.js"></script> 

After that, UTM labels will be available inside an ad server as special placeholders. You can insert them into the landing page URL on the ads form.

Placeholders: {refid}, {refid1}, {refid2}, {refid3}, {refid4}.

2. Arbitrary parameters

Firstly, you should add this snippet to the HEAD section of all the pages on your website:

<script type="text/javascript" src="https://media.aso1.net/js/tags/subid2attr.js"></script> 

After that, GET parameters t1 … t10 will become available inside the adserver as special placeholders. You can insert them into the landing page URL on the ads form.

Placeholders: {refid}, {refid1}, {refid2}, {refid3}, {refid4}, {refid5}, {refid6}, {refid7}, {refid8}, {refid9}.

Besides, you can add a special parameter to URL subid_param=xxx, for example, subid_param=subid. In this case, parameters with the names subid1 … subid10 will be extracted from the URL instead of t1 … t10

Please note statistics are only collected for the first two parameters (refid, refid1). Therefore, refid2 to refid9 are considered passthrough parameters, so there are no statistics on them.

Google Ad Manager (GAM)

This article explains how to publish our ad codes in Google Ad Manager.

Google AMP pages

What's AMP page? AMP code is available on a zone page.