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

Glimpse Bid Adapter: update testing, capture ad target, and GDPR consent choices #7476

Merged
merged 1 commit into from
Oct 5, 2021
Merged
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
208 changes: 160 additions & 48 deletions modules/glimpseBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,181 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { BANNER } from '../src/mediaTypes.js'
import { getStorageManager } from '../src/storageManager.js'
import { isArray } from '../src/utils.js'
import { registerBidder } from '../src/adapters/bidderFactory.js'

const BIDDER_CODE = 'glimpse';
const storageManager = getStorageManager()

function transformEachBidResponse(glimpseBid) {
const bid = glimpseBid;
bid.meta = { advertiserDomains: [] };

if (glimpseBid.adomain) {
bid.meta.advertiserDomains = glimpseBid.adomain;
}

return bid;
const BIDDER_CODE = 'glimpse'
const ENDPOINT = 'https://api.glimpsevault.io/ads/serving/public/v1/prebid'
const LOCAL_STORAGE_KEY = {
glimpse: {
jwt: 'gp_vault_jwt',
},
}

export const spec = {
code: BIDDER_CODE,
url: 'https://api.glimpseprotocol.io/cloud/v1/vault/prebid',
supportedMediaTypes: [BANNER],

/**
* Determines whether or not the given bid request is valid
* @param bid {BidRequest} The bid to validate
* @return {boolean}
*/
isBidRequestValid: (bid) => {
try {
const { placementId } = bid.params;
return typeof placementId === 'string' && placementId.length > 0;
} catch (error) {
return false;
}
return (
hasValue(bid) &&
hasValue(bid.params) &&
hasStringValue(bid.params.placementId)
)
},

/**
* Builds http request for Glimpse bids
* @param validBidRequests {BidRequest[]}
* @param bidderRequest {BidderRequest}
* @returns {ServerRequest}
*/
buildRequests: (validBidRequests, bidderRequest) => {
const { url, code: bidderCode } = spec;

const bids = validBidRequests.map((request) => {
delete request.mediaTypes;
return request;
});
const networkId = window.networkId || -1
const bids = validBidRequests.map(processBidRequest)
const referer = getReferer(bidderRequest)
const gdprConsent = getGdprConsentChoice(bidderRequest)
const jwt = getVaultJwt()

const sdk = {
source: 'pbjs',
version: '$prebid.version$',
};

const payload = {
...bidderRequest,
bidderCode,
bids,
sdk,
};
const data = {
auth: jwt,
data: {
bidderCode: spec.code,
networkId,
bids,
referer,
gdprConsent,
}
}

return {
method: 'POST',
url,
data: JSON.stringify(payload),
};
url: ENDPOINT,
data: JSON.stringify(data),
options: {},
}
},

interpretResponse: (serverResponse, _) => {
let bids = [];
try {
const { body } = serverResponse;
bids = body.map(transformEachBidResponse);
} catch (error) {}
/**
* Parse response from Glimpse server
* @param bidResponse {ServerResponse}
* @param bidRequest {BidRequest}
* @returns {Bid[]}
*/
interpretResponse: (bidResponse, bidRequest) => {
const isValidResponse = isValidBidResponse(bidResponse)

if (isValidResponse) {
const {auth, data} = bidResponse.body
setVaultJwt(auth)
return data.bids
}

return bids;
return []
},
};
}

function processBidRequest(bidRequest) {
const sizes = normalizeSizes(bidRequest.sizes)
const keywords = bidRequest.params.keywords || []

return {
bidId: bidRequest.bidId,
placementId: bidRequest.params.placementId,
unitCode: bidRequest.adUnitCode,
sizes,
keywords,
}
}

function normalizeSizes(sizes) {
const isSingleSize =
isArray(sizes) &&
sizes.length === 2 &&
!isArray(sizes[0]) &&
!isArray(sizes[1])

if (isSingleSize) {
return [sizes]
}

return sizes
}

function getReferer(bidderRequest) {
const hasReferer =
hasValue(bidderRequest) &&
hasValue(bidderRequest.refererInfo) &&
hasStringValue(bidderRequest.refererInfo.referer)

if (hasReferer) {
return bidderRequest.refererInfo.referer
}

return ''
}

function getGdprConsentChoice(bidderRequest) {
const hasGdprConsent =
hasValue(bidderRequest) &&
hasValue(bidderRequest.gdprConsent)

if (hasGdprConsent) {
return bidderRequest.gdprConsent
}

return {
consentString: '',
vendorData: {},
gdprApplies: false,
}
}

function setVaultJwt(auth) {
storageManager.setDataInLocalStorage(LOCAL_STORAGE_KEY.glimpse.jwt, auth)
}

function getVaultJwt() {
return storageManager.getDataFromLocalStorage(LOCAL_STORAGE_KEY.glimpse.jwt) || ''
}

function isValidBidResponse(bidResponse) {
return (
hasValue(bidResponse) &&
hasValue(bidResponse.body) &&
hasValue(bidResponse.body.data) &&
hasArrayValue(bidResponse.body.data.bids) &&
hasStringValue(bidResponse.body.auth)
)
}

function hasValue(value) {
return (
value !== undefined &&
value !== null
)
}

function hasStringValue(value) {
return (
hasValue(value) &&
typeof value === 'string' &&
value.length > 0
)
}

function hasArrayValue(value) {
return (
hasValue(value) &&
isArray(value) &&
value.length > 0
)
}

registerBidder(spec);
registerBidder(spec)
85 changes: 11 additions & 74 deletions modules/glimpseBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,36 @@
```
Module Name: Glimpse Protocol Bid Adapter
Module Type: Bidder Adapter
Maintainer: hello@glimpseprotocol.io
Maintainer: publisher@glimpseprotocol.io
```

# Description

This module connects publishers to Glimpse Protocol's demand sources via Prebid.js. Our innovative marketplace protects
consumer privacy while allowing precise targeting. It is compliant with GDPR, DPA and CCPA.

This adapter supports Banner.
The Glimpse Adapter supports banner formats.

# Test Parameters

```javascript
var adUnits = [
const adUnits = [
{
code: 'banner-div-a',
mediaTypes: {
banner: {
sizes: [[300, 250]],
},
},
bids: [
{
bidder: 'glimpse',
params: {
placementId: 'glimpse-demo-300x250',
bids: [{
bidder: 'glimpse',
params: {
placementId: 'e53a7f564f8f44cc913b',
keywords: {
country: 'uk',
},
},
],
}],
},
{
code: 'banner-div-b',
mediaTypes: {
banner: {
sizes: [[320, 50]],
},
},
bids: [
{
bidder: 'glimpse',
params: {
placementId: 'glimpse-demo-320x50',
},
},
],
},
{
code: 'banner-div-c',
mediaTypes: {
banner: {
sizes: [[970, 250]],
},
},
bids: [
{
bidder: 'glimpse',
params: {
placementId: 'glimpse-demo-970x250',
},
},
],
},
{
code: 'banner-div-d',
mediaTypes: {
banner: {
sizes: [[728, 90]],
},
},
bids: [
{
bidder: 'glimpse',
params: {
placementId: 'glimpse-demo-728x90',
},
},
],
},
{
code: 'banner-div-e',
mediaTypes: {
banner: {
sizes: [[300, 600]],
},
},
bids: [
{
bidder: 'glimpse',
params: {
placementId: 'glimpse-demo-300x600',
},
},
],
},
];
]
```
Loading