Ad code is a piece of code that an ad server uses to serve ads. Each zone of every website on your Adserver.Online account has its own ad code. In order to display ads, you need to place this code on your website(s).

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 in an asynchronous mode, so it doesn't block page loading.

Third-party clicks tracking

If you need to publish an ad code in some 3rd-party ad system, you could use "data-redirector" parameter to configure click tracking.

You should examine 3rd-party documentation in order to find needed macros. For example, in Google GAM/DFP, 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">

Configuration

The codes (all at once) on a page can be configured using a special JS-code 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 one time. 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 one time. False by default.
  • cmp – if true, the ad code will try to find the installed consent management platform (CMP) and retrieve the visitor's consent. Applied to GDPR only. False by default.

Please note these parameters will work with the usual ad code only. They will be ignored if you load ads programmatically using JS API (see below).

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', 'tag3'],
'keywords': ['cats', 'dogs', 'monkeys'],
'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': 'xxxxx',
'refid1': 'zzzzz'
};
</script> 

Javascript API

Callbacks

Our ad code supports two JS-callbacks. They have to be configured separately for each piece of code.

  • onload – will be called after the ad is shown
  • onempty – will be called in case of no ads

In order 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 has to 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

You can load ads programmatically if a usual ad code is not suitable for you for some reason. For example, if you want to show ads in a single-page application (SPA). 

To do that, you should use "_ASO.loadAd" function.

Simple usage example:

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

Calling with extra parameters:

_ASO.loadAd('el', 34919, true, { // HTML ID, Zone ID, async, params
  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 on a visitor's click.

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 in the form of 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 in the form of 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 having names subid1 … subid10 will be extracted from the URL instead of t1 … t10

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

Facebook Instant Articles

https://developers.facebook.com/docs/instant-articles/reference/ad

You should compose a code manually based on this example:

<figure class="op-ad">
  <iframe width="200" height="400">
     <!-- regular invocation code --> 
     <ins class="aso-zone" data-zone="xxx"></ins><script data-cfasync="false" async src="https://media.aso1.net/js/code.min.js"></script>
  </iframe>
</figure>

Google AMP pages

What's AMP page?

AMP-code is available on a zone page.

Auto refreshing

Our ad code supports auto-refreshing for banner zones. To enable it, you should set the refresh interval (in seconds) in the Advanced options of a zone.