diff --git a/modules/glimpseBidAdapter.js b/modules/glimpseBidAdapter.js deleted file mode 100644 index 53dc0bd3e1a..00000000000 --- a/modules/glimpseBidAdapter.js +++ /dev/null @@ -1,198 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER } from '../src/mediaTypes.js'; -import { getStorageManager } from '../src/storageManager.js'; -import { - isArray, - isEmpty, - isEmptyStr, - isStr, - isPlainObject, -} from '../src/utils.js'; - -const GVLID = 1012; -const BIDDER_CODE = 'glimpse'; -const storageManager = getStorageManager({bidderCode: BIDDER_CODE}); -const ENDPOINT = 'https://market.glimpsevault.io/public/v1/prebid'; -const LOCAL_STORAGE_KEY = { - vault: { - jwt: 'gp_vault_jwt', - }, -}; - -export const spec = { - gvlid: GVLID, - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - - /** - * Determines if the bid request is valid - * @param bid {BidRequest} The bid to validate - * @return {boolean} - */ - isBidRequestValid: (bid) => { - const pid = bid?.params?.pid; - return isStr(pid) && !isEmptyStr(pid); - }, - - /** - * Builds the http request - * @param validBidRequests {BidRequest[]} - * @param bidderRequest {BidderRequest} - * @returns {ServerRequest} - */ - buildRequests: (validBidRequests, bidderRequest) => { - const url = buildQuery(bidderRequest); - const auth = getVaultJwt(); - const referer = getReferer(bidderRequest); - const imp = validBidRequests.map(processBidRequest); - const fpd = getFirstPartyData(bidderRequest.ortb2); - - const data = { - auth, - data: { - referer, - imp, - fpd, - }, - }; - - return { - method: 'POST', - url, - data: JSON.stringify(data), - options: {}, - }; - }, - - /** - * Parse http response - * @param response {ServerResponse} - * @returns {Bid[]} - */ - interpretResponse: (response) => { - if (isValidResponse(response)) { - const { auth, data } = response.body; - setVaultJwt(auth); - const bids = data.bids.map(processBidResponse); - return bids; - } - return []; - }, -}; - -function setVaultJwt(auth) { - storageManager.setDataInLocalStorage(LOCAL_STORAGE_KEY.vault.jwt, auth); -} - -function getVaultJwt() { - return ( - storageManager.getDataFromLocalStorage(LOCAL_STORAGE_KEY.vault.jwt) || '' - ); -} - -function getReferer(bidderRequest) { - // TODO: is 'page' the right value here? - return bidderRequest?.refererInfo?.page || ''; -} - -function buildQuery(bidderRequest) { - let url = appendQueryParam(ENDPOINT, 'ver', '$prebid.version$'); - - const timeout = bidderRequest.timeout; - url = appendQueryParam(url, 'tmax', timeout); - - if (gdprApplies(bidderRequest)) { - const consentString = bidderRequest.gdprConsent.consentString; - url = appendQueryParam(url, 'gdpr', consentString); - } - - if (ccpaApplies(bidderRequest)) { - url = appendQueryParam(url, 'ccpa', bidderRequest.uspConsent); - } - - return url; -} - -function appendQueryParam(url, key, value) { - if (!value) { - return url; - } - const prefix = url.includes('?') ? '&' : '?'; - return `${url}${prefix}${key}=${encodeURIComponent(value)}`; -} - -function gdprApplies(bidderRequest) { - return Boolean(bidderRequest?.gdprConsent?.gdprApplies); -} - -function ccpaApplies(bidderRequest) { - return ( - isStr(bidderRequest.uspConsent) && - !isEmptyStr(bidderRequest.uspConsent) && - bidderRequest.uspConsent?.substr(1, 3) !== '---' - ); -} - -function processBidRequest(bid) { - const sizes = normalizeSizes(bid.sizes); - - return { - bid: bid.bidId, - pid: bid.params.pid, - sizes, - }; -} - -function normalizeSizes(sizes) { - const isSingleSize = - isArray(sizes) && - sizes.length === 2 && - !isArray(sizes[0]) && - !isArray(sizes[1]); - - if (isSingleSize) { - return [sizes]; - } - - return sizes; -} - -function getFirstPartyData(ortb2) { - let fpd = ortb2 || {}; - optimizeObject(fpd); - return fpd; -} - -function optimizeObject(obj) { - if (!isPlainObject(obj)) { - return; - } - for (const [key, value] of Object.entries(obj)) { - optimizeObject(value); - // only delete empty object, array, or string - if ( - (isPlainObject(value) || isArray(value) || isStr(value)) && - isEmpty(value) - ) { - delete obj[key]; - } - } -} - -function isValidResponse(bidResponse) { - const auth = bidResponse?.body?.auth; - const bids = bidResponse?.body?.data?.bids; - return isStr(auth) && isArray(bids) && !isEmpty(bids); -} - -function processBidResponse(bid) { - const meta = bid.meta || {}; - meta.advertiserDomains = bid.meta?.advertiserDomains || []; - - return { - ...bid, - meta, - }; -} - -registerBidder(spec); diff --git a/modules/glimpseBidAdapter.md b/modules/glimpseBidAdapter.md deleted file mode 100644 index e82c5d8f32e..00000000000 --- a/modules/glimpseBidAdapter.md +++ /dev/null @@ -1,37 +0,0 @@ -# Overview - -``` -Module Name: Glimpse Protocol Bid Adapter -Module Type: Bidder Adapter -Maintainer: publisher@glimpseprotocol.io -``` - -# Description - -This module connects publishers to Glimpse Protocol's demand sources via Prebid.js. Our innovative marketplace protects -consumer privacy while allowing precise targeting. It is compliant with GDPR, DPA and CCPA. - -The Glimpse Adapter supports banner formats. - -# Test Parameters - -```javascript -const adUnits = [ - { - code: 'banner-div-a', - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bids: [ - { - bidder: 'glimpse', - params: { - pid: 'e53a7f564f8f44cc913b', - }, - }, - ], - }, -]; -``` diff --git a/modules/liveyieldAnalyticsAdapter.js b/modules/liveyieldAnalyticsAdapter.js deleted file mode 100644 index 997c0eaace0..00000000000 --- a/modules/liveyieldAnalyticsAdapter.js +++ /dev/null @@ -1,454 +0,0 @@ -import { logError } from '../src/utils.js'; -import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; -import adapterManager from '../src/adapterManager.js'; -import CONSTANTS from '../src/constants.json'; - -const { - EVENTS: { BID_REQUESTED, BID_TIMEOUT, BID_RESPONSE, BID_WON } -} = CONSTANTS; - -const prebidVersion = '$prebid.version$'; - -const adapterConfig = { - /** Name of the `rta` function, override only when instructed. */ - rtaFunctionName: 'rta', - - /** This is optional but highly recommended. The value returned by the - * function will be used as ad impression ad unit attribute value. - * - * As such if you have placement (10293845) or ad unit codes - * (div-gpt-ad-124984-0) but you want these to be translated to meaningful - * values like 'SIDEBAR-AD-01-MOBILE' then this function shall express this - * mapping. - */ - getAdUnitName: function(placementOrAdUnitCode) { - return placementOrAdUnitCode; - }, - - /** - * Function used to extract placement/adUnitCode (depending on prebid - * version). - * - * The extracted value will be passed to the `getAdUnitName()` for mapping into - * human friendly value. - */ - getPlacementOrAdUnitCode: function(bid, version) { - return version[0] === '0' ? bid.placementCode : bid.adUnitCode; - }, - - /** - * Optional reference to Google Publisher Tag (gpt) - */ - googlePublisherTag: false, - - /** - * Do not override unless instructed. Useful for testing. Allows to redefined - * the event that triggers the ad impression event. - */ - wireGooglePublisherTag: function(gpt, cb) { - gpt.pubads().addEventListener('slotRenderEnded', function(event) { - cb(event.slot); - }); - }, - - /** - * Map which keeps BID_WON events. Keyed by adId property. - */ - prebidWinnersCache: {}, - - /** - * Map which keeps all BID_RESPONSE events. Keyed by adId property. - */ - prebidBidResponsesCache: {}, - - /** - * Decides if the GPT slot contains prebid ad impression or not. - * - * When BID_WON event is emitted adid is added to prebidWinnersCache, - * then we check if prebidWinnersCache contains slot.hb_adid. - * - * This function is optional and used only when googlePublisherTag is provided. - * - * Default implementation uses slot's `hb_adid` targeting parameter. - * - * @param slot the gpt slot - */ - isPrebidAdImpression: function(slot) { - const hbAdIdTargeting = slot.getTargeting('hb_adid'); - if (hbAdIdTargeting.length > 0) { - const hbAdId = hbAdIdTargeting[0]; - return typeof this.prebidWinnersCache[hbAdId] !== 'undefined'; - } - return false; - }, - - /** - * If isPrebidAdImpression decides that slot contain prebid ad impression, - * this function should return prebids highest ad impression partner for that - * slot. - * - * Default implementation uses slot's `hb_adid` targeting value to find - * highest bid response and when present then returns `bidder`. - * - * @param instanceConfig merged analytics adapter instance configuration - * @param slot the gpt slot for which the name of the highest bidder shall be - * returned - * @param version the version of the prebid.js library - */ - getHighestPrebidAdImpressionPartner: function(instanceConfig, slot, version) { - const bid = getHighestPrebidBidResponseBySlotTargeting( - instanceConfig, - slot, - version - ); - - // this is bid response event has `bidder` while bid won has bidderCode property - return bid ? bid.bidderCode || bid.bidder : null; - }, - - /** - * If isPrebidAdImpression decides that slot contain prebid ad impression, - * this function should return prebids highest ad impression value for that - * slot. - * - * Default implementation uses slot's `hb_adid` targeting value to find - * highest bid response and when present then returns `cpm`. - * - * @param instanceConfig merged analytics adapter instance configuration - * @param slot the gpt slot for which the highest ad impression value shall be - * returned - * @param version the version of the prebid.js library - */ - getHighestPrebidAdImpressionValue: function(instanceConfig, slot, version) { - const bid = getHighestPrebidBidResponseBySlotTargeting( - instanceConfig, - slot, - version - ); - - return bid ? bid.cpm : null; - }, - - /** - * This function should return proper ad unit name for slot given as a - * parameter. Unit names returned by this function should be meaningful, for - * example 'FOO_728x90_TOP'. The values returned shall be inline with - * `getAdUnitName`. - * - * Required when googlePublisherTag is defined. - * - * @param slot the gpt slot to translate into friendly name - * @param version the version of the prebid.js library - */ - getAdUnitNameByGooglePublisherTagSlot: (slot, version) => { - throw 'Required when googlePublisherTag is defined.'; - }, - - /** - * Function used to prepare and return parameters provided to rta. - * More information will be in docs given by LiveYield team. - * - * When googlePublisherTag is not provided, second parameter(slot) will always - * equal null. - * - * @param resolution the original ad impression details - * @param slot gpt slot, will be empty in pure Prebid.js-case (when - * googlePublisherTag is not provided) - * @param hbPartner the name of the highest bidding partner - * @param hbValue the value of the highest bid - * @param version version of the prebid.js library - */ - postProcessResolution: (resolution, slot, hbPartner, hbValue, version) => { - return resolution; - } -}; - -const cpmToMicroUSD = v => (isNaN(v) ? 0 : Math.round(v * 1000)); - -const getHighestPrebidBidResponseBySlotTargeting = function( - instanceConfig, - slot, - version -) { - const hbAdIdTargeting = slot.getTargeting('hb_adid'); - if (hbAdIdTargeting.length > 0) { - const hbAdId = hbAdIdTargeting[0]; - return ( - instanceConfig.prebidWinnersCache[hbAdId] || - instanceConfig.prebidBidResponsesCache[hbAdId] - ); - } - return null; -}; - -const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), { - track({ eventType, args }) { - switch (eventType) { - case BID_REQUESTED: - args.bids.forEach(function(b) { - try { - window[liveyield.instanceConfig.rtaFunctionName]( - 'bidRequested', - liveyield.instanceConfig.getAdUnitName( - liveyield.instanceConfig.getPlacementOrAdUnitCode( - b, - prebidVersion - ) - ), - args.bidderCode - ); - } catch (e) { - logError(e); - } - }); - break; - case BID_RESPONSE: - liveyield.instanceConfig.prebidBidResponsesCache[args.adId] = args; - var cpm = args.statusMessage === 'Bid available' ? args.cpm : null; - try { - window[liveyield.instanceConfig.rtaFunctionName]( - 'addBid', - liveyield.instanceConfig.getAdUnitName( - liveyield.instanceConfig.getPlacementOrAdUnitCode( - args, - prebidVersion - ) - ), - args.bidder || 'unknown', - cpmToMicroUSD(cpm), - typeof args.bidder === 'undefined', - args.statusMessage !== 'Bid available' - ); - } catch (e) { - logError(e); - } - break; - case BID_TIMEOUT: - window[liveyield.instanceConfig.rtaFunctionName]( - 'biddersTimeout', - args - ); - break; - case BID_WON: - liveyield.instanceConfig.prebidWinnersCache[args.adId] = args; - if (liveyield.instanceConfig.googlePublisherTag) { - break; - } - - try { - const ad = liveyield.instanceConfig.getAdUnitName( - liveyield.instanceConfig.getPlacementOrAdUnitCode( - args, - prebidVersion - ) - ); - if (!ad) { - logError( - 'Cannot find ad by unit name: ' + - liveyield.instanceConfig.getAdUnitName( - liveyield.instanceConfig.getPlacementOrAdUnitCode( - args, - prebidVersion - ) - ) - ); - break; - } - if (!args.bidderCode || !args.cpm) { - logError('Bidder code or cpm is not valid'); - break; - } - const resolution = { targetings: [] }; - resolution.prebidWon = true; - resolution.prebidPartner = args.bidderCode; - resolution.prebidValue = cpmToMicroUSD(parseFloat(args.cpm)); - const resolutionToUse = liveyield.instanceConfig.postProcessResolution( - resolution, - null, - resolution.prebidPartner, - resolution.prebidValue, - prebidVersion - ); - window[liveyield.instanceConfig.rtaFunctionName]( - 'resolveSlot', - liveyield.instanceConfig.getAdUnitName( - liveyield.instanceConfig.getPlacementOrAdUnitCode( - args, - prebidVersion - ) - ), - resolutionToUse - ); - } catch (e) { - logError(e); - } - break; - } - } -}); - -liveyield.originEnableAnalytics = liveyield.enableAnalytics; - -/** - * Minimal valid config: - * - * ``` - * { - * provider: 'liveyield', - * options: { - * // will be provided by the LiveYield team - * customerId: 'UUID', - * // will be provided by the LiveYield team, - * customerName: 'Customer Name', - * // do NOT use window.location.host, use constant value - * customerSite: 'Fixed Site Name', - * // this is used to be inline with GA 'sessionizer' which closes the session on midnight (EST-time). - * sessionTimezoneOffset: '-300' - * } - * } - * ``` - */ -liveyield.enableAnalytics = function(config) { - if (!config || !config.provider || config.provider !== 'liveyield') { - logError('expected config.provider to equal liveyield'); - return; - } - if (!config.options) { - logError('options must be defined'); - return; - } - if (!config.options.customerId) { - logError('options.customerId is required'); - return; - } - if (!config.options.customerName) { - logError('options.customerName is required'); - return; - } - if (!config.options.customerSite) { - logError('options.customerSite is required'); - return; - } - if (!config.options.sessionTimezoneOffset) { - logError('options.sessionTimezoneOffset is required'); - return; - } - liveyield.instanceConfig = Object.assign( - { prebidWinnersCache: {}, prebidBidResponsesCache: {} }, - adapterConfig, - config.options - ); - - if (typeof window[liveyield.instanceConfig.rtaFunctionName] !== 'function') { - logError( - `Function ${liveyield.instanceConfig.rtaFunctionName} is not defined.` + - `Make sure that LiveYield snippet in included before the Prebid Analytics configuration.` - ); - return; - } - if (liveyield.instanceConfig.googlePublisherTag) { - liveyield.instanceConfig.wireGooglePublisherTag( - liveyield.instanceConfig.googlePublisherTag, - onSlotRenderEnded(liveyield.instanceConfig) - ); - } - - const additionalParams = { - customerTimezone: config.options.customerTimezone, - contentId: config.options.contentId, - contentPart: config.options.contentPart, - contentAuthor: config.options.contentAuthor, - contentTitle: config.options.contentTitle, - contentCategory: config.options.contentCategory, - contentLayout: config.options.contentLayout, - contentVariants: config.options.contentVariants, - contentTimezone: config.options.contentTimezone, - cstringDim1: config.options.cstringDim1, - cstringDim2: config.options.cstringDim2, - cintDim1: config.options.cintDim1, - cintDim2: config.options.cintDim2, - cintArrayDim1: config.options.cintArrayDim1, - cintArrayDim2: config.options.cintArrayDim2, - cuniqueStringMet1: config.options.cuniqueStringMet1, - cuniqueStringMet2: config.options.cuniqueStringMet2, - cavgIntMet1: config.options.cavgIntMet1, - cavgIntMet2: config.options.cavgIntMet2, - csumIntMet1: config.options.csumIntMet1, - csumIntMet2: config.options.csumIntMet2 - }; - - Object.keys(additionalParams).forEach( - key => additionalParams[key] == null && delete additionalParams[key] - ); - - window[liveyield.instanceConfig.rtaFunctionName]( - 'create', - config.options.customerId, - config.options.customerName, - config.options.customerSite, - config.options.sessionTimezoneOffset, - additionalParams - ); - liveyield.originEnableAnalytics(config); -}; - -const onSlotRenderEnded = function(instanceConfig) { - const addDfpDetails = (resolution, slot) => { - const responseInformation = slot.getResponseInformation(); - if (responseInformation) { - resolution.dfpAdvertiserId = responseInformation.advertiserId; - resolution.dfpLineItemId = responseInformation.sourceAgnosticLineItemId; - resolution.dfpCreativeId = responseInformation.creativeId; - } - }; - - const addPrebidDetails = (resolution, slot) => { - if (instanceConfig.isPrebidAdImpression(slot)) { - resolution.prebidWon = true; - } - const highestPrebidAdImpPartner = instanceConfig.getHighestPrebidAdImpressionPartner( - instanceConfig, - slot, - prebidVersion - ); - const highestPrebidAdImpValue = instanceConfig.getHighestPrebidAdImpressionValue( - instanceConfig, - slot, - prebidVersion - ); - if (highestPrebidAdImpPartner) { - resolution.prebidPartner = highestPrebidAdImpPartner; - } - if (highestPrebidAdImpValue) { - resolution.prebidValue = cpmToMicroUSD( - parseFloat(highestPrebidAdImpValue) - ); - } - }; - return slot => { - const resolution = { targetings: [] }; - - addDfpDetails(resolution, slot); - addPrebidDetails(resolution, slot); - - const resolutionToUse = instanceConfig.postProcessResolution( - resolution, - slot, - resolution.highestPrebidAdImpPartner, - resolution.highestPrebidAdImpValue, - prebidVersion - ); - window[instanceConfig.rtaFunctionName]( - 'resolveSlot', - instanceConfig.getAdUnitNameByGooglePublisherTagSlot(slot, prebidVersion), - resolutionToUse - ); - }; -}; - -adapterManager.registerAnalyticsAdapter({ - adapter: liveyield, - code: 'liveyield' -}); - -export default liveyield; diff --git a/modules/liveyieldAnalyticsAdapter.md b/modules/liveyieldAnalyticsAdapter.md deleted file mode 100644 index a5e602361a1..00000000000 --- a/modules/liveyieldAnalyticsAdapter.md +++ /dev/null @@ -1,45 +0,0 @@ -# Overview - -Module Name: LiveYield Analytics Adapter - -Module Type: Analytics Adapter - -Maintainer: liveyield@pubocean.com - -# Description - -To install the LiveYield Tracker following snippet shall be added at the top of -the page. - -``` -(function(i,s,o,g,r,a,m,z){i['RTAAnalyticsObject']=r;i[r]=i[r]||function(){ -z=Array.prototype.slice.call(arguments);z.unshift(+new Date()); -(i[r].q=i[r].q||[]).push(z)},i[r].t=1,i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','https://rta.pubocean.com/lib/pubocean-tracker.min.js','rta'); -``` - -# Test Parameters - -The LiveYield team will provide you configurations for each of your sites, it -will be similar to: - -``` -{ - provider: 'liveyield', - options: { - // will be provided by the LiveYield team - customerId: 'UUID', - // will be provided by the LiveYield team, - customerName: 'Customer Name', - // do NOT use window.location.host, use constant value - customerSite: 'Fixed Site Name', - // this is used to be inline with GA 'sessionizer' which closes the session on midnight (EST-time). - sessionTimezoneOffset: '-300' - } -} -``` - -Additional documentation and support will be provided by the LiveYield team as -part of the onboarding process. - diff --git a/test/spec/modules/glimpseBidAdapter_spec.js b/test/spec/modules/glimpseBidAdapter_spec.js deleted file mode 100644 index 353e61c7859..00000000000 --- a/test/spec/modules/glimpseBidAdapter_spec.js +++ /dev/null @@ -1,422 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/glimpseBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config'; -import { BANNER } from '../../../src/mediaTypes'; - -const ENDPOINT = 'https://market.glimpsevault.io/public/v1/prebid'; - -const nonStringValues = [null, undefined, 123, true, {}, [], () => {}]; -const nonArrayValues = [null, undefined, 123, true, {}, 'str', () => {}]; - -const mock = { - bidRequest: { - bidder: 'glimpse', - bidId: '26a80b71cfd671', - bidderRequestId: '133baeded6ac94', - auctionId: '96692a73-307b-44b8-8e4f-ddfb40341570', - adUnitCode: 'banner-div-a', - sizes: [[300, 250]], - params: { - pid: 'glimpse-demo-300x250', - }, - }, - bidderRequest: { - bidderCode: 'glimpse', - bidderRequestId: '133baeded6ac94', - auctionId: '96692a73-307b-44b8-8e4f-ddfb40341570', - timeout: 3000, - gdprConsent: { - consentString: - 'COzP517OzP517AcABBENAlCsAP_AAAAAAAwIF8NX-T5eL2vju2Zdt7JEaYwfZxyigOgThgQIsW8NwIeFbBoGP2EgHBG4JCQAGBAkkgCBAQMsHGBcCQAAgIgRiRKMYE2MjzNKBJJAigkbc0FACDVunsHS2ZCY70-8O__bPAviADAvUC-AAAAA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - }, - uspConsent: '1YYY', - refererInfo: { - numIframes: 0, - reachedTop: true, - page: 'https://demo.glimpseprotocol.io/prebid/desktop', - stack: ['https://demo.glimpseprotocol.io/prebid/desktop'], - }, - }, - bidResponse: { - auth: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJoZWxsbyI6IndvcmxkISJ9.1p6T0ORhJ6riLprhXBGdzRhG3Q1egM27uFhPGNapPxs', - data: { - bids: [ - { - requestId: '133baeded6ac94', - creativeId: 'glimpse-demo-300x250', - adUnitCode: 'banner-div-a', - currency: 'GBP', - ad: '
Hello, World!
', - width: 300, - height: 250, - cpm: 1.04, - netRevenue: true, - mediaType: 'banner', - ttl: 300, - }, - ], - }, - }, -}; - -const getBidRequest = () => getDeepCopy(mock.bidRequest); -const getBidderRequest = () => ({ - bids: [getBidRequest()], - ...getDeepCopy(mock.bidderRequest), -}); - -const getBidResponse = () => ({ - body: getDeepCopy(mock.bidResponse), -}); - -function getDeepCopy(object) { - return JSON.parse(JSON.stringify(object)); -} - -describe('GlimpseProtocolAdapter', () => { - const glimpseAdapter = newBidder(spec); - - describe('spec', () => { - it('Has defined the glimpse gvlid', () => { - expect(spec.gvlid).to.equal(1012); - }); - - it('Has defined glimpse as the bidder', () => { - expect(spec.code).to.equal('glimpse'); - }); - - it('Has defined valid mediaTypes', () => { - expect(spec.supportedMediaTypes).to.deep.equal([BANNER]); - }); - }); - - describe('Inherited functions', () => { - it('Functions exist and are valid types', () => { - expect(glimpseAdapter.callBids).to.exist.and.to.be.a('function'); - expect(glimpseAdapter.getSpec).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('Returns true if placement id is non-empty string', () => { - const bidRequest = getBidRequest(); - - const isValidBidRequest = spec.isBidRequestValid(bidRequest); - expect(isValidBidRequest).to.be.true; - }); - - it('Returns false if no pid is provided', () => { - const bidRequest = getBidRequest(); - delete bidRequest.params.pid; - - const isValidBidRequest = spec.isBidRequestValid(bidRequest); - expect(isValidBidRequest).to.be.false; - }); - - it('Returns false if pid is empty string', () => { - const bidRequest = getBidRequest(); - bidRequest.params.pid = ''; - - const isValidBidRequest = spec.isBidRequestValid(bidRequest); - expect(isValidBidRequest).to.be.false; - }); - - it('Returns false if pid is not string', () => { - const bidRequest = getBidRequest(); - const invalidPids = nonStringValues; - - invalidPids.forEach((invalidPid) => { - bidRequest.params.pid = invalidPid; - const isValidBidRequest = spec.isBidRequestValid(bidRequest); - expect(isValidBidRequest).to.be.false; - }); - }); - }); - - describe('buildRequests', () => { - const bidRequests = [getBidRequest()]; - const bidderRequest = getBidderRequest(); - - it('Adds additional info to api request query', () => { - const request = spec.buildRequests(bidRequests, bidderRequest); - const url = new URL(request.url); - const queries = new URLSearchParams(url.search); - - expect(queries.get('ver')).to.exist; - expect(queries.get('tmax')).to.exist; - expect(queries.get('gdpr')).to.equal( - bidderRequest.gdprConsent.consentString - ); - expect(queries.get('ccpa')).to.equal(bidderRequest.uspConsent); - }); - - it('Has correct payload shape', () => { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.auth).to.be.a('string'); - expect(payload.data).to.be.an('object'); - expect(payload.data.referer).to.be.a('string'); - expect(payload.data.imp).to.be.an('array'); - expect(payload.data.fpd).to.be.an('object'); - }); - - it('Has referer information', () => { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - const expected = mock.bidderRequest.refererInfo.page; - - expect(payload.data.referer).to.equal(expected); - }); - - it('Has correct bids (imp) shape', () => { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - const imp = payload.data.imp; - - imp.forEach((i) => { - expect(i.bid).to.be.a('string'); - expect(i.pid).to.be.a('string'); - expect(i.sizes).to.be.an('array').that.deep.include([300, 250]); - }); - }); - }); - - describe('interpretResponse', () => { - it('Returns valid bids', () => { - const bidResponse = getBidResponse(); - const bids = spec.interpretResponse(bidResponse); - - expect(bids).to.have.lengthOf(1); - expect(bids[0].adUnitCode).to.equal(mock.bidRequest.adUnitCode); - }); - - it('Returns no bids if auth is not string', () => { - const bidResponse = getBidResponse(); - const invalidAuths = nonStringValues; - - invalidAuths.forEach((invalidAuth) => { - bidResponse.body.auth = invalidAuth; - - const bids = spec.interpretResponse(bidResponse); - expect(bids).to.have.lengthOf(0); - }); - }); - - it('Returns no bids if bids is empty', () => { - const bidResponse = getBidResponse(); - bidResponse.body.data.bids = []; - - const bids = spec.interpretResponse(bidResponse); - expect(bids).to.have.lengthOf(0); - }); - - it('Returns no bids if bids is not array', () => { - const bidResponse = getBidResponse(); - const invalidBids = nonArrayValues; - - invalidBids.forEach((invalidBid) => { - bidResponse.body.data.bids = invalidBid; - - const bids = spec.interpretResponse(bidResponse); - expect(bids).to.have.lengthOf(0); - }); - }); - - it('Contains advertiserDomains', () => { - const bidResponse = getBidResponse(); - - const bids = spec.interpretResponse(bidResponse); - bids.forEach((bid) => { - expect(bid.meta.advertiserDomains).to.be.an('array'); - }); - }); - }); - - describe('optimize request fpd data', () => { - const bidRequests = [getBidRequest()]; - const bidderRequest = getBidderRequest(); - - const fpdMockBase = { - site: { - keywords: 'site,keywords', - ext: { - data: { - fpdProvider: { - dataArray: ['data1', 'data2'], - dataObject: { - data1: 'data1', - data2: 'data2', - }, - dataString: 'data1,data2', - }, - }, - }, - }, - user: { - keywords: 'user,keywords', - ext: { - data: { - fpdProvider: { - dataArray: ['data1', 'data2'], - dataObject: { - data1: 'data1', - data2: 'data2', - }, - dataString: 'data1,data2', - }, - }, - }, - }, - }; - - it('should keep all non-empty fields', () => { - const fpdMock = fpdMockBase; - const expected = fpdMockBase; - - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: fpdMock}); - const payload = JSON.parse(request.data); - const fpd = payload.data.fpd; - - expect(fpd).to.deep.equal(expected); - }); - - it('should remove all empty objects', () => { - const fpdMock = getDeepCopy(fpdMockBase); - fpdMock.site.ext.data.fpdProvider.dataObject = {}; - fpdMock.user.ext.data.fpdProvider = {}; - - const expected = { - site: { - keywords: 'site,keywords', - ext: { - data: { - fpdProvider: { - dataArray: ['data1', 'data2'], - dataString: 'data1,data2', - }, - }, - }, - }, - user: { - keywords: 'user,keywords', - }, - }; - - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: fpdMock}); - const payload = JSON.parse(request.data); - const fpd = payload.data.fpd; - - expect(fpd).to.deep.equal(expected); - }); - - it('should remove all empty arrays', () => { - const fpdMock = getDeepCopy(fpdMockBase); - fpdMock.site.ext.data.fpdProvider.dataArray = []; - fpdMock.user.ext.data.fpdProvider.dataArray = []; - - const expected = { - site: { - keywords: 'site,keywords', - ext: { - data: { - fpdProvider: { - dataObject: { - data1: 'data1', - data2: 'data2', - }, - dataString: 'data1,data2', - }, - }, - }, - }, - user: { - keywords: 'user,keywords', - ext: { - data: { - fpdProvider: { - dataObject: { - data1: 'data1', - data2: 'data2', - }, - dataString: 'data1,data2', - }, - }, - }, - }, - }; - - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: fpdMock}); - const payload = JSON.parse(request.data); - const fpd = payload.data.fpd; - - expect(fpd).to.deep.equal(expected); - }); - - it('should remove all empty strings', () => { - const fpdMock = getDeepCopy(fpdMockBase); - fpdMock.site.keywords = ''; - fpdMock.site.ext.data.fpdProvider.dataString = ''; - fpdMock.user.keywords = ''; - fpdMock.user.ext.data.fpdProvider.dataString = ''; - - const expected = { - site: { - ext: { - data: { - fpdProvider: { - dataArray: ['data1', 'data2'], - dataObject: { - data1: 'data1', - data2: 'data2', - }, - }, - }, - }, - }, - user: { - ext: { - data: { - fpdProvider: { - dataArray: ['data1', 'data2'], - dataObject: { - data1: 'data1', - data2: 'data2', - }, - }, - }, - }, - }, - }; - - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: fpdMock}); - const payload = JSON.parse(request.data); - const fpd = payload.data.fpd; - - expect(fpd).to.deep.equal(expected); - }); - - it('should remove all empty fields', () => { - const fpdMock = getDeepCopy(fpdMockBase); - fpdMock.site.keywords = ''; - fpdMock.site.ext.data.fpdProvider.dataArray = []; - fpdMock.site.ext.data.fpdProvider.dataObject = {}; - fpdMock.site.ext.data.fpdProvider.dataString = ''; - fpdMock.user.keywords = ''; - fpdMock.user.ext.data.fpdProvider.dataArray = []; - fpdMock.user.ext.data.fpdProvider.dataObject = {}; - fpdMock.user.ext.data.fpdProvider.dataString = ''; - - const expected = {}; - - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: fpdMock}); - const payload = JSON.parse(request.data); - const fpd = payload.data.fpd; - - expect(fpd).to.deep.equal(expected); - }); - }); -}); diff --git a/test/spec/modules/liveyieldAnalyticsAdapter_spec.js b/test/spec/modules/liveyieldAnalyticsAdapter_spec.js deleted file mode 100644 index 9ec4eaf9acd..00000000000 --- a/test/spec/modules/liveyieldAnalyticsAdapter_spec.js +++ /dev/null @@ -1,704 +0,0 @@ -import CONSTANTS from 'src/constants.json'; -import liveyield from 'modules/liveyieldAnalyticsAdapter.js'; -import { expect } from 'chai'; -const events = require('src/events'); - -const { - EVENTS: { BID_REQUESTED, BID_TIMEOUT, BID_RESPONSE, BID_WON } -} = CONSTANTS; - -describe('liveyield analytics adapter', function() { - const rtaCalls = []; - - window.rta = function() { - rtaCalls.push({ callArgs: arguments }); - }; - - beforeEach(function() { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(function() { - events.getEvents.restore(); - }); - - describe('initialization', function() { - afterEach(function() { - rtaCalls.length = 0; - }); - it('it should require provider', function() { - liveyield.enableAnalytics({}); - expect(rtaCalls).to.be.empty; - }); - it('should require config.options', function() { - liveyield.enableAnalytics({ provider: 'liveyield' }); - expect(rtaCalls).to.be.empty; - }); - it('should require options.customerId', function() { - liveyield.enableAnalytics({ provider: 'liveyield', options: {} }); - expect(rtaCalls).to.be.empty; - }); - it('should require options.customerName', function() { - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa' - } - }); - expect(rtaCalls).to.be.empty; - }); - it('should require options.customerSite', function() { - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean' - } - }); - expect(rtaCalls).to.be.empty; - }); - it('should require options.sessionTimezoneOffset', function() { - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com' - } - }); - expect(rtaCalls).to.be.empty; - }); - it("should throw error, when 'rta' function is not defined ", function() { - const keepMe = window.rta; - - delete window.rta; - - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12 - } - }); - expect(rtaCalls).to.be.empty; - - window.rta = keepMe; - }); - it('should initialize when all required parameters are passed', function() { - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12 - } - }); - expect(rtaCalls[0].callArgs['0']).to.match(/create/); - expect(rtaCalls[0].callArgs['1']).to.match( - /d6a6f8da-190f-47d6-ae11-f1a4469083fa/ - ); - expect(rtaCalls[0].callArgs['2']).to.match(/pubocean/); - expect(rtaCalls[0].callArgs['4']).to.match(/12/); - liveyield.disableAnalytics(); - }); - it('should allow to redefine rta function name', function() { - const keepMe = window.rta; - window.abc = keepMe; - delete window.rta; - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - rtaFunctionName: 'abc', - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'test', - customerSite: 'scribol.com', - sessionTimezoneOffset: 25 - } - }); - - liveyield.disableAnalytics(); - expect(rtaCalls[0].callArgs['0']).to.match(/create/); - expect(rtaCalls[0].callArgs['1']).to.match( - /d6a6f8da-190f-47d6-ae11-f1a4469083fa/ - ); - expect(rtaCalls[0].callArgs['2']).to.match(/test/); - expect(rtaCalls[0].callArgs['4']).to.match(/25/); - - window.rta = keepMe; - liveyield.disableAnalytics(); - }); - it('should handle custom parameters', function() { - liveyield.enableAnalytics({ - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'test2', - customerSite: 'scribol.com', - sessionTimezoneOffset: 38, - contentTitle: 'testTitle', - contentAuthor: 'testAuthor', - contentCategory: 'testCategory' - } - }); - - liveyield.disableAnalytics(); - expect(rtaCalls[0].callArgs['0']).to.match(/create/); - expect(rtaCalls[0].callArgs['2']).to.match(/test2/); - expect(rtaCalls[0].callArgs['4']).to.match(/38/); - expect(rtaCalls[0].callArgs['5'].contentTitle).to.match(/testTitle/); - expect(rtaCalls[0].callArgs['5'].contentAuthor).to.match(/testAuthor/); - expect(rtaCalls[0].callArgs['5'].contentCategory).to.match( - /testCategory/ - ); - liveyield.disableAnalytics(); - }); - }); - - describe('handling events', function() { - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12 - } - }; - beforeEach(function() { - rtaCalls.length = 0; - liveyield.enableAnalytics(options); - }); - afterEach(function() { - liveyield.disableAnalytics(); - }); - it('should handle BID_REQUESTED event', function() { - const bidRequest = { - bidderCode: 'appnexus', - bids: [ - { - params: { - placementId: '10433394' - }, - adUnitCode: 'div-gpt-ad-1438287399331-0', - transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - sizes: '300x250,300x600', - bidId: '2eddfdc0c791dc', - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7' - } - ] - }; - - events.emit(BID_REQUESTED, bidRequest); - - expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); - expect(rtaCalls[1].callArgs['1']).to.equal('div-gpt-ad-1438287399331-0'); - expect(rtaCalls[1].callArgs['2']).to.equal('appnexus'); - }); - it('should handle BID_REQUESTED event with invalid args', function() { - const bidRequest = { - bids: [ - { - params: { - placementId: '10433394' - }, - transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - sizes: '300x250,300x600', - bidId: '2eddfdc0c791dc', - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcf' - }, - { - params: { - placementId: '31034023' - }, - transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - sizes: '300x250,300x600', - bidId: '3dkg0404fmd0', - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcf' - } - ] - }; - events.emit(BID_REQUESTED, bidRequest); - expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); - expect(rtaCalls[1].callArgs['1']).to.equal(undefined); - expect(rtaCalls[1].callArgs['2']).to.equal(undefined); - expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); - }); - it('should handle BID_RESPONSE event', function() { - const bidResponse = { - height: 250, - statusMessage: 'Bid available', - adId: '2eddfdc0c791dc', - mediaType: 'banner', - source: 'client', - requestId: '2eddfdc0c791dc', - cpm: 0.5, - creativeId: 29681110, - currency: 'USD', - netRevenue: true, - ttl: 300, - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', - responseTimestamp: 1522265866110, - requestTimestamp: 1522265863600, - bidder: 'appnexus', - adUnitCode: 'div-gpt-ad-1438287399331-0', - timeToRespond: 2510, - size: '300x250' - }; - - events.emit(BID_RESPONSE, bidResponse); - expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); - expect(rtaCalls[1].callArgs['1']).to.equal('div-gpt-ad-1438287399331-0'); - expect(rtaCalls[1].callArgs['2']).to.equal('appnexus'); - expect(rtaCalls[1].callArgs['3']).to.equal(500); - expect(rtaCalls[1].callArgs['4']).to.equal(false); - expect(rtaCalls[1].callArgs['5']).to.equal(false); - }); - it('should handle BID_RESPONSE event with undefined bidder and cpm', function() { - const bidResponse = { - height: 250, - statusMessage: 'Bid available', - adId: '2eddfdc0c791dc', - mediaType: 'banner', - source: 'client', - requestId: '2eddfdc0c791dc', - creativeId: 29681110, - currency: 'USD', - netRevenue: true, - ttl: 300, - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', - responseTimestamp: 1522265866110, - requestTimestamp: 1522265863600, - adUnitCode: 'div-gpt-ad-1438287399331-0', - timeToRespond: 2510, - size: '300x250' - }; - events.emit(BID_RESPONSE, bidResponse); - expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); - expect(rtaCalls[1].callArgs['2']).to.equal('unknown'); - expect(rtaCalls[1].callArgs['3']).to.equal(0); - expect(rtaCalls[1].callArgs['4']).to.equal(true); - }); - it('should handle BID_RESPONSE event with undefined status message and adUnitCode', function() { - const bidResponse = { - height: 250, - adId: '2eddfdc0c791dc', - mediaType: 'banner', - source: 'client', - requestId: '2eddfdc0c791dc', - cpm: 0.5, - creativeId: 29681110, - currency: 'USD', - netRevenue: true, - ttl: 300, - auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', - responseTimestamp: 1522265866110, - requestTimestamp: 1522265863600, - bidder: 'appnexus', - timeToRespond: 2510, - size: '300x250' - }; - events.emit(BID_RESPONSE, bidResponse); - expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); - expect(rtaCalls[1].callArgs['1']).to.equal(undefined); - expect(rtaCalls[1].callArgs['3']).to.equal(0); - expect(rtaCalls[1].callArgs['5']).to.equal(true); - }); - it('should handle BID_TIMEOUT', function() { - const bidTimeout = [ - { - bidId: '2baa51527bd015', - bidder: 'bidderOne', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - }, - { - bidId: '6fe3b4c2c23092', - bidder: 'bidderTwo', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - } - ]; - events.emit(BID_TIMEOUT, bidTimeout); - expect(rtaCalls[1].callArgs['0']).to.equal('biddersTimeout'); - expect(rtaCalls[1].callArgs['1'].length).to.equal(2); - }); - it('should handle BID_WON event', function() { - const bidWon = { - adId: '4587fec4900b81', - mediaType: 'banner', - requestId: '4587fec4900b81', - cpm: 1.962, - creativeId: 2126, - currency: 'EUR', - netRevenue: true, - ttl: 302, - auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', - statusMessage: 'Bid available', - responseTimestamp: 1530628534437, - requestTimestamp: 1530628534219, - bidderCode: 'testbidder4', - adUnitCode: 'div-gpt-ad-1438287399331-0', - timeToRespond: 218, - size: '300x250', - status: 'rendered' - }; - events.emit(BID_WON, bidWon); - expect(rtaCalls[1].callArgs['0']).to.equal('resolveSlot'); - expect(rtaCalls[1].callArgs['1']).to.equal('div-gpt-ad-1438287399331-0'); - expect(rtaCalls[1].callArgs['2'].prebidWon).to.equal(true); - expect(rtaCalls[1].callArgs['2'].prebidPartner).to.equal('testbidder4'); - expect(rtaCalls[1].callArgs['2'].prebidValue).to.equal(1962); - }); - it('should throw error, invoking BID_WON event without adUnitCode', function() { - const bidWon = { - adId: '4587fec4900b81', - mediaType: 'banner', - requestId: '4587fec4900b81', - cpm: 1.962, - creativeId: 2126, - currency: 'EUR', - netRevenue: true, - ttl: 302, - auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', - statusMessage: 'Bid available', - responseTimestamp: 1530628534437, - requestTimestamp: 1530628534219, - timeToRespond: 218, - bidderCode: 'testbidder4', - size: '300x250', - status: 'rendered' - }; - events.emit(BID_WON, bidWon); - expect(rtaCalls[1]).to.be.undefined; - }); - it('should throw error, invoking BID_WON event without bidderCode', function() { - const bidWon = { - adId: '4587fec4900b81', - mediaType: 'banner', - requestId: '4587fec4900b81', - cpm: 1.962, - creativeId: 2126, - currency: 'EUR', - netRevenue: true, - ttl: 302, - auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', - statusMessage: 'Bid available', - responseTimestamp: 1530628534437, - requestTimestamp: 1530628534219, - adUnitCode: 'div-gpt-ad-1438287399331-0', - timeToRespond: 218, - size: '300x250', - status: 'rendered' - }; - events.emit(BID_WON, bidWon); - expect(rtaCalls[1]).to.be.undefined; - }); - }); - - describe('googletag use case', function() { - beforeEach(function() { - rtaCalls.length = 0; - }); - afterEach(function() { - liveyield.disableAnalytics(); - }); - it('should ignore BID_WON events when gpt is provided', function() { - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: true, - wireGooglePublisherTag: function() { - return null; - } - } - }; - liveyield.enableAnalytics(options); - - const bidWon = { - adId: 'ignore_me', - mediaType: 'banner', - requestId: '4587fec4900b81', - cpm: 1.962, - creativeId: 2126, - currency: 'EUR', - netRevenue: true, - ttl: 302, - auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', - statusMessage: 'Bid available', - responseTimestamp: 1530628534437, - requestTimestamp: 1530628534219, - bidderCode: 'hello', - adUnitCode: 'div-gpt-ad-1438287399331-0', - timeToRespond: 218, - size: '300x250', - status: 'rendered' - }; - events.emit(BID_WON, bidWon); - - expect(rtaCalls.length).to.equal(1); - }); - it('should subscribe to slotRenderEnded', function() { - var googletag; - var callback; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: function(gpt, cb) { - googletag = gpt; - callback = cb; - } - } - }; - liveyield.enableAnalytics(options); - expect(googletag).to.equal('testGPT'); - expect(typeof callback).to.equal('function'); - }); - it('should handle BID_WON event for prebid', function() { - var call; - const slot = { - getResponseInformation: function() { - const dfpInfo = { - dfpAdvertiserId: 1, - dfpLineItemId: 2, - dfpCreativeId: 3 - }; - return dfpInfo; - }, - getTargeting: function(v) { - return ['4587fec4900b81']; - } - }; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: function(gpt, cb) { - call = cb; - }, - getHighestPrebidAdImpressionPartner: function(slot, version) { - return 'testbidder4'; - }, - getHighestPrebidAdImpressionValue: function(slot, version) { - return 12; - }, - postProcessResolution: function( - resolution, - slot, - hbPartner, - hbValue, - version - ) { - return resolution; - }, - getAdUnitNameByGooglePublisherTagSlot: function(slot, version) { - return 'testUnit'; - } - } - }; - liveyield.enableAnalytics(options); - const bidWon = { - adId: '4587fec4900b81' - }; - events.emit(BID_WON, bidWon); - call(slot); - expect(rtaCalls[1].callArgs['2'].prebidWon).to.equal(true); - expect(rtaCalls[1].callArgs['2'].prebidPartner).to.equal('testbidder4'); - }); - it('should handle BID_WON event for dfp', function() { - let call; - const slot = { - getResponseInformation: function() { - const dfpInfo = { - dfpAdvertiserId: 1, - dfpLineItemId: 2, - dfpCreativeId: 3 - }; - return dfpInfo; - } - }; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: function(gpt, cb) { - call = cb; - }, - getHighestPrebidAdImpressionPartner: function(slot, version) { - return 'testbidder4'; - }, - getHighestPrebidAdImpressionValue: function(slot, version) { - return 12; - }, - postProcessResolution: function(slot, version) { - return { partner: slot.prebidPartner, value: slot.prebidValue }; - }, - getAdUnitNameByGooglePublisherTagSlot: function(slot, version) { - return 'testUnit'; - }, - isPrebidAdImpression: function(slot) { - return true; - } - } - }; - liveyield.enableAnalytics(options); - call(slot); - expect(rtaCalls.length).to.equal(2); - expect(rtaCalls[1].callArgs[0]).to.equal('resolveSlot'); - expect(rtaCalls[1].callArgs[1]).to.equal('testUnit'); - expect(rtaCalls[1].callArgs[2].partner).to.equal('testbidder4'); - expect(rtaCalls[1].callArgs[2].value).to.equal(12000); - }); - it('should work with defaults: prebid won', () => { - let call; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: (gpt, cb) => (call = cb), - getAdUnitName: adUnitCode => - adUnitCode === 'PREBID_UNIT' ? 'ADUNIT' : null, - getAdUnitNameByGooglePublisherTagSlot: slot => - slot.getSlotElementId() === 'div-gpt-ad-1438287399331-0' - ? 'ADUNIT' - : null - } - }; - liveyield.enableAnalytics(options); - - const bidResponse = { - adId: 'defaults_with_cache', - statusMessage: 'Bid available', - cpm: 0.5, - bidder: 'appnexus', - adUnitCode: 'PREBID_UNIT' - }; - events.emit(BID_RESPONSE, bidResponse); - - const bidWon = { - adId: bidResponse.adId, - cpm: 1.962, // adjusted, this one shall be used, not the one from bidResponse - bidderCode: 'appnexus_from_bid_won_event', - adUnitCode: 'PREBID_UNIT' - }; - events.emit(BID_WON, bidWon); - - const slot = { - getTargeting: key => (key === 'hb_adid' ? [bidResponse.adId] : []), - getResponseInformation: () => null, - getSlotElementId: () => 'div-gpt-ad-1438287399331-0' - }; - call(slot); - - expect(rtaCalls[2].callArgs[0]).to.equal('resolveSlot'); - expect(rtaCalls[2].callArgs[1]).to.equal('ADUNIT'); - expect(rtaCalls[2].callArgs[2]).to.deep.equal({ - targetings: [], - prebidWon: true, - prebidPartner: 'appnexus_from_bid_won_event', - prebidValue: 1962 - }); - }); - it('should work with defaults: dfp won, prebid bid response', () => { - let call; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: (gpt, cb) => (call = cb), - getAdUnitName: adUnitCode => - adUnitCode === 'PREBID_UNIT' ? 'ADUNIT' : null, - getAdUnitNameByGooglePublisherTagSlot: slot => - slot.getSlotElementId() === 'div-gpt-ad-1438287399331-0' - ? 'ADUNIT' - : null - } - }; - liveyield.enableAnalytics(options); - - const bidResponse = { - adId: 'defaults_with_cache_no_prebid_win', - statusMessage: 'Bid available', - cpm: 0.5, - bidder: 'appnexus', - adUnitCode: 'PREBID_UNIT' - }; - events.emit(BID_RESPONSE, bidResponse); - - const slot = { - getTargeting: key => (key === 'hb_adid' ? [bidResponse.adId] : []), - getResponseInformation: () => null, - getSlotElementId: () => 'div-gpt-ad-1438287399331-0' - }; - call(slot); - - expect(rtaCalls[2].callArgs[0]).to.equal('resolveSlot'); - expect(rtaCalls[2].callArgs[1]).to.equal('ADUNIT'); - expect(rtaCalls[2].callArgs[2]).to.deep.equal({ - targetings: [], - prebidPartner: 'appnexus', - prebidValue: 500 - }); - }); - it('should work with defaults: dfp won, without prebid', () => { - let call; - const options = { - provider: 'liveyield', - options: { - customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', - customerName: 'pubocean', - customerSite: 'scribol.com', - sessionTimezoneOffset: 12, - googlePublisherTag: 'testGPT', - wireGooglePublisherTag: (gpt, cb) => (call = cb), - getAdUnitName: adUnitCode => - adUnitCode === 'PREBID_UNIT' ? 'ADUNIT' : null, - getAdUnitNameByGooglePublisherTagSlot: slot => - slot.getSlotElementId() === 'div-gpt-ad-1438287399331-0' - ? 'ADUNIT' - : null - } - }; - liveyield.enableAnalytics(options); - - const slot = { - getTargeting: key => (key === 'hb_adid' ? ['does-not-exist'] : []), - getResponseInformation: () => null, - getSlotElementId: () => 'div-gpt-ad-1438287399331-0' - }; - call(slot); - - expect(rtaCalls[1].callArgs[0]).to.equal('resolveSlot'); - expect(rtaCalls[1].callArgs[1]).to.equal('ADUNIT'); - expect(rtaCalls[1].callArgs[2]).to.deep.equal({ - targetings: [] - }); - }); - }); -});