From cf3a51ca36a1b5b0b69828110a48ca5128a3d2da Mon Sep 17 00:00:00 2001 From: gianmarcobrunialti Date: Thu, 14 Jun 2018 17:20:28 +0200 Subject: [PATCH 1/2] Emitting events for CMP --- modules/consentManagement.js | 8 ++++++++ modules/marfeelAnalyticsAdapter.js | 17 +++++++++++++++++ src/AnalyticsAdapter.js | 7 +++++-- src/constants.json | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/modules/consentManagement.js b/modules/consentManagement.js index af668523fa4..bae2e1511ea 100644 --- a/modules/consentManagement.js +++ b/modules/consentManagement.js @@ -6,9 +6,11 @@ */ import * as utils from 'src/utils'; import { config } from 'src/config'; +import events from 'src/events'; import { gdprDataHandler } from 'src/adaptermanager'; import includes from 'core-js/library/fn/array/includes'; import strIncludes from 'core-js/library/fn/string/includes'; +import { EVENTS } from 'src/constants'; const DEFAULT_CMP = 'iab'; const DEFAULT_CONSENT_TIMEOUT = 10000; @@ -237,6 +239,7 @@ function processCmpData(consentObject, hookConfig) { */ function cmpTimedOut(hookConfig) { cmpFailed('CMP workflow exceeded timeout threshold.', hookConfig); + events.emit(EVENTS.CMP_UPDATE, { timeout: true }); } /** @@ -265,6 +268,11 @@ function storeConsentData(cmpConsentObject) { gdprApplies: (cmpConsentObject) ? cmpConsentObject.getConsentData.gdprApplies : undefined }; gdprDataHandler.setConsentData(consentData); + + if (!!consentData.vendorData) { + consentData.vendorData.timeout = false; + } + events.emit(EVENTS.CMP_UPDATE, consentData.vendorData); } /** diff --git a/modules/marfeelAnalyticsAdapter.js b/modules/marfeelAnalyticsAdapter.js index 506f82f7d39..b1b98d7454c 100644 --- a/modules/marfeelAnalyticsAdapter.js +++ b/modules/marfeelAnalyticsAdapter.js @@ -12,6 +12,17 @@ let AUCTION_INIT = CONSTANTS.EVENTS.AUCTION_INIT; let AUCTION_END = CONSTANTS.EVENTS.AUCTION_END; let BID_WON = CONSTANTS.EVENTS.BID_WON; let BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; +let CONSENT_UPDATE = CONSTANTS.EVENTS.CMP_UPDATE; +let CONSENT_TIMEOUT = CONSTANTS.EVENTS.CMP_TIMEOUT; + +const TARGETINGS = { + notNeeded: 'withoutConsent', + accepted: 'consentAccepted', + rejected: 'consentRejected', + timeout: 'consentTimeout', + unknown: 'consentUnknown' +}; + let auctions = {}; function auctionEnd(auction, {timedOut}) { @@ -20,6 +31,10 @@ function auctionEnd(auction, {timedOut}) { window.mrfpb && window.mrfpb.trackAuction(auction) } +function registerCMPState(state) { + window.mrfpb && window.mrfpb.setCMPState(state); +} + function registerWinner(auction, args) { window.mrfpb && window.mrfpb.trackAuctionWinner(auction, args) } @@ -41,6 +56,8 @@ let marfeelAnalyticsAdapter = Object.assign(adapter({url, analyticsType}), registerWinner(auctions[args.auctionId], args); } else if (eventType === AUCTION_END) { auctionEnd(auctions[args.auctionId], args); + } else if (eventType === CONSENT_UPDATE) { + registerCMPState(args); } }, diff --git a/src/AnalyticsAdapter.js b/src/AnalyticsAdapter.js index 30848b341d8..8d799295366 100644 --- a/src/AnalyticsAdapter.js +++ b/src/AnalyticsAdapter.js @@ -16,7 +16,9 @@ const { BID_ADJUSTMENT, BIDDER_DONE, SET_TARGETING, - AD_RENDER_FAILED + AD_RENDER_FAILED, + CMP_TIMEOUT, + CMP_UPDATE } } = CONSTANTS; @@ -116,7 +118,8 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } [AUCTION_INIT]: args => { args.config = typeof config === 'object' ? config.options || {} : {}; // enableAnaltyics configuration object this.enqueue({ eventType: AUCTION_INIT, args }); - } + }, + [CMP_UPDATE]: args => this.enqueue({ eventType: CMP_UPDATE, args }) }; utils._each(_handlers, (handler, event) => { diff --git a/src/constants.json b/src/constants.json index c8a7c3ebefc..87e386cce24 100644 --- a/src/constants.json +++ b/src/constants.json @@ -35,7 +35,8 @@ "SET_TARGETING": "setTargeting", "REQUEST_BIDS": "requestBids", "ADD_AD_UNITS": "addAdUnits", - "AD_RENDER_FAILED" : "adRenderFailed" + "AD_RENDER_FAILED" : "adRenderFailed", + "CMP_UPDATE": "consentUpdate" }, "AD_RENDER_FAILED_REASON" : { "PREVENT_WRITING_ON_MAIN_DOCUMENT": "preventWritingOnMainDocuemnt", From 2aaa93865299b7dbe2feca0ac833ecf489ce71b6 Mon Sep 17 00:00:00 2001 From: gianmarcobrunialti Date: Fri, 15 Jun 2018 12:17:23 +0200 Subject: [PATCH 2/2] PR Comments --- modules/consentManagement.js | 2 +- modules/marfeelAnalyticsAdapter.js | 11 +---------- src/AnalyticsAdapter.js | 1 - 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/consentManagement.js b/modules/consentManagement.js index bae2e1511ea..01bd1b16dc2 100644 --- a/modules/consentManagement.js +++ b/modules/consentManagement.js @@ -271,8 +271,8 @@ function storeConsentData(cmpConsentObject) { if (!!consentData.vendorData) { consentData.vendorData.timeout = false; + events.emit(EVENTS.CMP_UPDATE, consentData.vendorData); } - events.emit(EVENTS.CMP_UPDATE, consentData.vendorData); } /** diff --git a/modules/marfeelAnalyticsAdapter.js b/modules/marfeelAnalyticsAdapter.js index b1b98d7454c..3dc8d978059 100644 --- a/modules/marfeelAnalyticsAdapter.js +++ b/modules/marfeelAnalyticsAdapter.js @@ -13,15 +13,6 @@ let AUCTION_END = CONSTANTS.EVENTS.AUCTION_END; let BID_WON = CONSTANTS.EVENTS.BID_WON; let BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; let CONSENT_UPDATE = CONSTANTS.EVENTS.CMP_UPDATE; -let CONSENT_TIMEOUT = CONSTANTS.EVENTS.CMP_TIMEOUT; - -const TARGETINGS = { - notNeeded: 'withoutConsent', - accepted: 'consentAccepted', - rejected: 'consentRejected', - timeout: 'consentTimeout', - unknown: 'consentUnknown' -}; let auctions = {}; @@ -32,7 +23,7 @@ function auctionEnd(auction, {timedOut}) { } function registerCMPState(state) { - window.mrfpb && window.mrfpb.setCMPState(state); + window.mrfpb && window.mrfpb.setCMPState && window.mrfpb.setCMPState(state); } function registerWinner(auction, args) { diff --git a/src/AnalyticsAdapter.js b/src/AnalyticsAdapter.js index 8d799295366..7dedefdc1e6 100644 --- a/src/AnalyticsAdapter.js +++ b/src/AnalyticsAdapter.js @@ -17,7 +17,6 @@ const { BIDDER_DONE, SET_TARGETING, AD_RENDER_FAILED, - CMP_TIMEOUT, CMP_UPDATE } } = CONSTANTS;