diff --git a/modules/.submodules.json b/modules/.submodules.json index fc69dd276a3..54da15ca438 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -30,6 +30,7 @@ "browsiRtdProvider", "haloRtdProvider", "jwplayerRtdProvider", + "pubwiseRtdProvider", "reconciliationRtdProvider", "geoedgeRtdProvider" ] diff --git a/modules/pubwiseAnalyticsAdapter.js b/modules/pubwiseAnalyticsAdapter.js index fe217454b88..9858bcce1c7 100644 --- a/modules/pubwiseAnalyticsAdapter.js +++ b/modules/pubwiseAnalyticsAdapter.js @@ -252,6 +252,18 @@ function filterAuctionInit(data) { return modified; } +function filterBidRequested(data) { + let modified = Object.assign({}, data); + + if (typeof modified.gdprConsent !== 'undefined') { + delete modified.gdprConsent; // not tracking through this channel currently + } + + modified.gdprConsent = {}; + + return modified; +} + let pubwiseAnalytics = Object.assign(adapter({analyticsType}), { // Override AnalyticsAdapter functions by supplying custom methods track({eventType, args}) { @@ -279,6 +291,8 @@ pubwiseAnalytics.handleEvent = function(eventType, data) { data = filterAuctionInit(data); } else if (eventType === CONSTANTS.EVENTS.BID_RESPONSE) { data = filterBidResponse(data); + } else if (eventType === CONSTANTS.EVENTS.BID_REQUESTED) { + data = filterBidRequested(data); } // add all ingested events diff --git a/modules/pubwiseRtdProvider.js b/modules/pubwiseRtdProvider.js new file mode 100644 index 00000000000..5be76c79313 --- /dev/null +++ b/modules/pubwiseRtdProvider.js @@ -0,0 +1,103 @@ +/** + * This module adds the PubWise.io provider to the Real Time Data module (rtdModule) + * The {@link module:modules/realTimeData} module is required + * The module allows page level traffic quality assessments as well as audience ad targeting information + * @requires module:modules/realTimeData + */ + +import * as utils from '../src/utils.js'; +import { submodule } from '../src/hook.js'; +import { getGlobal } from '../src/prebidGlobal.js'; +import { ajaxBuilder } from '../src/ajax.js'; + +let _moduleParams = {}; +let _assessmentData = {Quality: {Result: 0}}; +const LogPrepend = 'PubWise: '; + +function init(provider, userConsent) { + const win = window.top; + const doc = win.document; + + _moduleParams = provider.params; + if (_moduleParams && _moduleParams.siteId) { + let paramData = { + ...{ + siteId: _moduleParams.siteId, + pageUrl: `${doc.location.protocol}//${doc.location.host}${doc.location.pathname}`, + }, + ...(document.referrer ? {r: document.referrer} : {}), + ...(document.title ? {at: document.title} : {}) + }; + getAssessment(`${_moduleParams.endpoint}/traffic/quality/?${toUrlParams(paramData)}`); + } else { + utils.logError(LogPrepend + 'missing params for PubWise audience rtd module'); + } + return true; +} + +/** + * serialize object and return query params string + * @param {Object} data + * @return {string} + */ +function toUrlParams(data) { + return Object.keys(data) + .map(key => key + '=' + encodeURIComponent(data[key])) + .join('&'); +} + +function getAssessment(url) { + let ajax = ajaxBuilder(); + + ajax(url, + { + success: function (response, req) { + if (req.status === 200) { + try { + const data = JSON.parse(response); + if (data && data.Quality) { + setData({Quality: data.Quality}); + } else { + setData({Quality: {Result: 0}}); + } + } catch (err) { + utils.logError(LogPrepend + 'unable to parse assessment data'); + setData({Quality: {Result: 0}}) + } + } else if (req.status === 204) { + // unrecognized site key + setData({Quality: {Result: 0}}); + } + }, + error: function () { + setData({Quality: {Result: 0}}); + utils.logError(LogPrepend + 'unable to get assessment data'); + } + } + ); +} + +function setData(data) { + _assessmentData = data; +} + +function processBidRequestData(reqBidsConfigObj, onDone, config, userConsent) { + utils.logInfo(LogPrepend + 'Assessment Data', _assessmentData) + if (_assessmentData.Quality && _assessmentData.Quality.Result && _assessmentData.Quality.Result == 1) { + const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; + adUnits.forEach(adUnit => { + delete adUnit.bids; + }); + reqBidsConfigObj.adUnitCodes = {}; + reqBidsConfigObj.timeout = 1; + } + onDone(); +} + +export const pubwiseRtdSubmodule = { + name: 'pubwise', + init: init, + getBidRequestData: processBidRequestData +}; + +submodule('realTimeData', pubwiseRtdSubmodule); diff --git a/modules/pubwiseRtdProvider.md b/modules/pubwiseRtdProvider.md new file mode 100644 index 00000000000..e7dedfdbd32 --- /dev/null +++ b/modules/pubwiseRtdProvider.md @@ -0,0 +1,9 @@ +# Overview + +Module Name: PubWise Audience Provider +Module Type: Rtd Provider +Maintainer: support@pubwise.io + +# Description + +RTD Module for PubWise.io. Includes audience functionality, traffic quality assessment and more. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 330298cbaac..b494811f2e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "4.15.0-pre", + "version": "4.28.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index dc0a46844ca..ee060ad6cbf 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "header bidding", "prebid" ], - "globalVarName": "pbjs", + "globalVarName": "pwpbjs", "author": "the prebid.js contributors", "license": "Apache-2.0", "engines": {