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

Taboola Adapter - Adding Optional Chaining #11

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export const userData = {

export const internal = {
getPageUrl: (refererInfo = {}) => {
return refererInfo.page || getWindowSelf().location.href;
return refererInfo?.page || getWindowSelf().location?.href;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmadlob getWindowSelf().location can be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the check

},
getReferrer: (refererInfo = {}) => {
if (refererInfo.ref) {
if (refererInfo?.ref) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmadlob here we don't need the ?, because we check if (refererInfo.ref)
we can change the if else to be same as the page url

Copy link
Contributor Author

@ahmadlob ahmadlob Sep 22, 2022

Choose a reason for hiding this comment

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

the condition here checks if "refererInfo.ref" is null. the chaining I added -> If "refererInfo" is null - evaluate "undefined" and the general condition to be falsy.
It prevent an error to be thrown when refererIndo is undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it to be much more shorter

return refererInfo.ref;
} else {
return getWindowSelf().document.referrer;
return getWindowSelf().document?.referrer;
}
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ function getSiteProperties({publisherId, bcat = []}, refererInfo) {
return {
id: publisherId,
name: publisherId,
domain: refererInfo?.domain || window.location.host,
domain: refererInfo?.domain || window.location?.host,
page: getPageUrl(refererInfo),
ref: getReferrer(refererInfo),
publisher: {
Expand Down