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

Pw b UI ld 042800 pwpbjs #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"browsiRtdProvider",
"haloRtdProvider",
"jwplayerRtdProvider",
"pubwiseRtdProvider",
"reconciliationRtdProvider",
"geoedgeRtdProvider"
]
Expand Down
14 changes: 14 additions & 0 deletions modules/pubwiseAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down Expand Up @@ -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
Expand Down
103 changes: 103 additions & 0 deletions modules/pubwiseRtdProvider.js
Original file line number Diff line number Diff line change
@@ -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);
9 changes: 9 additions & 0 deletions modules/pubwiseRtdProvider.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"header bidding",
"prebid"
],
"globalVarName": "pbjs",
"globalVarName": "pwpbjs",
"author": "the prebid.js contributors",
"license": "Apache-2.0",
"engines": {
Expand Down