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

Add missing VAST 4.1 Macros #342

Merged
merged 11 commits into from
Oct 31, 2019
Merged

Add missing VAST 4.1 Macros #342

merged 11 commits into from
Oct 31, 2019

Conversation

ZacharieTFR
Copy link
Contributor

@ZacharieTFR ZacharieTFR commented Oct 24, 2019

Description

Add support for VAST 4.1 Macros. Macros can now be replaced by their values when trackers are called.

Issue

#336

TODO

  • Unit tests
  • Documentation

Type

  • Breaking change
  • Enhancement
  • Fix
  • Documentation
  • Tooling

@ZacharieTFR ZacharieTFR added enhancement feature wip Work in progress 3.0 3.0 roadmap hacktoberfest Participate in 2019's hacktoberfest! labels Oct 24, 2019
Comment on lines +40 to +46
// <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
Copy link
Contributor Author

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.

spec/vast_trackers.spec.js Outdated Show resolved Hide resolved
spec/vast_trackers.spec.js Outdated Show resolved Hide resolved
src/util/util.js Outdated Show resolved Hide resolved
src/util/util.js Outdated Show resolved Hide resolved
src/vast_tracker.js Show resolved Hide resolved
*/
verificationNotExecuted(macros = {}) {
if (
!(this.ad && this.ad.adVerifications && this.ad.adVerifications.length)
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

src/vast_tracker.js Outdated Show resolved Hide resolved
src/vast_tracker.js Outdated Show resolved Hide resolved
src/vast_tracker.js Outdated Show resolved Hide resolved
src/vast_tracker.js Outdated Show resolved Hide resolved
@ZacharieTFR ZacharieTFR added breaking-change and removed wip Work in progress labels Oct 28, 2019
@ZacharieTFR ZacharieTFR self-assigned this Oct 29, 2019
docs/api/vast-tracker.md Outdated Show resolved Hide resolved
docs/api/vast-tracker.md Outdated Show resolved Hide resolved
Copy link
Contributor

@kobawan kobawan left a 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
Comment on lines 53 to 54
const replacedUrlMacros = replaceUrlMacros(resolveURL, macros);
resolvedURLs.push(replacedUrlMacros);
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Comment on lines 102 to 105
const macro1 = `[${key}]`;
const macro2 = `%%${key}%%`;
replacedMacrosUrl = replacedMacrosUrl.replace(macro1, value);
replacedMacrosUrl = replacedMacrosUrl.replace(macro2, value);
Copy link
Contributor

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);

Copy link
Contributor

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.

Copy link
Contributor Author

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 😅

Copy link
Contributor

@rumesh rumesh left a comment

Choose a reason for hiding this comment

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

👍

@ZacharieTFR ZacharieTFR merged commit 778e3b9 into 3.0-version Oct 31, 2019
@ZacharieTFR ZacharieTFR deleted the missing-4.1-macros branch October 31, 2019 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 3.0 roadmap breaking-change enhancement feature hacktoberfest Participate in 2019's hacktoberfest!
Development

Successfully merging this pull request may close these issues.

None yet

3 participants