Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

EX-16373 - PrebidJS Adapter #1

Merged
merged 45 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
295e037
First commit
giuseppe-exads Jan 19, 2024
3dcb786
fix: readme.md
giuseppe-exads Jan 19, 2024
30eb51e
fix: changed exads urls
giuseppe-exads Jan 19, 2024
1e83db3
fix: Tools and suggestions related to the doc
giuseppe-exads Jan 19, 2024
38caa60
fix: from code review
giuseppe-exads Jan 22, 2024
bad299c
fix: from code review
giuseppe-exads Jan 22, 2024
0a4caf6
fix: from code review
giuseppe-exads Jan 22, 2024
9439670
fix: error from code review - native example
giuseppe-exads Jan 23, 2024
4965cfc
fox: from code review
giuseppe-exads Jan 24, 2024
091f340
fix: from code review
giuseppe-exads Jan 24, 2024
72163cf
fix: from code review
giuseppe-exads Jan 24, 2024
e0740ba
fix: native img set as mandatory
giuseppe-exads Jan 24, 2024
ec22581
fix: from code review
giuseppe-exads Jan 24, 2024
08b94c8
fix: from code review
giuseppe-exads Jan 24, 2024
fc03f90
fix: from code review
giuseppe-exads Jan 30, 2024
f4431a8
Merge branch 'master' into EX-16373
giuseppe-exads Jan 30, 2024
9b8ac1f
fix: from code review
giuseppe-exads Feb 20, 2024
d153e9a
fix: from code review
giuseppe-exads Feb 20, 2024
47bc992
fix: from code review
giuseppe-exads Feb 20, 2024
20edd7b
fix: bidfloor and bidfloorcur set as optional
giuseppe-exads Feb 20, 2024
a047b32
fix: dsa
giuseppe-exads Feb 20, 2024
17d705a
fix: mananing multiple responses
giuseppe-exads Feb 21, 2024
c2df4a1
fix: unit test after code review
giuseppe-exads Feb 21, 2024
f264a20
fix: fixing native snippet code
giuseppe-exads Feb 22, 2024
a89f377
fix: from code review
giuseppe-exads Feb 23, 2024
06b8349
fix: video events after code review
giuseppe-exads Feb 23, 2024
e3e8056
fix: video module into documentation
giuseppe-exads Feb 23, 2024
2cee2f3
fix: impression tracker for native
giuseppe-exads Feb 23, 2024
cbf78f7
fix: afeter code review
giuseppe-exads Feb 23, 2024
0c58be6
fix: unit tests
giuseppe-exads Feb 23, 2024
f807674
fix: added badv and bcat
giuseppe-exads Feb 26, 2024
85ad4f4
fix: video -> mimes and protocols
giuseppe-exads Feb 27, 2024
a5f14e4
fix
giuseppe-exads Feb 27, 2024
5029e42
fix: removed image_output and video_output params, forcing always htm…
giuseppe-exads Feb 27, 2024
d524e33
fix: gulp
giuseppe-exads Feb 28, 2024
12fc5bb
fix: added site.name
giuseppe-exads Mar 4, 2024
5cc107a
fix: removed EXADS dir
giuseppe-exads Mar 5, 2024
99098df
fix: after linting
giuseppe-exads Mar 5, 2024
a430eba
fix: unit tests
giuseppe-exads Mar 5, 2024
a27dec0
fix: final dsa solution
giuseppe-exads Mar 6, 2024
8666d36
Merge branch 'master' into EX-16373
giuseppe-exads Mar 6, 2024
9552cfe
fix: dsa
giuseppe-exads Mar 6, 2024
e38bfb7
fix: fix instream example
giuseppe-exads Mar 7, 2024
5a2ca31
fix: doc media type context
giuseppe-exads Mar 7, 2024
ad34d6b
fix: documented the endpoint param into native section
giuseppe-exads Mar 7, 2024
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
46 changes: 46 additions & 0 deletions exads/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# exadsBidAdapter
EXADS PrebidJS Adapter

#### In order to mantain the adapter locally:

* Change the adapter code that you can find in `./Prebid.js/modules/exadsBidAdapter.js`
* Update the unit tests, they are in `./Prebid.js/test/spec/modules/exadsBidAdapter_spec.js`
* Run tlint and unit tests (to see the specific paragraph)
* Do manual tests (to see the specific paragraph)
* Build the new version of the adapter and all modules needed: `gulp build --modules=consentManagement,exadsBidAdapter`
* After that, you can use the prebidJS, merged with our module.
* You can find it in `./build/dist/prebid.js`
* Update our HTML examples in order to test the adapter. You can find them in `./exads/examples`

