Skip to content

Commit

Permalink
Omit empty tracking URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp committed Aug 30, 2016
1 parent d797fc5 commit e63a42c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 47 deletions.
8 changes: 2 additions & 6 deletions src/factory/impression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import {Impression} from 'iab-vast-model'

export default ($impression) => {
const impression = new Impression()
if ($impression._value) {
impression.id = $impression.id
impression.uri = $impression._value
} else {
impression.uri = $impression
}
impression.id = $impression.id
impression.uri = $impression._value
return impression
}
3 changes: 2 additions & 1 deletion src/factory/linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import createClick from './click'
import createTimeOffset from './time-offset'
import inheritCreative from '../inherit/creative'
import mapTrackingEvents from '../util/map-tracking-events'
import isNonEmptyString from '../util/is-non-empty-string'

const mapVideoClicks = ($videoClicks, videoClicks) => {
if ($videoClicks.clickThrough) {
Expand All @@ -22,7 +23,7 @@ export default ($creative) => {
const $linear = $creative.linear
const linear = new Linear()
inheritCreative($creative, linear)
if (typeof $linear.skipoffset === 'string' && $linear.skipoffset.length > 0) {
if (isNonEmptyString($linear.skipoffset)) {
linear.skipoffset = createTimeOffset($linear.skipoffset)
}
if ($linear.adParameters) {
Expand Down
17 changes: 11 additions & 6 deletions src/inherit/ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ import {AdSystem} from 'iab-vast-model'
import createCreative from '../factory/creative'
import createExtension from '../factory/extension'
import createImpression from '../factory/impression'
import isNonEmptyString from '../util/is-non-empty-string'

const hasValue = ($node) => ($node != null && isNonEmptyString($node._value))

export default ($ad, $impl, ad) => {
ad.id = $ad.id
ad.sequence = $ad.sequence
if ($impl.adSystem) {
if ($impl.adSystem != null) {
ad.adSystem = new AdSystem()
ad.adSystem.name = $impl.adSystem._value
ad.adSystem.version = $impl.adSystem.version
}
if ($impl.impression) {
ad.impressions.push(...$impl.impression.map(createImpression))
if ($impl.impression != null) {
ad.impressions.push(...$impl.impression
.filter(hasValue)
.map(createImpression))
}
if ($impl.error) {
if ($impl.error != null && hasValue($impl.error)) {
ad.error = $impl.error._value
}
if ($impl.creatives && $impl.creatives.creative) {
if ($impl.creatives != null && Array.isArray($impl.creatives.creative)) {
$impl.creatives.creative.map(createCreative).forEach((creative) => {
ad.creatives.add(creative)
})
}
if ($impl.extensions && $impl.extensions.extension) {
if ($impl.extensions != null && Array.isArray($impl.extensions.extension)) {
ad.extensions.push(...$impl.extensions.extension.map(createExtension))
}
return ad
Expand Down
1 change: 1 addition & 0 deletions src/util/is-non-empty-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (str) => (typeof str === 'string' && str.length > 0)
22 changes: 13 additions & 9 deletions src/util/map-tracking-events.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import {TrackingEvent} from 'iab-vast-model'
import createTimeOffset from '../factory/time-offset'
import isNonEmptyString from './is-non-empty-string'

export default ($trackingEvents, trackingEvents) => {
if ($trackingEvents != null && Array.isArray($trackingEvents.tracking)) {
for (const $tracking of $trackingEvents.tracking) {
const conf = new TrackingEvent()
conf.uri = $tracking._value
if ($tracking.event === 'progress' &&
typeof $tracking.offset === 'string' && $tracking.offset.length > 0) {
conf.offset = createTimeOffset($tracking.offset)
}
trackingEvents.add($tracking.event, conf)
if ($trackingEvents == null || !Array.isArray($trackingEvents.tracking)) {
return
}
for (const $tracking of $trackingEvents.tracking) {
if (!isNonEmptyString($tracking._value)) {
continue
}
const conf = new TrackingEvent()
conf.uri = $tracking._value
if ($tracking.event === 'progress' && isNonEmptyString($tracking.offset)) {
conf.offset = createTimeOffset($tracking.offset)
}
trackingEvents.add($tracking.event, conf)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
],
"id": "1",
"impressions": [
{
"_type": "Impression",
"uri": {
}
}
],
"sequence": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@
],
"id": "1",
"impressions": [
{
"_type": "Impression",
"uri": {
}
}
],
"sequence": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
],
"id": "1",
"impressions": [
{
"_type": "Impression",
"uri": {
}
}
],
"sequence": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
],
"id": "1",
"impressions": [
{
"_type": "Impression",
"uri": {
}
}
],
"sequence": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@
],
"id": "1",
"impressions": [
{
"_type": "Impression",
"uri": {
}
}
],
"sequence": 1
}
Expand Down

0 comments on commit e63a42c

Please sign in to comment.