Skip to content

Commit

Permalink
convert bidders: adyoulike
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 18, 2022
1 parent b9a4d56 commit 113e717
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 44 deletions.
3 changes: 2 additions & 1 deletion modules/adxpremiumAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function auctionInit(args) {

completeObject.auction_id = args.auctionId;
completeObject.publisher_id = adxpremiumAnalyticsAdapter.initOptions.pubId;
try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.referer.split('?')[0]); } catch (e) { logError('AdxPremium Analytics - ' + e.message); }
// TODO: is 'page' the right value here?
try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.page.split('?')[0]); } catch (e) { logError('AdxPremium Analytics - ' + e.message); }
if (args.adUnitCodes && args.adUnitCodes.length > 0) {
elementIds = args.adUnitCodes;
}
Expand Down
26 changes: 5 additions & 21 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,6 @@ function getHostname(bidderRequest) {
return '';
}

/* Get current page canonical url */
function getCanonicalUrl() {
let link;
if (window.self !== window.top) {
try {
link = window.top.document.head.querySelector('link[rel="canonical"][href]');
} catch (e) { }
} else {
link = document.head.querySelector('link[rel="canonical"][href]');
}

if (link) {
return link.href;
}
return '';
}

/* Get mediatype from bidRequest */
function getMediatype(bidRequest) {
if (deepAccess(bidRequest, 'mediaTypes.banner')) {
Expand Down Expand Up @@ -236,20 +219,21 @@ function createEndpointQS(bidderRequest) {

if (bidderRequest) {
const ref = bidderRequest.refererInfo;
if (ref) {
qs.RefererUrl = encodeURIComponent(ref.referer);
if (ref?.location) {
// TODO: is 'location' the right value here?
qs.RefererUrl = encodeURIComponent(ref.location);
if (ref.numIframes > 0) {
qs.SafeFrame = true;
}
}
}

const can = getCanonicalUrl();
const can = bidderRequest?.refererInfo?.canonicalUrl;
if (can) {
qs.CanonicalUrl = encodeURIComponent(can);
}

const domain = config.getConfig('publisherDomain');
const domain = bidderRequest?.refererInfo?.domain;
if (domain) {
qs.PublisherDomain = encodeURIComponent(domain);
}
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/adxpremiumAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('AdxPremium analytics adapter', function () {
'auctionStart': 1589707613899,
'timeout': 2000,
'refererInfo': {
'referer': 'https://test.com/article/176067',
'page': 'https://test.com/article/176067',
'reachedTop': true,
'numIframes': 0,
'stack': [
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('AdxPremium analytics adapter', function () {
'auctionStart': 1589707613899,
'timeout': 2000,
'refererInfo': {
'referer': 'https://test.com/article/176067',
'page': 'https://test.com/article/176067',
'reachedTop': true,
'numIframes': 0,
'stack': [
Expand Down
26 changes: 6 additions & 20 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { newBidder } from 'src/adapters/bidderFactory.js';
describe('Adyoulike Adapter', function () {
const canonicalUrl = 'https://canonical.url/?t=%26';
const referrerUrl = 'http://referrer.url/?param=value';
const domain = 'domain:123';
const defaultDC = 'hb-api';
const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
const bidderRequest = {
Expand All @@ -16,7 +17,7 @@ describe('Adyoulike Adapter', function () {
consentString: consentString,
gdprApplies: true
},
refererInfo: {referer: referrerUrl}
refererInfo: {location: referrerUrl, canonicalUrl, domain}
};
const bidRequestWithEmptyPlacement = [
{
Expand Down Expand Up @@ -578,19 +579,6 @@ describe('Adyoulike Adapter', function () {
});

describe('buildRequests', function () {
let canonicalQuery;

beforeEach(function () {
let canonical = document.createElement('link');
canonical.rel = 'canonical';
canonical.href = canonicalUrl;
canonicalQuery = sinon.stub(window.top.document.head, 'querySelector');
canonicalQuery.withArgs('link[rel="canonical"][href]').returns(canonical);
});

afterEach(function () {
canonicalQuery.restore();
});

it('Should expand short native image config type', function() {
const request = spec.buildRequests(bidRequestWithNativeImageType, bidderRequest);
Expand All @@ -600,7 +588,7 @@ describe('Adyoulike Adapter', function () {
expect(request.method).to.equal('POST');
expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));
expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl));
expect(request.url).to.contains('PublisherDomain=http%3A%2F%2Flocalhost%3A9876');
expect(request.url).to.contains('PublisherDomain=' + encodeURIComponent(domain));

expect(payload.Version).to.equal('1.0');
expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0');
Expand Down Expand Up @@ -696,7 +684,7 @@ describe('Adyoulike Adapter', function () {
expect(request.method).to.equal('POST');
expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));
expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl));
expect(request.url).to.contains('PublisherDomain=http%3A%2F%2Flocalhost%3A9876');
expect(request.url).to.contains('PublisherDomain=' + encodeURIComponent(domain));

expect(payload.Version).to.equal('1.0');
expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0');
Expand All @@ -705,8 +693,7 @@ describe('Adyoulike Adapter', function () {
});

it('sends bid request to endpoint with single placement without canonical', function () {
canonicalQuery.restore();
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
const request = spec.buildRequests(bidRequestWithSinglePlacement, {...bidderRequest, refererInfo: {...bidderRequest.refererInfo, canonicalUrl: null}});
const payload = JSON.parse(request.data);

expect(request.url).to.contain(getEndpoint());
Expand All @@ -720,8 +707,7 @@ describe('Adyoulike Adapter', function () {
});

it('sends bid request to endpoint with single placement multiple mediatype', function () {
canonicalQuery.restore();
const request = spec.buildRequests(bidRequestWithMultipleMediatype, bidderRequest);
const request = spec.buildRequests(bidRequestWithSinglePlacement, {...bidderRequest, refererInfo: {...bidderRequest.refererInfo, canonicalUrl: null}});
const payload = JSON.parse(request.data);

expect(request.url).to.contain(getEndpoint());
Expand Down

0 comments on commit 113e717

Please sign in to comment.