Skip to content

Commit

Permalink
AdMatic Bid Adapter: added native type (#10647)
Browse files Browse the repository at this point in the history
* Admatic Bidder Adaptor

* Update admaticBidAdapter.md

* Update admaticBidAdapter.md

* remove floor parameter

* Update admaticBidAdapter.js

* Admatic Bid Adapter: alias and bid floor features activated

* Admatic adapter: host param control changed

* Alias name changed.

* Revert "Admatic adapter: host param control changed"

This reverts commit de7ac85.

* added alias feature and host param

* Revert "added alias feature and host param"

This reverts commit 6ec8f45.

* Revert "Alias name changed."

This reverts commit 661c54f.

* Revert "Admatic Bid Adapter: alias and bid floor features activated"

This reverts commit 7a2e0e2.

* Revert "Update admaticBidAdapter.js"

This reverts commit 7a845b7.

* Revert "remove floor parameter"

This reverts commit 7a23b05.

* Admatic adapter: host param control && Add new Bidder

* Revert "Admatic adapter: host param control && Add new Bidder"

This reverts commit 3c797b1.

* commit new features

* Update admaticBidAdapter.js

* updated for coverage

* sync updated

* Update adloader.js

* AdMatic Bidder: development of user sync url

* Update admaticBidAdapter.js

* Set currency for AdserverCurrency: bug fix

* Update admaticBidAdapter.js

* update

* admatic adapter video params update

* Update admaticBidAdapter.js

* update

* Update admaticBidAdapter.js

* update

* update

* Update admaticBidAdapter_spec.js

* Update admaticBidAdapter.js

* Update admaticBidAdapter.js

* Revert "Update admaticBidAdapter.js"

This reverts commit 1216892.

* Revert "Update admaticBidAdapter.js"

This reverts commit b1929ec.

* Revert "Update admaticBidAdapter_spec.js"

This reverts commit 1ca6597.

* Revert "update"

This reverts commit 689ce9d.

* Revert "update"

This reverts commit f381a45.

* Revert "Update admaticBidAdapter.js"

This reverts commit 38fd7ab.

* Revert "update"

This reverts commit a5316e7.

* Revert "Update admaticBidAdapter.js"

This reverts commit 60a28ca.

* Revert "admatic adapter video params update"

This reverts commit 31e69e8.

* update

* Update admaticBidAdapter.js

* Update admaticBidAdapter_spec.js

* mime_type add

* add native adapter
  • Loading branch information
fatihkaya84 authored Nov 2, 2023
1 parent 3f2cc28 commit a54c17c
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 6 deletions.
87 changes: 81 additions & 6 deletions modules/admaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import {getValue, logError, isEmpty, deepAccess, isArray, getBidIdParameter} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
export const OPENRTB = {
NATIVE: {
IMAGE_TYPE: {
ICON: 1,
MAIN: 3,
},
ASSET_ID: {
TITLE: 1,
IMAGE: 2,
ICON: 3,
BODY: 4,
SPONSORED: 5,
CTA: 6
},
DATA_ASSET_TYPE: {
SPONSORED: 1,
DESC: 2,
CTA_TEXT: 12,
},
}
};

let SYNC_URL = '';
const BIDDER_CODE = 'admatic';

export const spec = {
code: BIDDER_CODE,
aliases: [
{code: 'pixad'}
],
supportedMediaTypes: [BANNER, VIDEO],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/** f
* @param {object} bid
* @return {boolean}
Expand Down Expand Up @@ -46,10 +69,10 @@ export const spec = {
},
blacklist: [],
site: {
page: location.href,
ref: location.origin,
page: bidderRequest.refererInfo.page,
ref: bidderRequest.refererInfo.page,
publisher: {
name: location.hostname,
name: bidderRequest.refererInfo.domain,
publisherId: networkId
}
},
Expand Down Expand Up @@ -122,6 +145,8 @@ export const spec = {
resbid.vastImpUrl = bid.iurl;
} else if (resbid.mediaType === 'banner') {
resbid.ad = bid.party_tag;
} else if (resbid.mediaType === 'native') {
resbid.native = interpretNativeAd(bid.party_tag)
};

bidResponses.push(resbid);
Expand Down Expand Up @@ -157,6 +182,11 @@ function enrichSlotWithFloors(slot, bidRequest) {
videoSizes.forEach(videoSize => slotFloors.video[parseSize(videoSize).toString()] = bidRequest.getFloor({ size: videoSize, mediaType: VIDEO }));
}

if (bidRequest.mediaTypes?.native) {
slotFloors.native = {};
slotFloors.native['*'] = bidRequest.getFloor({ size: '*', mediaType: NATIVE });
}

if (Object.keys(slotFloors).length > 0) {
if (!slot) {
slot = {}
Expand Down Expand Up @@ -196,6 +226,11 @@ function buildRequestObject(bid) {
reqObj.type = 'video';
reqObj.mediatype = bid.mediaTypes.video;
}
if (bid.mediaTypes?.native) {
reqObj.type = 'native';
reqObj.size = [{w: 1, h: 1}];
reqObj.mediatype = bid.mediaTypes.native;
}

if (deepAccess(bid, 'ortb2Imp.ext')) {
reqObj.ext = bid.ortb2Imp.ext;
Expand All @@ -215,10 +250,11 @@ function getSizes(bid) {
function concatSizes(bid) {
let playerSize = deepAccess(bid, 'mediaTypes.video.playerSize');
let videoSizes = deepAccess(bid, 'mediaTypes.video.sizes');
let nativeSizes = deepAccess(bid, 'mediaTypes.native.sizes');
let bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes');

if (isArray(bannerSizes) || isArray(playerSize) || isArray(videoSizes)) {
let mediaTypesSizes = [bannerSizes, videoSizes, playerSize];
let mediaTypesSizes = [bannerSizes, videoSizes, nativeSizes, playerSize];
return mediaTypesSizes
.reduce(function(acc, currSize) {
if (isArray(currSize)) {
Expand All @@ -233,6 +269,45 @@ function concatSizes(bid) {
}
}

function interpretNativeAd(adm) {
const native = JSON.parse(adm).native;
const result = {
clickUrl: encodeURI(native.link.url),
impressionTrackers: native.imptrackers
};
native.assets.forEach(asset => {
switch (asset.id) {
case OPENRTB.NATIVE.ASSET_ID.TITLE:
result.title = asset.title.text;
break;
case OPENRTB.NATIVE.ASSET_ID.IMAGE:
result.image = {
url: encodeURI(asset.img.url),
width: asset.img.w,
height: asset.img.h
};
break;
case OPENRTB.NATIVE.ASSET_ID.ICON:
result.icon = {
url: encodeURI(asset.img.url),
width: asset.img.w,
height: asset.img.h
};
break;
case OPENRTB.NATIVE.ASSET_ID.BODY:
result.body = asset.data.value;
break;
case OPENRTB.NATIVE.ASSET_ID.SPONSORED:
result.sponsoredBy = asset.data.value;
break;
case OPENRTB.NATIVE.ASSET_ID.CTA:
result.cta = asset.data.value;
break;
}
});
return result;
}

function _validateId(id) {
return (parseInt(id) > 0);
}
Expand Down
152 changes: 152 additions & 0 deletions test/spec/modules/admaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe('admaticBidAdapter', () => {

describe('isBidRequestValid', function() {
let bid = {
'refererInfo': {
'page': 'https://www.admatic.com.tr',
'domain': 'https://www.admatic.com.tr',
},
'bidder': 'admatic',
'params': {
'networkId': 10433394,
Expand Down Expand Up @@ -48,6 +52,10 @@ describe('admaticBidAdapter', () => {
describe('buildRequests', function () {
it('sends bid request to ENDPOINT via POST', function () {
let validRequest = [ {
'refererInfo': {
'page': 'https://www.admatic.com.tr',
'domain': 'https://www.admatic.com.tr',
},
'bidder': 'admatic',
'params': {
'networkId': 10433394,
Expand Down Expand Up @@ -151,6 +159,51 @@ describe('admaticBidAdapter', () => {
'placement': 2
},
'id': '45e86fc7ce7fc93'
},
{
'size': [
{
'w': 1,
'h': 1
}
],
'type': 'native',
'mediatype': {
'title': {
'required': true,
'len': 120
},
'image': {
'required': true
},
'icon': {
'required': false,
'sizes': [
640,
480
]
},
'sponsoredBy': {
'required': false
},
'body': {
'required': false
},
'clickUrl': {
'required': false
},
'displayUrl': {
'required': false
}
},
'ext': {
'instl': 0,
'gpid': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a',
'data': {
'pbadslot': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a'
}
},
'id': '16e0c8982318f91'
}
],
'ext': {
Expand All @@ -159,6 +212,10 @@ describe('admaticBidAdapter', () => {
}
} ];
let bidderRequest = {
'refererInfo': {
'page': 'https://www.admatic.com.tr',
'domain': 'https://www.admatic.com.tr',
},
'bidder': 'admatic',
'params': {
'networkId': 10433394,
Expand Down Expand Up @@ -262,6 +319,51 @@ describe('admaticBidAdapter', () => {
'placement': 2
},
'id': '45e86fc7ce7fc93'
},
{
'size': [
{
'w': 1,
'h': 1
}
],
'type': 'native',
'mediatype': {
'title': {
'required': true,
'len': 120
},
'image': {
'required': true
},
'icon': {
'required': false,
'sizes': [
640,
480
]
},
'sponsoredBy': {
'required': false
},
'body': {
'required': false
},
'clickUrl': {
'required': false
},
'displayUrl': {
'required': false
}
},
'ext': {
'instl': 0,
'gpid': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a',
'data': {
'pbadslot': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a'
}
},
'id': '16e0c8982318f91'
}
],
'ext': {
Expand Down Expand Up @@ -307,6 +409,10 @@ describe('admaticBidAdapter', () => {
},
];
let bidderRequest = {
'refererInfo': {
'page': 'https://www.admatic.com.tr',
'domain': 'https://www.admatic.com.tr',
},
'bidder': 'admatic',
'params': {
'networkId': 10433394,
Expand Down Expand Up @@ -378,6 +484,19 @@ describe('admaticBidAdapter', () => {
'adomain': ['admatic.com.tr'],
'party_tag': 'https://www.admatic.com.tr',
'iurl': 'https://www.admatic.com.tr'
},
{
'id': 4,
'creative_id': '3742',
'width': 1,
'height': 1,
'price': 0.01,
'type': 'native',
'mime_type': 'iframe',
'bidder': 'admatic',
'adomain': ['admatic.com.tr'],
'party_tag': '{"native":{"ver":"1.1","assets":[{"id":1,"title":{"text":"title"}},{"id":4,"data":{"value":"body"}},{"id":5,"data":{"value":"sponsored"}},{"id":2,"img":{"url":"https://www.admatic.com.tr","w":1200,"h":628}},{"id":3,"img":{"url":"https://www.admatic.com.tr","w":640,"h":480}}],"link":{"url":"https://www.admatic.com.tr"},"imptrackers":["https://www.admatic.com.tr"]}}',
'iurl': 'https://www.admatic.com.tr'
}
],
'queryId': 'cdnbh24rlv0hhkpfpln0',
Expand Down Expand Up @@ -437,6 +556,39 @@ describe('admaticBidAdapter', () => {
},
ttl: 60,
bidder: 'admatic'
},
{
requestId: 4,
cpm: 0.01,
width: 1,
height: 1,
currency: 'TRY',
mediaType: 'native',
netRevenue: true,
native: {
'clickUrl': 'https://www.admatic.com.tr',
'impressionTrackers': ['https://www.admatic.com.tr'],
'title': 'title',
'body': 'body',
'sponsoredBy': 'sponsored',
'image': {
'url': 'https://www.admatic.com.tr',
'width': 1200,
'height': 628
},
'icon': {
'url': 'https://www.admatic.com.tr',
'width': 640,
'height': 480
}
},
creativeId: '3742',
meta: {
model: 'iframe',
advertiserDomains: ['admatic.com.tr']
},
ttl: 60,
bidder: 'admatic'
}
];
const request = {
Expand Down

0 comments on commit a54c17c

Please sign in to comment.