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

updates to add rtd module #14

Open
wants to merge 1 commit 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
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.