-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Zeotap ID+ submodule #5640
Merged
Merged
Zeotap ID+ submodule #5640
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9334591
IDU-117 IDU-119 Add zeotap submodule
shikharsharma-zeotap 699c53a
IDU-117 IDU-119 Add tests for zeotapId+ module
shikharsharma-zeotap 8bf0bc7
add zeotapId+ module spec
shikharsharma-zeotap 5e055e8
Add IDP base64 decode logic
shikharsharma-zeotap 9b52f84
remove unwanted file changes
shikharsharma-zeotap 435f3c7
rename zeotapId+ to zeotapIdPlus
shikharsharma-zeotap f587d2a
add zeotapIdPlus submodule to submodules.json
shikharsharma-zeotap 20f152e
refactor code for requested changes: remove storage from configParams
shikharsharma-zeotap 4fe5411
add tests to eids_spec
shikharsharma-zeotap 3b56ee6
rebase n resolve conflicts
shikharsharma-zeotap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,9 @@ | |
name: "_li_pbid", | ||
expires: 28 | ||
} | ||
}, | ||
{ | ||
name: "zeotapIdPlus" | ||
}], | ||
syncDelay: 5000, | ||
auctionDelay: 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* This module adds Zeotap to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/zeotapIdPlusIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
import * as utils from '../src/utils.js' | ||
import {submodule} from '../src/hook.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
|
||
const ZEOTAP_COOKIE_NAME = 'IDP'; | ||
const storage = getStorageManager(); | ||
|
||
function readCookie() { | ||
return storage.cookiesAreEnabled ? storage.getCookie(ZEOTAP_COOKIE_NAME) : null; | ||
} | ||
|
||
function readFromLocalStorage() { | ||
return storage.localStorageIsEnabled ? storage.getDataFromLocalStorage(ZEOTAP_COOKIE_NAME) : null; | ||
} | ||
|
||
/** @type {Submodule} */ | ||
export const zeotapIdPlusSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'zeotapIdPlus', | ||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param { Object | string | undefined } value | ||
* @return { Object | string | undefined } | ||
*/ | ||
decode(value) { | ||
const id = value ? utils.isStr(value) ? value : utils.isPlainObject(value) ? value.id : undefined : undefined; | ||
return id ? { | ||
'IDP': JSON.parse(atob(id)) | ||
} : undefined; | ||
}, | ||
/** | ||
* performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleParams} configParams | ||
* @return {{id: string | undefined} | undefined} | ||
*/ | ||
getId() { | ||
const id = readCookie() || readFromLocalStorage(); | ||
return id ? { id } : undefined; | ||
} | ||
}; | ||
submodule('userId', zeotapIdPlusSubmodule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { expect } from 'chai'; | ||
import find from 'core-js-pure/features/array/find.js'; | ||
import { config } from 'src/config.js'; | ||
import { newStorageManager } from 'src/storageManager.js'; | ||
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js'; | ||
import { zeotapIdPlusSubmodule } from 'modules/zeotapIdPlusIdSystem.js'; | ||
|
||
const storage = newStorageManager(); | ||
|
||
const ZEOTAP_COOKIE_NAME = 'IDP'; | ||
const ZEOTAP_COOKIE = 'THIS-IS-A-DUMMY-COOKIE'; | ||
const ENCODED_ZEOTAP_COOKIE = btoa(JSON.stringify(ZEOTAP_COOKIE)); | ||
|
||
function getConfigMock() { | ||
return { | ||
userSync: { | ||
syncDelay: 0, | ||
userIds: [{ | ||
name: 'zeotapIdPlus' | ||
}] | ||
} | ||
} | ||
} | ||
|
||
function getAdUnitMock(code = 'adUnit-code') { | ||
return { | ||
code, | ||
mediaTypes: {banner: {}, native: {}}, | ||
sizes: [ | ||
[300, 200], | ||
[300, 600] | ||
], | ||
bids: [{ | ||
bidder: 'sampleBidder', | ||
params: { placementId: 'banner-only-bidder' } | ||
}] | ||
}; | ||
} | ||
|
||
function unsetCookie() { | ||
storage.setCookie(ZEOTAP_COOKIE_NAME, ''); | ||
} | ||
|
||
function unsetLocalStorage() { | ||
storage.setDataInLocalStorage(ZEOTAP_COOKIE_NAME, ''); | ||
} | ||
|
||
describe('Zeotap ID System', function() { | ||
describe('test method: getId', function() { | ||
afterEach(() => { | ||
unsetCookie(); | ||
unsetLocalStorage(); | ||
}) | ||
|
||
it('provides the stored Zeotap id if a cookie exists', function() { | ||
storage.setCookie( | ||
ZEOTAP_COOKIE_NAME, | ||
ENCODED_ZEOTAP_COOKIE, | ||
(new Date(Date.now() + 5000).toUTCString()), | ||
); | ||
let id = zeotapIdPlusSubmodule.getId(); | ||
expect(id).to.deep.equal({ | ||
id: ENCODED_ZEOTAP_COOKIE | ||
}); | ||
}); | ||
|
||
it('provides the stored Zeotap id if cookie is absent but present in local storage', function() { | ||
smenzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
storage.setDataInLocalStorage(ZEOTAP_COOKIE_NAME, ENCODED_ZEOTAP_COOKIE); | ||
let id = zeotapIdPlusSubmodule.getId(); | ||
expect(id).to.deep.equal({ | ||
id: ENCODED_ZEOTAP_COOKIE | ||
}); | ||
}); | ||
|
||
it('returns undefined if both cookie and local storage are empty', function() { | ||
let id = zeotapIdPlusSubmodule.getId(); | ||
expect(id).to.be.undefined | ||
}) | ||
}); | ||
|
||
describe('test method: decode', function() { | ||
it('provides the Zeotap ID (IDP) from a stored object', function() { | ||
let zeotapId = { | ||
id: ENCODED_ZEOTAP_COOKIE, | ||
}; | ||
|
||
expect(zeotapIdPlusSubmodule.decode(zeotapId)).to.deep.equal({ | ||
IDP: ZEOTAP_COOKIE | ||
}); | ||
}); | ||
|
||
it('provides the Zeotap ID (IDP) from a stored string', function() { | ||
let zeotapId = ENCODED_ZEOTAP_COOKIE; | ||
|
||
expect(zeotapIdPlusSubmodule.decode(zeotapId)).to.deep.equal({ | ||
IDP: ZEOTAP_COOKIE | ||
}); | ||
}); | ||
}); | ||
|
||
describe('requestBids hook', function() { | ||
let adUnits; | ||
|
||
beforeEach(function() { | ||
adUnits = [getAdUnitMock()]; | ||
storage.setCookie( | ||
ZEOTAP_COOKIE_NAME, | ||
ENCODED_ZEOTAP_COOKIE, | ||
(new Date(Date.now() + 5000).toUTCString()), | ||
); | ||
setSubmoduleRegistry([zeotapIdPlusSubmodule]); | ||
init(config); | ||
config.setConfig(getConfigMock()); | ||
}); | ||
|
||
afterEach(function() { | ||
unsetCookie(); | ||
unsetLocalStorage(); | ||
}); | ||
|
||
it('when a stored Zeotap ID exists it is added to bids', function(done) { | ||
requestBidsHook(function() { | ||
adUnits.forEach(unit => { | ||
unit.bids.forEach(bid => { | ||
expect(bid).to.have.deep.nested.property('userId.IDP'); | ||
expect(bid.userId.IDP).to.equal(ZEOTAP_COOKIE); | ||
const zeotapIdAsEid = find(bid.userIdAsEids, e => e.source == 'zeotap.com'); | ||
expect(zeotapIdAsEid).to.deep.equal({ | ||
source: 'zeotap.com', | ||
uids: [{ | ||
id: ZEOTAP_COOKIE, | ||
atype: 1, | ||
}] | ||
}); | ||
}); | ||
}); | ||
done(); | ||
}, { adUnits }); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be configurable by the pub? can you read if this is set in config and fallback to 'IDP' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patmmccann I have added the tests to eid spec file. The cookie name 'IDP' is not configurable by the pub. It gets added to the storage by Zeotap JS after publisher integration. I didn't get the other question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!