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

VAST 3.0 Companion ads #280

Merged
merged 2 commits into from
Mar 14, 2019
Merged

VAST 3.0 Companion ads #280

merged 2 commits into from
Mar 14, 2019

Conversation

kobawan
Copy link
Contributor

@kobawan kobawan commented Feb 14, 2019

Description

Support VAST 3.0 Companion ads

Added properties:

CreativeCompanion:

  • required: String|null

CompanionAd:

  • assetWidth: Number|null
  • assetHeight: Number|null
  • expandedWidth: Number|null
  • expandedHeight: Number|null
  • apiFramework: String|null
  • adSlotID: String|null
  • adParameters: String|null
  • xmlEncoded: Boolean|null

Renamed properties:

CompanionAd:

  • staticResources: Array<{ url: String, creativeType: String|null }> (Renamed from staticResource)
  • htmlResources: Array (Renamed from htmlResource)
  • iframeResources: Array (Renamed from iframeResource)

Removed property:

CreativeCompanion:

  • trackingEvents: Object
  • type: String|null (It is now part of staticResources)

Type

  • Breaking change
  • Enhancement
  • Fix
  • Documentation
  • Tooling

@kobawan kobawan self-assigned this Feb 14, 2019
@eliamaino-fp eliamaino-fp added this to the 3.0 milestone Feb 14, 2019
@kobawan kobawan changed the base branch from jest-babel7 to 3.0-version February 20, 2019 16:13
if (trackingEventsElement) {
parserUtils
.childrenByName(trackingEventsElement, 'Tracking')
.forEach(trackingElement => {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

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?

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 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.

Copy link
Contributor

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

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

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
}

Copy link
Contributor Author

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;
Copy link
Contributor

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?

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

Copy link
Contributor Author

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

Copy link
Contributor

@eliamaino-fp eliamaino-fp left a comment

Choose a reason for hiding this comment

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

Looks good

@eliamaino-fp eliamaino-fp merged commit 1fab4db into 3.0-version Mar 14, 2019
@kobawan kobawan deleted the companions-3.0 branch July 26, 2019 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants