Skip to content

Commit

Permalink
CMP behavior: events emits (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcobrunialtimrf authored and florevallatmrf committed Sep 6, 2018
1 parent a155a78 commit 20d0f32
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,6 +243,7 @@ function processCmpData(consentObject, hookConfig) {
*/
function cmpTimedOut(hookConfig) {
cmpFailed('CMP workflow exceeded timeout threshold.', hookConfig);
events.emit(EVENTS.CMP_UPDATE, { timeout: true });
}

/**
Expand Down Expand Up @@ -270,6 +273,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);
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions modules/marfeelAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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 auctions = {};

function auctionEnd(auction, {timedOut}) {
Expand All @@ -20,6 +22,10 @@ function auctionEnd(auction, {timedOut}) {
window.mrfpb && window.mrfpb.trackAuction(auction)
}

function registerCMPState(state) {
window.mrfpb && window.mrfpb.setCMPState && window.mrfpb.setCMPState(state);
}

function registerWinner(auction, args) {
window.mrfpb && window.mrfpb.trackAuctionWinner(auction, args)
}
Expand All @@ -41,6 +47,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);
}
},

Expand Down
6 changes: 4 additions & 2 deletions src/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const {
BID_ADJUSTMENT,
BIDDER_DONE,
SET_TARGETING,
AD_RENDER_FAILED
AD_RENDER_FAILED,
CMP_UPDATE
}
} = CONSTANTS;

Expand Down Expand Up @@ -110,7 +111,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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 20d0f32

Please sign in to comment.