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

AdHash Bid Adapter: brand safety changes #11617

Merged
merged 41 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e7d3b8a
AdHash Bidder Adapter: minor changes
wyand-sp Jan 7, 2022
814f3a8
Implemented brand safety
wyand-sp Jan 18, 2022
d5e34de
Fix for GDPR consent
wyand-sp Mar 10, 2022
4eb1553
Merge branch 'prebid:master' into master
wyand-sp Mar 10, 2022
bdc4fad
Ad fraud prevention formula changed
wyand-sp Mar 16, 2022
35f24dc
AdHash brand safety additions
wyand-sp Apr 14, 2022
e681fbd
AdHash brand safety updates
wyand-sp Jun 28, 2022
c837c36
Merge branch 'master' of https://github.com/AdHashProtocol/Prebid.js
wyand-sp Aug 5, 2022
a6c5faf
AdHash Analytics adapter
wyand-sp Aug 5, 2022
fc5809d
Merge branch 'prebid:master' into master
wyand-sp Aug 10, 2022
3fa0e52
Support for recent ads
wyand-sp Aug 17, 2022
66fddd1
Fix for timestamp
wyand-sp Aug 18, 2022
0c7953c
PUB-222
Sep 15, 2022
66d14ba
Unit tests for the analytics adapter
Sep 19, 2022
1c2470a
Removed export causing errors
Sep 19, 2022
6e4148b
Added globalScript parameter
wyand-sp Sep 26, 2022
ae443ae
Merge branch 'prebid:master' into master
wyand-sp Oct 4, 2022
441240d
PUB-227
vsaraminev Oct 4, 2022
a589f12
Merge branch 'prebid:master' into master
wyand-sp Oct 12, 2022
8dacbc9
GEN-964
M1TKO Oct 28, 2022
9cd75bf
GEN-1025
Nov 16, 2022
dbd9f3d
Removing the analytics adaptor
wyand-sp Nov 28, 2022
65a0d26
Fix for regexp match
wyand-sp Nov 28, 2022
e27cbe4
Version change
wyand-sp Nov 28, 2022
d68efac
MINOR
wyand-sp Dec 7, 2022
e8ab5c2
Merge branch 'prebid:master' into master
wyand-sp Feb 7, 2023
78dea30
GEN-1153
Apr 27, 2023
340e473
MINOR
wyand-sp Apr 28, 2023
cc6994b
Merge branch 'prebid:master' into master
wyand-sp Apr 28, 2023
9ee05e2
Removing globalScript flag
wyand-sp May 9, 2023
2d9d9f2
Merge branch 'prebid:master' into master
wyand-sp May 18, 2023
17cce26
Merge branch 'prebid:master' into master
wyand-sp May 18, 2023
c5942e5
Merge branch 'prebid:master' into master
wyand-sp May 19, 2023
e4cf0cd
Merge branch 'prebid:master' into master
wyand-sp May 24, 2023
661f4b6
Brand safety change
wyand-sp May 24, 2023
925e317
Accessing local storage and fixing text selectors
NikolayMGeorgiev May 30, 2024
b716548
Unit tests updated
wyand-sp May 30, 2024
93d8feb
Merge branch 'master' into master
wyand-sp May 30, 2024
ae0b300
Fixing test selector
NikolayMGeorgiev May 31, 2024
db1a750
Merge branch 'prebid:master' into master
wyand-sp May 31, 2024
baa6f81
Unit tests fixed
wyand-sp May 31, 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
20 changes: 18 additions & 2 deletions modules/adhashBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const VERSION = '3.6';
const BAD_WORD_STEP = 0.1;
const BAD_WORD_MIN = 0.2;
const ADHASH_BIDDER_CODE = 'adhash';
const storage = getStorageManager({ bidderCode: ADHASH_BIDDER_CODE });

