-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add missing VAST 4.1 Macros #342
Conversation
// <BlockedAdCategories> element is not parsed for now so the vastTracker | ||
// can't replace the macro with element value automatically. | ||
// The player need to pass it inside "macro" parameter when calling trackers | ||
'BLOCKEDADCATEGORIES', | ||
'ADCATEGORIES', // <Category> element is also not parsed for now. Same instructions as above | ||
'ADTYPE', //adType attribute of <Ad> element is not parsed for now. Same instructions as above | ||
'ADSERVINGID' // <AdServingId> element is also not parsed for now. Same instructions as above |
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.
I will open a PR when these elements are supported.
src/vast_tracker.js
Outdated
*/ | ||
verificationNotExecuted(macros = {}) { | ||
if ( | ||
!(this.ad && this.ad.adVerifications && this.ad.adVerifications.length) |
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.
this is a bit hard to read, we could just write:
!this.ad || !this.ad.adVerifications || !this.ad.adVerifications.length
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.
but I'm not sure we should do this check. IMO this should break if you try to call it when there is no adVerifications
. Or we should send an error. @rumesh what do you think?
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.
Y6es I agree, this function shouldn't be called if no adVerifications, but to be clean and robuste vast-client should send an error saying no adVerification.
Because if we do not have this check it will be an error like it wasn't handle properly by the vast-client.
So agree on this should break but not because accessing this.ad.adVerifications
while it's not defined but because we throw an error in this case
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.
Done !
…nt-js into missing-4.1-macros
…otExecuted tracker + unit test
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.
LGTM! Let's get another 👍 before merging
src/util/util.js
Outdated
const replacedUrlMacros = replaceUrlMacros(resolveURL, macros); | ||
resolvedURLs.push(replacedUrlMacros); |
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.
Do we really need to store it in this tempory const
?
Why not just do this
resolvedURLs.push(
replaceUrlMacros(resolveURL, macros)
);
src/util/util.js
Outdated
let supportedRemainingMacros = remainingMacros.filter( | ||
macro => supportedMacros.indexOf(macro) > -1 | ||
); | ||
if (!supportedRemainingMacros) { |
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.
if (!supportedRemainingMacros) { | |
if (supportedRemainingMacros.length === 0) { |
We know that filter
return an array, and for execution performance it's better to do this otherwise browser have to "cast" the array as a boolean before executing this
src/util/util.js
Outdated
const macro1 = `[${key}]`; | ||
const macro2 = `%%${key}%%`; | ||
replacedMacrosUrl = replacedMacrosUrl.replace(macro1, value); | ||
replacedMacrosUrl = replacedMacrosUrl.replace(macro2, value); |
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.
Let use power of regex for better performance
// this will match [${key}] and %%${key}%%
let macroRegex = new RegExp(`(?:\[|%%)([${key}])(?:\]|%%)`, 'g');
replacedMacrosUrl = replacedMacrosUrl.replace(macroRegex, value);
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.
Not only better performance btw, with the regexp 'g' option it will replace all the occurence while a normal replace will only replace the first.
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.
Sure, i replaced it. It was a legacy code that i should have optimized before using 😅
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.
👍
Description
Add support for VAST 4.1 Macros. Macros can now be replaced by their values when trackers are called.
Issue
#336
TODO
Type