Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lucead Adapter: update #11143

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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