#### Lint and Unit tests
* Note: lint checks the official prebidJS rules.
* Also, to do the pull request to official prebidJS team, it is mondatory 80% or more of covarage.
* To check the coverage, type:
* `gulp test-coverage` and then
* `gulp view-coverage`

#### Manual tests
* Copy all examples to use in the publisher test website: `./exads/doc/README.md`
* Copy the prebidJS library containing the new changes of the adapter `./build/dist/prebid.js`
* For each example, change `<script async src="js/prebid.js"></script>`, based on the publisher website configuration
* Note: if you need to debug the snippet code, comment the previous instruction and uncomment the `<script src="js/prebid.js"></script>`
* Change all params based on test scenarios (to see: `./Prebid.js/modules/exadsBidAdapter.md`)
* Navigate to the publisher website and test it

#### Environments (development and production) - Changes to do in the snippet code
* Set isEnabledDebug global variable (If it is true, you will be able to see logs)

* For development environments
```
<!-- Uncomment for development environments -->
<script src="js/prebid.js"></script>
<!-- Remove this line -->
<script async src="js/prebid.js" onload="onScriptLoaded()"></script>
```
* For production environments
```
<!-- Remove this line -->
<script src="js/prebid.js"></script>
<!-- Uncomment for production environments -->
<script async src="js/prebid.js" onload="onScriptLoaded()"></script>
```
261 changes: 261 additions & 0 deletions exads/examples/prebidJS-client-RTB-InStreamVideo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
<!DOCTYPE html>
<html lang='en'>

<head>
<meta charset='UTF-8'>
<title>RTB Instream Video Prebid.js</title>

<link href="https://vjs.zencdn.net/7.20.2/video-js.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.css"
integrity="sha512-0gIqgiX1dWTChdWUl8XGIBDFvLo7aTvmd6FAhJjzWx5bzYsCJTiPJLKqLF3q31IN4Kfrc0NbTO+EthoT6O0olQ=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/2.1.0/videojs.ima.css"
integrity="sha512-vvsEsf+dZDp6wbommO1Jbb2bpFhVQjw6pIzfE5fUY5Fgkmsgn/16sQWegqrd236T69kK5F1SbGZ+yK46a9il5A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://vjs.zencdn.net/7.20.2/video.js"></script>
<script src="https://imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.js"
integrity="sha512-XjyyAijQGlXZET35toG8igvVs8HvfVgKXGnbfAs2EpZ0o8vjJoIrxL9RBBQbQjzAODIe0jvWelFfZOA3Z/vdWg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/2.1.0/videojs.ima.js"
integrity="sha512-SCLZezhUawfgEVvtAuWp8OpRjZVa30okAsUoUe4+wPO6BEj4dWV1rDDruNwgOUrNdKpJL0GBf0KRrslSO7nqrw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/videojs-playlist@5.1.0/dist/videojs-playlist.min.js"></script>

<!-- Uncomment for development environments -->
<!-- <script src='js/prebid.js'></script> -->
<!-- Uncomment for production environments -->
<script async src='js/prebid.js' onload='onScriptLoaded()'></script>

<script>
// Client Conf start
// Set as true for development environments only
const isEnabledDebug = false;
const exadsEndpoint = 'https://your-ad-network.com/rtb.php';
const partner = 'ortb_2_4';
let zoneId = 5208095;
let fid = '56aa7575210d931d37f62d816a84d4afdb2dfa97';

// Start GDPR params

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should now implement DSA here as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let isGDPRRequested = false;
// Valid iabtcf consent string
let consentString = 'CO_V33gP0l1PgAoAAAENCZCgAAAAAAAAAAAAE0wAQE0gTTABATSAAA.YAAAAAAAAAA';
// End GDPR params

let siteId = '12345';
let country = 'IRL';
let keywords = 'lifestyle, humour';
let bidfloorcur = 'EUR';
let bidfloor = 0.00000011;
// Client Conf end
let adUnits = [];

let PREBID_TIMEOUT = 500000;
let userIp = 0;
let userIpLoaded = false;
let impressionId = hashCode(new Date().getTime().toString());
let userId = localStorage.getItem('prebidJS.userId');

