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

CMP behaviour: events emits #11

Merged
merged 2 commits into from
Jun 15, 2018
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
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 @@ -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 });
}

/**
Expand Down Expand Up @@ -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);
}
}

/**
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 @@ -16,7 +16,8 @@ const {
BID_ADJUSTMENT,
BIDDER_DONE,
SET_TARGETING,
AD_RENDER_FAILED
AD_RENDER_FAILED,
CMP_UPDATE
}
} = CONSTANTS;

Expand Down Expand Up @@ -116,7 +117,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