-
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
LiveConnect, lighter-weight module #6016
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a95d622
NT. Trying out how webpack plays with env vars
jankoulaga bc3fac1
NT. Test run before merge
jankoulaga 2305e67
Merge remote-tracking branch 'origin/master' into NT-lighterweight-mo…
jankoulaga e8d90ea
NT. POC kinda ok for me now
jankoulaga 2aa4200
NT. Updated the lc version to released one.
jankoulaga 2e97247
Merge branch 'master' into NT-lighterweight-module
jankoulaga edf5d96
NT. Reverting test data. Ready for PR
jankoulaga 07bb071
NT. Fixing linting.
jankoulaga 9277360
NT. Fixing the email hash scenario.
jankoulaga 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,188 @@ | ||
import * as utils from 'src/utils.js'; | ||
import { gdprDataHandler, uspDataHandler } from '../../../src/adapterManager.js'; | ||
import { server } from 'test/mocks/xhr.js'; | ||
import { liveIntentIdSubmodule, reset as resetLiveIntentIdSubmodule, storage } from 'modules/liveIntentIdSystem.js'; | ||
|
||
const PUBLISHER_ID = '89899'; | ||
const defaultConfigParams = { params: {publisherId: PUBLISHER_ID} }; | ||
const responseHeader = {'Content-Type': 'application/json'}; | ||
|
||
describe('LiveIntentMinimalId', function() { | ||
let logErrorStub; | ||
let uspConsentDataStub; | ||
let gdprConsentDataStub; | ||
let getCookieStub; | ||
let getDataFromLocalStorageStub; | ||
let imgStub; | ||
|
||
beforeEach(function() { | ||
liveIntentIdSubmodule.setModuleMode('minimal'); | ||
imgStub = sinon.stub(utils, 'triggerPixel'); | ||
getCookieStub = sinon.stub(storage, 'getCookie'); | ||
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); | ||
logErrorStub = sinon.stub(utils, 'logError'); | ||
uspConsentDataStub = sinon.stub(uspDataHandler, 'getConsentData'); | ||
gdprConsentDataStub = sinon.stub(gdprDataHandler, 'getConsentData'); | ||
}); | ||
|
||
afterEach(function() { | ||
imgStub.restore(); | ||
getCookieStub.restore(); | ||
getDataFromLocalStorageStub.restore(); | ||
logErrorStub.restore(); | ||
uspConsentDataStub.restore(); | ||
gdprConsentDataStub.restore(); | ||
liveIntentIdSubmodule.setModuleMode('minimal'); | ||
resetLiveIntentIdSubmodule(); | ||
}); | ||
it('should not fire an event when getId', function() { | ||
uspConsentDataStub.returns('1YNY'); | ||
gdprConsentDataStub.returns({ | ||
gdprApplies: true, | ||
consentString: 'consentDataString' | ||
}) | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
expect(server.requests[0]).to.eql(undefined) | ||
}); | ||
|
||
it('should not return a decoded identifier when the unifiedId is not present in the value', function() { | ||
const result = liveIntentIdSubmodule.decode({ additionalData: 'data' }); | ||
expect(result).to.be.undefined; | ||
}); | ||
|
||
it('should initialize LiveConnect and send no data', function() { | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
liveIntentIdSubmodule.decode({}, defaultConfigParams); | ||
liveIntentIdSubmodule.getId(defaultConfigParams); | ||
liveIntentIdSubmodule.decode({}, defaultConfigParams); | ||
expect(server.requests.length).to.be.eq(0); | ||
}); | ||
|
||
it('should call the Custom URL of the LiveIntent Identity Exchange endpoint', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId({ params: {...defaultConfigParams.params, ...{'url': 'https://dummy.liveintent.com/idex'}} }).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/prebid/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should call the default url of the LiveIntent Identity Exchange endpoint, with a partner', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId({ params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'url': 'https://dummy.liveintent.com/idex', | ||
'partner': 'rubicon' | ||
} | ||
} }).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/rubicon/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should call the LiveIntent Identity Exchange endpoint, with no additional query params', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should log an error and continue to callback if ajax request errors', function() { | ||
getCookieStub.returns(null); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899'); | ||
request.respond( | ||
503, | ||
responseHeader, | ||
'Unavailable' | ||
); | ||
expect(logErrorStub.calledOnce).to.be.true; | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include the LiveConnect identifier when calling the LiveIntent Identity Exchange endpoint', function() { | ||
const oldCookie = 'a-xxxx--123e4567-e89b-12d3-a456-426655440000' | ||
getDataFromLocalStorageStub.withArgs('_li_duid').returns(oldCookie); | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}`); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include the LiveConnect identifier and additional Identifiers to resolve', function() { | ||
const oldCookie = 'a-xxxx--123e4567-e89b-12d3-a456-426655440000' | ||
getDataFromLocalStorageStub.withArgs('_li_duid').returns(oldCookie); | ||
getDataFromLocalStorageStub.withArgs('_thirdPC').returns('third-pc'); | ||
const configParams = { params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'identifiersToResolve': ['_thirdPC'] | ||
} | ||
}}; | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}&_thirdPC=third-pc`); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should include an additional identifier value to resolve even if it is an object', function() { | ||
getCookieStub.returns(null); | ||
getDataFromLocalStorageStub.withArgs('_thirdPC').returns({'key': 'value'}); | ||
const configParams = { params: { | ||
...defaultConfigParams.params, | ||
...{ | ||
'identifiersToResolve': ['_thirdPC'] | ||
} | ||
}}; | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899?_thirdPC=%7B%22key%22%3A%22value%22%7D'); | ||
request.respond( | ||
200, | ||
responseHeader, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
}); |
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
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.
@jankoulaga Will this result in both libraries (LiveConnect and MinimalLiveConnect) being added to the bundle?
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.
Hey @msm0504 well, the bundle is generated by webpack, so no.
If this were pieced together without any treeshaking, then yes, both sources would have been added, however, the trick here is that at some point, there's an evaluation of a boolean which is either true or false, and that's how webpack will know which import will be used. Anything unused will be automatically removed from the bundle.