VAST XML responses for online video advertisers.
npm install vast-xml```
npm install vast-xml
`javascript
var VAST = require('vast-xml');
var vast = new VAST();
var ad = vast.attachAd({
id : 1
, structure : 'inline'
, sequence : 99
, Error: 'http://error.err'
, AdTitle : 'Common name of the ad'
, AdSystem : { name: 'Test Ad Server', version : '1.0' }
});
`
`javascript
var VAST = require('vast-xml');
var vast = new VAST();
var ad = vast.attachAd({
id : 1
, structure : 'inline'
, sequence : 99
, Error: 'http://error.err'
, Extensions: ['
, AdTitle : 'Common name of the ad'
, AdSystem : { name: 'Test Ad Server', version : '1.0' }
});
`
`javascript`
ad.attachImpression({
id: "23"
, url: "http://impression.com"
});
ad.attachImpression({
id: "sample-server"
, url: "http://sample-impression.com"
});
`javascript`
var creative = ad.attachCreative('Linear', {
AdParameters : '
, Duration : '00:00:30'
});
creative.attachMediaFile('http://domain.com/file.ext', {
type: "video/mp4"
, bitrate: "320"
, minBitrate: "320"
, maxBitrate: "320"
, width: "640"
, height: "360"
, scalable: "true"
, maintainAspectRatio: "true"
, codec: ""
, apiFramework: "VPAID"
});
creative.attachTrackingEvent('creativeView', 'http://creativeview.com');
creative.attachVideoClick('ClickThrough', 'http://click-through.com');
Create _skippable linear creative_ by adding a skipoffset attribute when attaching creative. Attach skip and/or progress tracking events. See below:
`javascript`
var creative = ad.attachCreative('Linear', {
AdParameters : '
, skipoffset: '00:00:05'
, Duration : '00:00:30'
});
// ...
creative.attachTrackingEvent('skip', 'http://skipevent.com');
creative.attachTrackingEvent('progress', 'http://zing-zang.com', '00:00:15.000');
`javascript`
var icon = creative.attachIcon({
program : 'foo'
, height : 250
, width : 300
, xPosition : 'left'
, yPosition : 'top'
, apiFramework : 'VPAID'
, offset : '01:05:09'
, duration : '00:00:00'
});
icon.attachResource('StaticResource', 'http://domain.com/file.gif', 'image/gif');
icon.attachClick('IconClickThrough', 'http://icon-click-through.com');
icon.attachTrackingEvent('IconViewTracking', 'http://icon-view-tracking.com');
`javascript`
var creative = ad.attachCreative('NonLinear', {
id : 99
, width : 90
, height: 10
, expandedWidth : 90
, expandedHeight : 45
, scalable : false
, maintainAspectRatio : false
, minSuggestedDuration : '00:00:00'
, apiFramework : 'VPAID'
});
`javascript`
var creative = ad.attachCreative('CompanionAd', {
width : 300
, height : 250
, type : 'image/jpeg'
, url : 'http://companionad.com/image.jpg'
});
creative.attachTrackingEvent('creativeView', 'http://companionad.com/creativeView');
`javascript`
vast.xml({ pretty : true, indent : ' ', newline : '\n' });
`xml`
`javascript
var VAST = require('vast-xml');
var vast = new VAST({VASTErrorURI: 'http://adserver.com/noad.gif'});
vast.xml({ pretty : true, indent : ' ', newline : '\n' });
`
`xml`
npm test validates the test builds. The validation is done against the VAST .xsd file, made available by the IAB.
Currently included in the test suite are:
1. linear ad
* with companion
* with icon
1. non-linear ad
* with companion
1. wrapper ad
The VAST spec is, well vast, and contains a lot of different corner cases.
Pull requests, feedback and collaboration in fully rounding-out this module is more than welcome.
xmllint is a good tool for validating XML. As a helper, this repo contains the VAST .xsd and to validate a VAST file, follow:
`bash``
$ xmllint --noout --schema ./test/files/vast3_draft.xsd /path/to/the/vast.xml