Ad deduplication
When there are multiple ad slots on a page, each ad slot is requested independently.
Therefore, the same ad creatives may be displayed.
To avoid displaying the same ad creatives, you may apply ad deduplication settings.
For guide and example of duplication control and restoration in a React environment, please refer to Ad Duplication Control and Restoration in React.
1. Ad Deduplication settings
1-1. Create ad deduplication manager
-
Use gladsdk.setAdDeduplication() to set an ad deduplication and create an ad deduplication manager.
- dedupReqId: identifier for ad ad deduplication manager
- maxDedupReqCount: number of ad slots that is applied ad deduplication - 1
var dedupReqId = 'deduplicationReuqestId';
var maxDedupReqCount = 5; // number of ad slots that is applied ad deduplication
var adDedupManager = window.gladsdk.setAdDeduplication(dedupReqId, maxDedupReqCount); -
Use gladsdk.setGlobalConfig() to set the default value for maxDedupReqCount.
Priority is given in the order of delivered value of
setAdDeduplication
>global settings
.The number of ad slots that is applied ad deduplication by using the adDedupManager as below sample code is 6.
window.gladsdk.setGlobalConfig({
maxDedupReqCount: 3,
});
var dedupReqId = 'deduplicationReuqestId';
var maxDedupReqCount = 5; // number of ad slots that is applied ad deduplication
var adDedupManager = window.gladsdk.setAdDeduplication(dedupReqId, maxDedupReqCount);
1-2. Disable ad deduplication
-
Use gladsdk.clearAdDeduplication() to disable ad deduplication.
var dedupReqId = 'deduplicationReuqestId';
window.gladsdk.clearAdDeduplication(dedupReqId);
2. Display a deduplicated ad
2-1. Display a deduplicated ad
- Use adDeduplicationManager.displayAds() to disable ad deduplication.
var adSlot1 = window.gladsdk.defineAdSlot(adSlotInfo1);
var adSlot2 = window.gladsdk.defineAdSlot(adSlotInfo2);
adDedupManager.displayAds([adSlot1, adSlot2]);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello NAM</title>
<script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script>
<script>
window.gladsdk = window.gladsdk || { cmd: [] };
</script>
</head>
<body>
<div id="division_1"></div>
<div id="division_2"></div>
<div id="division_3"></div>
<script>
var adSlotInfo1 = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division_1',
};
var adSlotInfo2 = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division_2',
};
var adSlotInfo3 = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division_3',
};
window.gladsdk.cmd.push(function () {
var adSlot1 = window.gladsdk.defineAdSlot(adSlotInfo1);
var adSlot2 = window.gladsdk.defineAdSlot(adSlotInfo2);
var adSlot3 = window.gladsdk.defineAdSlot(adSlotInfo3);
var adDedupManager = gladsdk.setAdDeduplication('deduplicationReuqestId', 2);
adDedupManager.displayAds([adSlot1, adSlot2, adSlot3]);
});
</script>
</body>
</html>
2-2. Restore a deduplicated ad
Restoring deduplicated ads only works when Persist mode is enabled
-
Use adDeduplicationManager.restoreAds() to restore ad slots previously requested by an ad deduplication manager
cautionrestoreAds
is a function that restores existing ads when going to another page and then returning to the previous page by going back with the Persist mode applied.Branch processing is required to determine whether the page has been loaded via go back on the media.
In the first rendering, ads must be rendered usingadDeduplicationManager.displayAds()
.
After restoration,adDeduplicationManager.restoreAds()
must be called.var adSlot = window.gladsdk.findAdSlot('division');
adDedupManager.restoreAds([adSlot]); -
If no arguments are passed to adDeduplicationManager.restoreAds(), all ad slots displayed by using the ad deduplication manager will be restored.
var adSlot1 = window.gladsdk.defineAdSlot(adSlotInfo1);
var adSlot2 = window.gladsdk.defineAdSlot(adSlotInfo2);
adDedupManager.displayAds([adSlot1, adSlot2]); // display by an adDedupManager
var adSlot3 = window.gladsdk.defineAdSlot(adSlotInfo3);
window.gladsdk.displayAd(adSlot3); // display without using an adDedupManager
// -------------------------------------------------------
adDedupManager.restoreAds(); // adSlot1, adSlot2 are restored, not adSlot3cautionIn a non-SPA environment, the
AdDeduplicationManager
cannot maintain the previous state if the page is refreshed by going back.Therefore, if a refresh occurs when going back, a slot needs to be newly created and then passed to restoreAds() to restore the advertisement.
For an example of a ad restoration by using the ad deduplication manager, please refer to Examples – Ad deduplication and Persist ad restoration.
3. Check whether ad deduplication is enabled.
-
The
ba
andbx
values must be added to the ad request QueryString.- Requests from the first ad slot with the ad deduplication applied would not be included
- Requests from the second ad slot with the ad deduplication applied would be included.
-
The
ba
andbx
values include theba
andbx
values of the previous ad slot request.- The
ba
andbx
values of the second slot must be included in theba
andbx
values of the third slot.
- The