-
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
VAST 3.0 Companion ads #280
Conversation
43795b2
to
c035b9e
Compare
if (trackingEventsElement) { | ||
parserUtils | ||
.childrenByName(trackingEventsElement, 'Tracking') | ||
.forEach(trackingElement => { |
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.
why are we using forEach
here and map
on line 21?
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.
because companionAd.trackingEvents
is an object not an array
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 sure I get what you mean, both times you chain to childrenByName
which always returns an array.
companionAd.width = companionResource.getAttribute('width'); | ||
companionAd.height = companionResource.getAttribute('height'); | ||
companionAd.companionClickTrackingURLTemplates = []; | ||
.map(companionResource => { |
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.
Maybe we can make the scenario in which we call childrenByName
+ some array iteration faster, by making children extraction accepting a custom function to apply:
function applyToChildrenByName(node, nodeName, fn) {
const children = [];
const childNodes = node.childNodes;
for (const childKey in childNodes) {
const child = childNodes[childKey];
if (child.nodeName === name) {
children.push(fn(child)); // This will save us one iteration
}
}
return children;
}
Or
function childrenByName(node, nodeName, fn) {
const hasFunctionToApply = typeof fn === 'function'
const children = [];
const childNodes = node.childNodes;
for (const childKey in childNodes) {
const child = childNodes[childKey];
if (child.nodeName === name) {
hasFunctionToApply ? children.push(fn(child)) : children.push(child);
}
}
return children;
}
What do you think about this idea?
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 think this will make the code less readable in my opinion. Mostly because we would be passing the entire parsing function as a callback :/ I also don't think that iterating twice in this case is a problem (if it would be a large array, maybe...). I don't have a very strong opinion on this though.
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.
You are right, it doesn't have a noticeable impact on execution perf.
companionAd.width = companionResource.getAttribute('width'); | ||
companionAd.height = companionResource.getAttribute('height'); | ||
companionAd.companionClickTrackingURLTemplates = []; | ||
.map(companionResource => { |
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.
You are right, it doesn't have a noticeable impact on execution perf.
for (let i = 0; i < companionAttrs.length; i++) { | ||
attributes[companionAttrs[i].nodeName] = companionAttrs[i].nodeValue; | ||
} | ||
const companionAd = new CompanionAd(attributes); |
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 like this approach of passing at least the attributes to the constructor (and the class logic will take care of assigning them to the right properties).
Maybe we can factor this in an util method in order to use it in the future too, something like getAttributes
:
function getAttributes(node) {
const attributes = {};
const nodeAttributes = node.attributes;
for (let i = 0; i < companionAttrs.length; i++) {
attributes[nodeAttributes[i].nodeName] = nodeAttributes[i].nodeValue;
}
return attributes
}
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.
created function parseAttributes
companionAd.htmlResource = | ||
parserUtils.parseNodeText( | ||
parserUtils.childByName(companionResource, 'HTMLResource') | ||
) || null; |
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.
According to the VAST spec
Each element must specify at least one resource file that may be one of:
<StaticResource>
,<IFrameResource>
or<HTMLResource>
What is the approach we want to take when multiple resources are provided?
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 didn't understand from the specs whether you could have multiple StaticResources
for example, or just multiple resources of different types. either way we were still only assigning one resource per type previously
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.
added support for multiple of the same resources
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.
Looks good
Description
Support VAST 3.0 Companion ads
Added properties:
CreativeCompanion:
CompanionAd:
Renamed properties:
CompanionAd:
Removed property:
CreativeCompanion:
Type