Google Ad Manager has been set up to work with Adrelevantis Bidder Adapter to deliver native ads that are relevant to page content. As a publisher, you just need to use the Google tag to display relevant ads in your pages. In this blog, I will show you how to make a page to display content-relevant ads by providing keywords and IAB Categories for the page.
Here, I assume that you have basic understanding of Prebid.js header bidding open source library. If you are new to the Prebid.js, please read this Basic Prebid.js Example. Then, go to Ads relevant to content with Adrelevantis bidder adapter to see the code that is discussed in this blog.
Here is the entire code from native-example.html.
<html>
<head>
<script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
<script async src="//www.adrelevantis.com/pub/prebid.js"></script>
<script>
//Prebid.js and Google Ad Manager code
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var PREBID_TIMEOUT = 3000;
var FAILSAFE_TIMEOUT = 6000;
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
function bidFunc(keywrds, cats)
{
//Keywords and IAB Categories of the content are sent as bidder parameters
pbjs.que.push(function() {
pbjs.setBidderConfig({
bidders: ['adrelevantis'],
config: {
ortb2: {
site: {
keywords: keywrds,
ext: {
data: {category: cats}
}
}
}
}
});
var adUnits = [
{
code: 'div-1',
mediaTypes: {
native: {
sendTargetingKeys: false,
title: {
required: true
},
image: {
required: true
},
clickUrl: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'adrelevantis',
params: {
placementId: 13232354,
allowSmallerSizes: true,
cpm: 0.9
}
}]
},
{
code: 'div-2',
mediaTypes: {
native: {
sendTargetingKeys: false,
title: {
required: true
},
image: {
required: true
},
clickUrl: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'adrelevantis',
params: {
placementId: 13232354,
allowSmallerSizes: true,
cpm: 0.9
}
}]
},
{
code: 'div-3',
mediaTypes: {
native: {
sendTargetingKeys: false,
title: {
required: true
},
image: {
required: true
},
clickUrl: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'adrelevantis',
params: {
placementId: 13232354,
allowSmallerSizes: true,
cpm: 0.9
}
}]
},
{
code: 'div-4',
mediaTypes: {
native: {
sendTargetingKeys: false,
title: {
required: true
},
image: {
required: true
},
clickUrl: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'adrelevantis',
params: {
placementId: 13232354,
allowSmallerSizes: true,
cpm: 0.9
}
}]
}];
googletag.cmd.push(function() {
var slot1 = googletag.defineSlot('/21901351985/native_nature', 'fluid', 'div-1').addService(googletag.pubads());
var slot1 = googletag.defineSlot('/21901351985/native_square', 'fluid', 'div-2').addService(googletag.pubads());
var slot1 = googletag.defineSlot('/21901351985/native_horizontal', 'fluid', 'div-3').addService(googletag.pubads());
var slot1 = googletag.defineSlot('/21901351985/native_vertical', 'fluid', 'div-4').addService(googletag.pubads());
googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});
function initAdserver(bids) {
if (pbjs.initAdserverSet) return;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
pbjs.initAdserverSet = true;
}
setTimeout(function(bids) {
initAdserver(bids);
}, FAILSAFE_TIMEOUT);
};
bidFunc("Pets Dental Health,Pet dental", "/pets|/pets/cats");
</script>
</head>
<body>
<h2>Native Content-Driven Advertising Examples</h2>
<div id='div-1'>
</div>
<div id='div-2' style="width: 30%">
</div>
<div id='div-3' style="width: 50%">
</div>
<div id='div-4' style="width: 25%">
</div>
</body>
</html>
The function bidFunc(keywrds, cats) has typical Prebid.js code for publishers that works with Googletag. Pay attention to the setBidderConfig that sets keywords and categories for adrelevantis bidder. These keywords and categories are used to match ads. If an ad found and other criteria (geo-location, cpm, etc.) met, a bid is returned. The rest of the code defines ad units, maps the ad units to ad slots of Google Ad Manager, and requests bid.
In this simple example, we hard-coded the comma-separated keywords (“Pets Dental Health,Pet dental”) and the pipe-separated IAB Categories (“/pets|/pets/cats”) for demonstration purpose. If you know the keywords or IAB Categories of a page, or you want to target to particular keywords or categories, you can use this approach. However, it will be more useful if the keywords and categories of a page can be identified automatically when the page is viewed. In next post, I will discuss how an AI service can be used to identify the keywords and categories of a page automatically.
Click the following link to see native ads in this example: native-example.
Contact: info@adrelevantis.com.
To understand what the Content-Driven Advertising is, please read the following post: