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

https://github.com/tbuchok/vast-xml/issues/34 #35

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,49 @@ 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' }
});
```

### Ad extensions

```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: ['<xml>data</xml>'] // accepts an array or string of XML, warning: XML is not validated by this library!
, AdTitle : 'Common name of the ad'
, AdSystem : { name: 'Test Ad Server', version : '1.0' }
});
```

### AdVerifications (VAST 4.1)

```javascript
var VAST = require('vast-xml');

var vast = new VAST({version: '4.1'});
var ad = vast.attachAd({
id : 'AdVerificationsExample'
, structure : 'wrapper'
, AdSystem : { name : '2.0', version : '2.0' }
, Error : 'https://error.url.com/path/p?error=true'
, AdVerifications: [{ vendor: 'thirdPartyVendor-com.omid'
, JavaScriptResource: { browserOptional: 'false', resourceUrl: 'https://path.to/adVerification/script.js'}
, trackingEvents: [{ event:'verificationNotExecuted', url: 'https://error.url.com/p?event=verificationNotExecuted?' }, {event:'secondEvent', url: 'https://second.url/p?secondEvent=true' }]
, VerificationParameters: 'Parameter=one&Parameter=two'
}]
, VASTAdTagURI : 'https://path.to.original/vast.xml'
});
```

## Attach Impression tracking URLs

```javascript
Expand Down Expand Up @@ -133,6 +171,7 @@ vast.xml({ pretty : true, indent : ' ', newline : '\n' });
<AdTitle>Common name of the ad</AdTitle>
<Description/>
<Survey/>
<Error><![CDATA[http://error.err]]></Error>
<Impression id="23">http://impression.com</Impression>
<Impression id="sample-server">http://sample-impression.com</Impression>
<Creatives>
Expand Down
44 changes: 41 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var xml = function(options) {
if (ad.structure.toLowerCase() === 'wrapper') {
var wrapper = Ad.element('Wrapper');
wrapper.element('AdSystem', ad.AdSystem.name, { version : ad.AdSystem.version });
wrapper.element('VASTAdTagURI', ad.VASTAdTagURI);
wrapper.element('VASTAdTagURI').cdata(ad.VASTAdTagURI);
if (ad.Error)
wrapper.element('Error').cdata(ad.Error);
ad.impressions.forEach(function(impression) {
if (track) wrapper.element('Impression').cdata(impression.url);
});
Expand Down Expand Up @@ -56,7 +58,8 @@ var xml = function(options) {
icon.element(r.type, r.uri, (r.creativeType) ? { creativeType : r.creativeType } : {});
});
});
creativeType.element('Duration', c.Duration);
//creativeType.element('Duration', c.Duration);
creativeType.element('Duration').cdata(c.Duration);
var trackingEvents = creativeType.element('TrackingEvents');
c.trackingEvents.forEach(function(trackingEvent){
if (track) {
Expand All @@ -68,7 +71,7 @@ var xml = function(options) {
if (c.AdParameters) creativeType.element('AdParameters').cdata(c.AdParameters);
var videoClicks = creativeType.element('VideoClicks');
c.videoClicks.forEach(function(videoClick){
videoClicks.element(videoClick.type, videoClick.url, { id : videoClick.id });
videoClicks.element('ClickThrough', videoClick.attributes).cdata(videoClick.url)
});
var mediaFiles = creativeType.element('MediaFiles');
c.mediaFiles.forEach(function(mediaFile) {
Expand Down Expand Up @@ -97,6 +100,41 @@ var xml = function(options) {
if (r.adParameters) companion.element('AdParameters', r.adParameters.data, { xmlEncoded : r.adParameters.xmlEncoded });
});
});
if (ad.Extensions) {
var extensions;
if(inline != void 0) extensions = inline.element('Extensions');
if(wrapper != void 0) extensions = wrapper.element('Extensions');
[].concat(ad.Extensions).forEach(function(extension) {
extensions.element('Extension', {type: 'AdVerifications'}).raw(extension);
});
}

if (ad.AdVerifications){
// VAST 4.1 necessary
var adVerifications;
if(wrapper != void 0) adVerifications = wrapper.element('AdVerifications');

[].concat(ad.AdVerifications).forEach(function(currentVerifiction){

var ad_verifications = adVerifications.element('Verification', {vendor: currentVerifiction.vendor});

[].concat(currentVerifiction).forEach(function(verif) {
// browserOptional -> true would signify that it's our native script -> e.g. to run in iOS' JSContext
// false meaning that the resource needs a true JS environment
ad_verifications.element('JavaScriptResource', {browserOptional: verif.JavaScriptResource.browserOptional}).cdata(verif.JavaScriptResource.resourceUrl);

if(verif.trackingEvents) {
var trackElementsNode = ad_verifications.element('TrackingEvents');
var currentTrackingEvent = verif.trackingEvents;
[].concat(currentTrackingEvent).forEach(function(currentTrackingEvent){
trackElementsNode.element('Tracking', {event: currentTrackingEvent.event}).cdata(currentTrackingEvent.url);
});
}
ad_verifications.element('VerificationParameters').cdata(verif.VerificationParameters);
}); // end of concat each Verification Node
});
}

});
return response.end(options);
};
Expand Down
1 change: 1 addition & 0 deletions lib/ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Ad(settings) {
this.Error = settings.Error;
this.Description = settings.Description;
this.Advertiser = settings.Advertiser;
this.AdVerifications = settings.AdVerifications; // vast 4.1
this.surveys = [];
this.attachSurvey = function(settings) {
var survey = { url : settings.url }
Expand Down