Skip to content

Craft Bid Adapter : generate virtual uid #12955

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

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 11 additions & 8 deletions modules/craftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getBidRequest} from '../src/utils.js';
import {getBidRequest, generateUUID} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {find, includes} from '../src/polyfill.js';
Expand Down Expand Up @@ -48,7 +48,7 @@ export const spec = {
payload.us_privacy = bidderRequest.uspConsent;
}
if (bidderRequest.refererInfo) {
let refererinfo = {
const refererinfo = {
// TODO: this collects everything it finds, except for the canonical URL
rd_ref: bidderRequest.refererInfo.topmostLocation,
rd_top: bidderRequest.refererInfo.reachedTop,
Expand Down Expand Up @@ -92,11 +92,9 @@ export const spec = {
};

function formatRequest(payload, bidderRequest) {
let options = {};
const options = {};
if (!hasPurpose1Consent(bidderRequest?.gdprConsent)) {
options = {
withCredentials: false
};
options.withCredentials = false;
}
const baseUrl = payload.tags[0].url || URL_BASE;
const payloadString = JSON.stringify(payload);
Expand Down Expand Up @@ -132,12 +130,17 @@ function newBid(serverBid, rtbBid, bidderRequest) {

function bidToTag(bid) {
const tag = {};
for (var k in bid.params) {
for (const k in bid.params) {
tag[k] = bid.params[k];
}
try {
if (storage.hasLocalStorage()) {
tag.uid = JSON.parse(storage.getDataFromLocalStorage(`${bid.params.sitekey}_uid`));
const field = `${bid.params.sitekey}_uid`;
tag.uid = JSON.parse(storage.getDataFromLocalStorage(field));
if (!tag.uid) {
tag.uid = {value: {id: generateUUID()}};
storage.setDataInLocalStorage(field, JSON.stringify(tag.uid));
Copy link
Collaborator

@patmmccann patmmccann Apr 3, 2025

Choose a reason for hiding this comment

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

declare in your documentation pr exactly which key you are setting and what its purpose is, eg in a format similar to https://business.safety.google/adscookies/

}
}
} catch (e) {
}
Expand Down
26 changes: 14 additions & 12 deletions test/spec/modules/craftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {newBidder} from 'src/adapters/bidderFactory.js';
import {config} from 'src/config.js';

describe('craftAdapter', function () {
let adapter = newBidder(spec);
const adapter = newBidder(spec);

describe('inherited functions', function () {
it('exists and is a function', function () {
Expand All @@ -27,7 +27,7 @@ describe('craftAdapter', function () {
$$PREBID_GLOBAL$$.bidderSettings = {};
window.context = this.windowContext;
});
let bid = {
const bid = {
bidder: 'craft',
params: {
sitekey: 'craft-prebid-example',
Expand All @@ -40,7 +40,7 @@ describe('craftAdapter', function () {
});

it('should return false when params.sitekey not found', function () {
let invalidBid = Object.assign({}, bid);
const invalidBid = Object.assign({}, bid);
delete invalidBid.params;
invalidBid.params = {
placementId: '1234abcd'
Expand All @@ -49,7 +49,7 @@ describe('craftAdapter', function () {
});

it('should return false when params.placementId not found', function () {
let invalidBid = Object.assign({}, bid);
const invalidBid = Object.assign({}, bid);
delete invalidBid.params;
invalidBid.params = {
sitekey: 'craft-prebid-example'
Expand All @@ -76,7 +76,7 @@ describe('craftAdapter', function () {
after(function () {
$$PREBID_GLOBAL$$.bidderSettings = {};
});
let bidRequests = [{
const bidRequests = [{
bidder: 'craft',
params: {
'sitekey': 'craft-prebid-example',
Expand All @@ -89,32 +89,34 @@ describe('craftAdapter', function () {
auctionId: '8720f980-4639-4150-923a-e96da2f1de36',
transactionId: 'e0c52da2-c008-491c-a910-c6765d948700',
}];
let bidderRequest = {
const bidderRequest = {
refererInfo: {
topmostLocation: 'https://www.gacraft.jp/publish/craft-prebid-example.html'
}
};
it('sends bid request to ENDPOINT via POST', function () {
let request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.method).to.equal('POST');
expect(request.url).to.equal('https://gacraft.jp/prebid-v3/craft-prebid-example');
let data = JSON.parse(request.data);
const data = JSON.parse(request.data);
const uid = data.tags[0].uid;
delete data.tags[0].uid;
expect(data.tags).to.deep.equals([{
sitekey: 'craft-prebid-example',
placementId: '1234abcd',
uid: null,
sizes: [[300, 250]],
primary_size: [300, 250],
uuid: '0396fae4eb5f47'
}]);
expect(uid.value.id.length).to.deep.equals(36);
expect(data.referrer_detection).to.deep.equals({
rd_ref: 'https://www.gacraft.jp/publish/craft-prebid-example.html'
});
});
});

describe('interpretResponse', function() {
let serverResponse = {
const serverResponse = {
body: {
tags: [{
uuid: '0396fae4eb5f47',
Expand All @@ -137,14 +139,14 @@ describe('craftAdapter', function () {
}],
}
};
let bidderRequest = {
const bidderRequest = {
bids: [{
bidId: '0396fae4eb5f47',
adUnitCode: 'craft-prebid-example'
}]
};
it('should get correct bid response', function() {
let bids = spec.interpretResponse(serverResponse, {bidderRequest: bidderRequest});
const bids = spec.interpretResponse(serverResponse, {bidderRequest: bidderRequest});
expect(bids).to.have.lengthOf(1);
expect(bids[0]).to.deep.equals({
_adUnitCode: 'craft-prebid-example',
Expand Down