From f2905a86964a12dbcaeb11be41211b161e001887 Mon Sep 17 00:00:00 2001 From: Stephen Johnston Date: Mon, 1 Mar 2021 13:52:33 -0500 Subject: [PATCH 1/4] updates to add rtd module --- modules/.submodules.json | 1 + modules/pubwiseRtdProvider.js | 103 ++++++++++++++++++++++++++++++++++ modules/pubwiseRtdProvider.md | 9 +++ 3 files changed, 113 insertions(+) create mode 100644 modules/pubwiseRtdProvider.js create mode 100644 modules/pubwiseRtdProvider.md 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/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 From b34f1ddfe51a77247eaddf44f77efdd176f3723a Mon Sep 17 00:00:00 2001 From: Stephen Johnston Date: Mon, 1 Mar 2021 13:53:31 -0500 Subject: [PATCH 2/4] updates to add pwpbjs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From 775879fb80a2ce4c184bc827508953e01827ae77 Mon Sep 17 00:00:00 2001 From: Stephen Johnston Date: Fri, 12 Mar 2021 16:18:25 -0500 Subject: [PATCH 3/4] updates to remove gdprConsent --- modules/pubwiseAnalyticsAdapter.js | 12 ++++++++++++ package-lock.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/pubwiseAnalyticsAdapter.js b/modules/pubwiseAnalyticsAdapter.js index fe217454b88..8e4d69dd49a 100644 --- a/modules/pubwiseAnalyticsAdapter.js +++ b/modules/pubwiseAnalyticsAdapter.js @@ -252,6 +252,16 @@ 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 + } + + return modified; +} + let pubwiseAnalytics = Object.assign(adapter({analyticsType}), { // Override AnalyticsAdapter functions by supplying custom methods track({eventType, args}) { @@ -279,6 +289,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/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": { From 0e92d25ae7f4ec46ab97461878f26660cd23d6c6 Mon Sep 17 00:00:00 2001 From: Stephen Johnston Date: Fri, 12 Mar 2021 16:22:02 -0500 Subject: [PATCH 4/4] updates to handling --- modules/pubwiseAnalyticsAdapter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/pubwiseAnalyticsAdapter.js b/modules/pubwiseAnalyticsAdapter.js index 8e4d69dd49a..9858bcce1c7 100644 --- a/modules/pubwiseAnalyticsAdapter.js +++ b/modules/pubwiseAnalyticsAdapter.js @@ -259,6 +259,8 @@ function filterBidRequested(data) { delete modified.gdprConsent; // not tracking through this channel currently } + modified.gdprConsent = {}; + return modified; }