/**
* Function that checks the page where the ads are being served for brand safety.
Expand Down Expand Up @@ -120,7 +121,7 @@ function brandSafety(badWords, maxScore) {
.replaceAll(/\s\s+/g, ' ')
.toLowerCase()
.trim();
const content = window.top.document.body.innerText.toLowerCase();
const content = window.top.document.body.textContent.toLowerCase();
// \p{L} matches a single unicode code point in the category 'letter'. Matches any kind of letter from any language.
const regexp = new RegExp('[\\p{L}]+', 'gu');
const wordsMatched = content.match(regexp);
Expand Down Expand Up @@ -171,7 +172,6 @@ export const spec = {
},

buildRequests: (validBidRequests, bidderRequest) => {
const storage = getStorageManager({ bidderCode: ADHASH_BIDDER_CODE });
const { gdprConsent } = bidderRequest;
const bidRequests = [];
const body = document.body;
Expand Down Expand Up @@ -199,9 +199,11 @@ export const spec = {
position: validBidRequests[i].adUnitCode
};
let recentAds = [];
let recentAdsPrebid = [];
if (storage.localStorageIsEnabled()) {
const prefix = validBidRequests[i].params.prefix || 'adHash';
recentAds = JSON.parse(storage.getDataFromLocalStorage(prefix + 'recentAds') || '[]');
recentAdsPrebid = JSON.parse(storage.getDataFromLocalStorage(prefix + 'recentAdsPrebid') || '[]');
}

// Needed for the ad density calculation
Expand Down Expand Up @@ -237,6 +239,7 @@ export const spec = {
blockedCreatives: [],
currentTimestamp: (new Date().getTime() / 1000) | 0,
recentAds: recentAds,
recentAdsPrebid: recentAdsPrebid,
GDPRApplies: gdprConsent ? gdprConsent.gdprApplies : null,
GDPR: gdprConsent ? gdprConsent.consentString : null,
servedAdsCount: window.adsCount,
Expand All @@ -263,6 +266,19 @@ export const spec = {
return [];
}

if (storage.localStorageIsEnabled()) {
const prefix = request.bidRequest.params.prefix || 'adHash';
let recentAdsPrebid = JSON.parse(storage.getDataFromLocalStorage(prefix + 'recentAdsPrebid') || '[]');
recentAdsPrebid.push([
(new Date().getTime() / 1000) | 0,
responseBody.creatives[0].advertiserId,
responseBody.creatives[0].budgetId,
responseBody.creatives[0].expectedHashes.length ? responseBody.creatives[0].expectedHashes[0] : '',
]);
let recentAdsPrebidFinal = JSON.stringify(recentAdsPrebid.slice(-100));
storage.setDataInLocalStorage(prefix + 'recentAdsPrebid', recentAdsPrebidFinal);
}

const publisherURL = JSON.stringify(request.bidRequest.params.platformURL);
const bidderURL = request.bidRequest.params.bidderURL || 'https://bidder.adhash.com';
const oneTimeId = request.bidRequest.adUnitCode + Math.random().toFixed(16).replace('0.', '.');
Expand Down
30 changes: 15 additions & 15 deletions test/spec/modules/adhashBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,105 +178,105 @@ describe('adhashBidAdapter', function () {
});

it('should return empty array when there are bad words (full)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example badword text' + ' word'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (full cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text дума дума example дума text' + ' текст'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (partial)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadwordb badwordb example badwordbtext' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (partial, compound phrase)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbad wordb bad wordb example bad wordbtext' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (starts)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text startsWith starts text startsAgain' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (starts cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text стартТекст старт text стартТекст' + ' дума'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (ends)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text wordEnds ends text anotherends' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (ends cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text ДругКрай край text ощеединкрай' + ' дума'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (combo)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'queen of england dies, the queen dies' + ' word'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return empty array when there are bad words (regexp)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text xxxayyy zzxxxAyyyzz text xxxbyyy' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});

it('should return non-empty array when there are not enough bad words (full)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example text' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});

it('should return non-empty array when there are not enough bad words (partial)', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadwordb example' + ' word'.repeat(996);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});

it('should return non-empty array when there are no-bad word matches', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadword example text' + ' word'.repeat(995);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});

it('should return non-empty array when there are bad words and good words', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example badword goodWord goodWord ' + ' word'.repeat(992);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});

it('should return non-empty array when there is a problem with the brand-safety', function () {
bodyStub = sinon.stub(window.top.document.body, 'innerText').get(function() {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return null;
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
Expand Down