Skip to content

Commit

Permalink
Discovery Bid Adapter : get UTM tag data (#11380)
Browse files Browse the repository at this point in the history
* feat(isBidRequestValid): just filter token once. not filter publisher and tagid

* feat(isBidRequestValid): add unit test

* feat(spec): fix eslint

* feat(spec): fix unit test

* feat(spec): fix unit test

* feat(ext): change default value

* feat(utm): build UTMTag data

* feat(spec): fix utm test

* feat(utm): get UTMTag

* feat(utm): add unit tests

* feat(utm): fix unit tests

* feat(utm): fix unit tests

* feat(utm): fix unit tests

---------

Co-authored-by: yubei01 <[email protected]>
  • Loading branch information
ecoeco163 and yubei01 committed May 6, 2024
1 parent 2bb9f97 commit 55d008a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
3 changes: 2 additions & 1 deletion modules/discoveryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function getItems(validBidRequests, bidderRequest) {

export const buildUTMTagData = (url) => {
if (!storage.cookiesAreEnabled()) return;
const urlParams = utils.parseUrl(url).search;
const urlParams = utils.parseUrl(url).search || {};
const UTMParams = {};
Object.keys(urlParams).forEach(key => {
if (/^utm_/.test(key)) {
Expand Down Expand Up @@ -486,6 +486,7 @@ function getParam(validBidRequests, bidderRequest) {
ssppid: storage.getCookie(COOKIE_KEY_SSPPID) || undefined,
pmguid: getPmgUID(),
tpData,
utm: storage.getCookie(UTM_KEY),
page: {
title: title ? title.slice(0, 100) : undefined,
desc: desc ? desc.slice(0, 300) : undefined,
Expand Down
53 changes: 20 additions & 33 deletions test/spec/modules/discoveryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ import {
import * as utils from 'src/utils.js';

describe('discovery:BidAdapterTests', function () {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(storage, 'getCookie');
sandbox.stub(storage, 'setCookie');
sandbox.stub(utils, 'generateUUID').returns('new-uuid');
sandbox.stub(utils, 'parseUrl').returns({
search: {
utm_source: 'example.com'
}
});
sandbox.stub(storage, 'cookiesAreEnabled');
})

afterEach(() => {
sandbox.restore();
});

let bidRequestData = {
bidderCode: 'discovery',
auctionId: 'ff66e39e-4075-4d18-9854-56fde9b879ac',
Expand Down Expand Up @@ -200,8 +219,8 @@ describe('discovery:BidAdapterTests', function () {
})
).to.equal(true);
});

it('discovery:validate_generated_params', function () {
storage.getCookie.withArgs('_ss_pp_utm').callsFake(() => '{"utm_source":"example.com","utm_medium":"123","utm_campaign":"456"}');
request = spec.buildRequests(bidRequestData.bids, bidRequestData);
let req_data = JSON.parse(request.data);
expect(req_data.imp).to.have.lengthOf(1);
Expand All @@ -216,20 +235,6 @@ describe('discovery:BidAdapterTests', function () {

describe('discovery: buildRequests', function() {
describe('getPmgUID function', function() {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(storage, 'getCookie');
sandbox.stub(storage, 'setCookie');
sandbox.stub(utils, 'generateUUID').returns('new-uuid');
sandbox.stub(storage, 'cookiesAreEnabled');
})

afterEach(() => {
sandbox.restore();
});

it('should generate new UUID and set cookie if not exists', () => {
storage.cookiesAreEnabled.callsFake(() => true);
storage.getCookie.callsFake(() => null);
Expand All @@ -254,24 +259,6 @@ describe('discovery:BidAdapterTests', function () {
});
})
describe('buildUTMTagData function', function() {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(storage, 'getCookie');
sandbox.stub(storage, 'setCookie');
sandbox.stub(utils, 'parseUrl').returns({
search: {
utm_source: 'example.com'
}
});
sandbox.stub(storage, 'cookiesAreEnabled');
})

afterEach(() => {
sandbox.restore();
});

it('should set UTM cookie', () => {
storage.cookiesAreEnabled.callsFake(() => true);
storage.getCookie.callsFake(() => null);
Expand Down

0 comments on commit 55d008a

Please sign in to comment.