Skip to content

Commit

Permalink
Lucead Adapter: update (#11143)
Browse files Browse the repository at this point in the history
* Lucead Adapter: update

* update endpoint url

* update tests
  • Loading branch information
aymeric45 authored Feb 28, 2024
1 parent c794435 commit 37d368e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
45 changes: 30 additions & 15 deletions modules/luceadBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import {loadExternalScript} from '../src/adloader.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getUniqueIdentifierStr, logInfo} from '../src/utils.js';
import {getUniqueIdentifierStr, logInfo, deepSetValue} from '../src/utils.js';
import {fetch} from '../src/ajax.js';

const bidderCode = 'lucead';
let baseUrl = 'https://ayads.io';
let staticUrl = 'https://s.ayads.io';
let baseUrl = 'https://lucead.com';
let staticUrl = 'https://s.lucead.com';
let companionUrl = 'https://cdn.jsdelivr.net/gh/lucead/prebid-js-external-js-lucead@master/dist/prod.min.js';
let endpointUrl = 'https://prebid.ayads.io/go';
let endpointUrl = 'https://prebid.lucead.com/go';
const defaultCurrency = 'EUR';
const defaultTtl = 500;
const isDevEnv = location.hostname.endsWith('.ngrok-free.app');

function isDevEnv() {
return location.hostname.endsWith('.ngrok-free.app') || location.href.startsWith('https://ayads.io/test');
}

function isBidRequestValid(bidRequest) {
return !!bidRequest?.params?.placementId;
Expand All @@ -21,16 +24,16 @@ export function log(msg, obj) {
logInfo('Lucead - ' + msg, obj);
}

function buildRequests(validBidRequests, bidderRequest) {
if (isDevEnv) {
baseUrl = `https://${location.hostname}`;
function buildRequests(bidRequests, bidderRequest) {
if (isDevEnv()) {
baseUrl = location.origin;
staticUrl = baseUrl;
companionUrl = `${staticUrl}/dist/prebid-companion.js`;
endpointUrl = `${baseUrl}/go`;
}

log('buildRequests', {
validBidRequests,
bidRequests,
bidderRequest,
});

Expand All @@ -39,15 +42,17 @@ function buildRequests(validBidRequests, bidderRequest) {
static_url: staticUrl,
endpoint_url: endpointUrl,
request_id: bidderRequest.bidderRequestId,
validBidRequests,
prebid_version: '$prebid.version$',
bidRequests,
bidderRequest,
getUniqueIdentifierStr,
ortbConverter,
deepSetValue,
};

loadExternalScript(companionUrl, bidderCode, () => window.ayads_prebid && window.ayads_prebid(companionData));

return validBidRequests.map(bidRequest => ({
return bidRequests.map(bidRequest => ({
method: 'POST',
url: `${endpointUrl}/prebid/sub`,
data: JSON.stringify({
Expand Down Expand Up @@ -80,7 +85,7 @@ function interpretResponse(serverResponse, bidRequest) {
height: (response?.size && response?.size?.height) || 250,
currency: response?.currency || defaultCurrency,
ttl: response?.ttl || defaultTtl,
creativeId: response?.ad_id || '0',
creativeId: response.ssp ? `ssp:${response.ssp}` : (response?.ad_id || '0'),
netRevenue: response?.netRevenue || true,
ad: response?.ad || '',
meta: {
Expand Down Expand Up @@ -119,13 +124,22 @@ function report(type = 'impression', data = {}) {
function onBidWon(bid) {
log('Bid won', bid);

return report(`impression`, {
let data = {
bid_id: bid?.bidId,
ad_id: bid?.creativeId,
placement_id: bid?.params ? bid?.params[0]?.placementId : 0,
spent: bid?.cpm,
currency: bid?.currency,
});
};

if (bid.creativeId) {
if (bid.creativeId.toString().startsWith('ssp:')) {
data.ssp = bid.creativeId.split(':')[1];
} else {
data.ad_id = bid.creativeId;
}
}

return report(`impression`, data);
}

function onTimeout(timeoutData) {
Expand All @@ -141,6 +155,7 @@ export const spec = {
interpretResponse,
onBidWon,
onTimeout,
isDevEnv,
};

// noinspection JSCheckFunctionSignatures
Expand Down
2 changes: 2 additions & 0 deletions modules/luceadBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Overview

Module Name: Lucead Bidder Adapter

Module Type: Bidder Adapter

Maintainer: prebid@lucead.com

# Description
Expand Down
8 changes: 7 additions & 1 deletion test/spec/modules/luceadBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ describe('Lucead Adapter', () => {
});
});

describe('utils functions', function () {
it('returns false', function () {
expect(spec.isDevEnv()).to.be.false;
});
});

describe('isBidRequestValid', function () {
let bid;
beforeEach(function () {
Expand All @@ -33,7 +39,7 @@ describe('Lucead Adapter', () => {

describe('onBidWon', function () {
let sandbox;
const bid = { foo: 'bar' };
const bid = { foo: 'bar', creativeId: 'ssp:improve' };

beforeEach(function () {
sandbox = sinon.sandbox.create();
Expand Down

0 comments on commit 37d368e

Please sign in to comment.