if (!userId) {
localStorage.setItem('prebidJS.userId', hashCode('userId' + new Date().getTime().toString()));
userId = localStorage.getItem('prebidJS.userId');
}

let ipScript = document.createElement('script');
ipScript.type = 'text/javascript';
ipScript.src = 'https://api.ipify.org?format=jsonp&callback=userIpCallback';
document.getElementsByTagName('head')[0].appendChild(ipScript);

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

handleRTB();

if (isEnabledDebug) {
onScriptLoaded();
}

function onScriptLoaded() {

}

// ======== DO NOT EDIT BELOW THIS LINE =========== //
function userIpCallback(user_ip) {
userIpLoaded = true;
if (user_ip.hasOwnProperty('ip')) {
userIp = user_ip.ip;
}
}

// MurmurHash3 hash function
function hashCode(str, seed = 0) {
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}

function handleRTB() {
adUnits = [{
code: 'postbid_iframe',
mediaTypes: {
video: {
mimes: ['video/mp4'],
protocols: [3, 6],
divId: 'player', // required to indicate which player is being used to render this ad unit.
/*renderer: {
url: 'example.com/videoRenderer.js',
render: function (bid) { renderVideo(...) }
}*/
}
},
bids: [{
bidder: 'exadsadserver',
params: {
zoneId: zoneId,
fid: fid,
partner: partner,
siteId: siteId,
userIp: 0, // DO NOT EDIT - Client side data
userId: userId,
impressionId: impressionId.toString(), // DO NOT EDIT - Custom hash
imp: {
video: {
mimes: ['video/mp4'],
protocols: [3,6],
},

ext: {
video_cta: 0
}
},
dsa: {
dsarequired: 3,
pubrender: 0,
datatopub: 2
},
country: country,
keywords: keywords,
bidfloor: bidfloor,
bidfloorcur: bidfloorcur,
endpoint: exadsEndpoint
}
}]
}];
}

// Init when IP data is available
function initBids() {
if (userIpLoaded === false) {
window.setTimeout(initBids, 50);
} else {
for (let i = 0; i < adUnits.length; i++) {
for (let t = 0; t < adUnits[i].bids.length; t++) {
adUnits[i].bids[t].params.userIp = userIp;
}
}

pbjs.que.push(function () {
pbjs.setConfig({
debug: isEnabledDebug,
cache: { url: 'https://prebid.adnxs.com/pbc/v1/cache' },
consentManagement: {
gdpr: {
cmpApi: 'static',
timeout: 1000000,
defaultGdprScope: true,
consentData: {
getTCData: {
tcString: consentString,
gdprApplies: isGDPRRequested
}
}
}
},
video: {
providers: [{
divId: 'player',
vendorCode: 2, // videojs vendorCode
playerConfig: {
params: {
adPluginConfig: {
numRedirects: 10
},
vendorConfig: {
controls: true,
autoplay: true,
preload: "auto",
}
}
}
},]
},
});
pbjs.addAdUnits(adUnits);

pbjs.onEvent('videoSetupComplete', e => {
const player = videojs('player');
// Load the playlist items with their metadata when the video player is done instantiating.
player.playlist([{
sources: [{
src: 'https://vjs.zencdn.net/v/oceans.mp4',
type: 'video/mp4'
}]
}]);

player.playlist.autoadvance(0);
});

pbjs.onEvent('videoSetupFailed', e => {
console.log('player setup failed: ', e);
});

pbjs.onEvent('videoPlaylist', (e) => {
console.log('videos pb playlist: ', e);
});

pbjs.onEvent('videoContentLoaded', (e) => {
console.log('videos pb contentLoaded: ', e);
});

pbjs.onEvent('videoComplete', (e) => {
console.log('videos pb complete: ', e);
});

//pbjs.requestBids(adUnits);
pbjs.requestBids({
timeout: PREBID_TIMEOUT,
bidsBackHandler: function (bidResponses) {
const bidResponse = bidResponses['postbid_iframe'];
if (!bidResponse) {
return;
}

bidResponse.bids.forEach(bid => {
pbjs.videoModule.renderBid('player', bid);
});
}
});
});
}
}

initBids();

</script>

</head>

<body>

<h2>RTB Instream Video Prebid.js</h2>
<video-js id='player' class="vjs-big-play-centered" muted="'true">
</video-js>
</body>

</html>
Loading