Using of Asynchronous codes » Tell ad server which data to use

Tell ad server which data to use

Last modified by ZdVo on 2018/07/11 08:28
Comments (0) · Attachments (0)

The second step you should decide about is whether you want to attach any data such as page keywords, category or anything else to the request for the ads which will be made to the ad server.
You can do that by simply "telling" to adserver to attach certain data to each request.

Data are passed to Ad Server through attachData(); method

You can pass keywords in such way: 

adserver.attachData("keywords", "keyword1; keyword2");

In the example above you pass to Ad Server request URL parameter with name keywords, which contains values keyword1 and keyword2. 

Another examples of insertion:

adserver.attachData("bestOffer", 0.60);

Or you can use function reference

adserver.attachData("userProfile", getFromDMP);

In latter case, before the ad server request for ads is made, the tag will call the function getFromDMP providing it with a "callback" function as argument. Your function can make any asynchronous request for data (user profile from DMP in this case) and when the profile arrives, you just have to call the callback function with the resulting profile. It will be attached to the request as userProfile and you can use it in targeting.

So, here is a "pseudocode" describing such function:

function getFromDMP(callback) {
   // somehow request the profile from DMP.. depends on the DMP or data provider.
   // when done, call:
   callback(profile);
}

Because there is the risk that we could wait indefinitely for the response from DMP (e.g. due to network problems etc.) there is a timeout that ensures, that if the profile does not return within a reasonable time, we will continue requesting ads from the ad server without the profile, which is, of course, better than not asking ad server at all.

You can of course attach multiple data to the request:
adserver.attachData("key1", "value1");
adserver.attachData("key2", "value2");
adserver2.attachData("key3", 3);

And of course, you can attach the same or different data to each of the configured ad server instances.

If you happen to have data already in a form of a "hash map"  ( an object with multiple key/value pairs) you can also pass it directly to attachData method:

adserver.attachData({
    key1: 'value1',
    key2: 'value2',
    key3, 3
});

Similarly, you can pass in the function which would eventually resolve with such a hash map:

adserver.attachData(someDataRetrievalFunction);

function someDataRetrievalFunction(callback) {
   // retrieve data in a form of hashmap
   ...
   //  call callback function with the data
   callback(data);
}

Please note that retrieving data using a function is always subject to a timeout. If the data cannot be retrieved in time, the request to ad server will anyways be made without the data attached so that you do not lose the impressions completely.
The data retrieval starts immediately after you call the attachData function. Hence, the sooner you call it before you actually try to request ads from the ad server the more time you will have for data collection before the timeout expires (it starts as soon as you try to request ads).

Attach data to one specific position

Upravit

If you need to attach data to one specific position, you can use following method:
attachDataToAdSlot('adslot''parameter''parameter value');

Then is necessary for position, to which are data passed, call requestAndPlaceAds('adslot') method.

adserver.attachDataToAdSlot('leaderboard','param1','testvalue');
ibbAds.tag.requestAndPlaceAds('leaderboard');

By this code, for position with name "leaderboard" is passed parameter with name "param1" and value of this parameter is "testvalue".
You can call this method multiple times for different adslots of course.

For example:

adserver.attachDataToAdSlot('ATG_J_300x600_1_S', 'headerbidder','test_01');
ibbAds.tag.requestAndPlaceAds('ATG_J_300x600_1_S');
adserver.attachDataToAdSlot('ATG_K_300x600_2_S', 'headerbidder','test_02');
ibbAds.tag.requestAndPlaceAds('ATG_K_300x600_2_S');
adserver.attachDataToAdSlot('ATG_K_300x300_2_S', 'headerbidder','test_03');
ibbAds.tag.requestAndPlaceAds('ATG_K_300x300_2_S');
Tags:
Created by ZdVo on 2017/03/21 10:13
Translated into en by ZdVo on 2017/05/09 09:45

Navigation


This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 4.0 - Documentation