Giter VIP home page Giter VIP logo

php-vast's Introduction

Stand With Ukraine

SWUbanner


PHP-VAST

Build Total Downloads Coverage Status

โญ VAST Ad generator and parser library on PHP.

Specs

Install

Install library through composer:

composer require sokil/php-vast

Quick start

// create document
$factory = new \Sokil\Vast\Factory();
$document = $factory->create('4.1');

// insert Ad section
$ad1 = $document
    ->createInLineAdSection()
    ->setId('ad1')
    ->setAdSystem('Ad Server Name')
    ->setAdTitle('Ad Title')
    ->addImpression('http://ad.server.com/impression', 'imp1');

// create creative for ad section
$linearCreative = $ad1
    ->createLinearCreative()
    ->setDuration(128)
    ->setId('013d876d-14fc-49a2-aefd-744fce68365b')
    ->setAdId('pre')
    ->setVideoClicksClickThrough('http://entertainmentserver.com/landing')
    ->addVideoClicksClickTracking('http://ad.server.com/videoclicks/clicktracking')
    ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick')
    ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start')
    ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop');

// add closed caption file (Closed Caption support starts on VAST 4.1)
$linearCreative
    ->createClosedCaptionFile()
    ->setLanguage('en-US')
    ->setType('text/srt')
    ->setUrl('http://server.com/cc.srt');
    
// add 100x100 media file
$linearCreative
    ->createMediaFile()
    ->setProgressiveDelivery()
    ->setType('video/mp4')
    ->setHeight(100)
    ->setWidth(100)
    ->setBitrate(2500)
    ->setUrl('http://server.com/media1.mp4');

// add 200x200 media file
$linearCreative
    ->createMediaFile()
    ->setProgressiveDelivery()
    ->setType('video/mp4')
    ->setHeight(200)
    ->setWidth(200)
    ->setBitrate(2500)
    ->setUrl('http://server.com/media2.mp4');
    
// get dom document
$domDocument = $document->toDomDocument();

// get XML string
echo $document;

This will generate:

<?xml version="1.0" encoding="UTF-8"?>
<VAST version="2.0">
    <Ad id="ad1">
        <InLine>
            <AdSystem>Ad Server Name</AdSystem>
            <AdTitle><![CDATA[Ad Title]]></AdTitle>
            <Impression id="imp1"><![CDATA[http://ad.server.com/impression]]></Impression>
            <Creatives>
                <Creative>
                    <Linear>
                        <Duration>00:02:08</Duration>
                        <VideoClicks>
                            <ClickThrough><![CDATA[http://entertainmentserver.com/landing]]></ClickThrough>
                            <ClickTracking><![CDATA[http://ad.server.com/videoclicks/clicktracking]]></ClickTracking>
                            <CustomClick><![CDATA[http://ad.server.com/videoclicks/customclick]]></CustomClick>
                        </VideoClicks>
                        <TrackingEvents>
                            <Tracking event="start"><![CDATA[http://ad.server.com/trackingevent/start]]></Tracking>
                            <Tracking event="pause"><![CDATA[http://ad.server.com/trackingevent/stop]]></Tracking>
                        </TrackingEvents>
                        <MediaFiles>
                            <ClosedCaptionFiles>
                              <ClosedCaptionFile language="en-US" type="text/srt">
                                  <![CDATA[http://server.com/cc.srt]]>
                              </ClosedCaptionFile>
                            </ClosedCaptionFiles>
                            <MediaFile delivery="progressive" type="video/mp4" height="100" width="100" bitrate="2500">
                                <![CDATA[http://server.com/media1.mp4]]>
                            </MediaFile>
                            <MediaFile delivery="progressive" type="video/mp4" height="200" width="200" bitrate="2500">
                                <![CDATA[http://server.com/media2.mp4]]>
                            </MediaFile>
                        </MediaFiles>
                    </Linear>
                </Creative>
            </Creatives>
        </InLine>
    </Ad>
</VAST>

Custom Specification Support

VAST document elements are completely described in it's specification, but some Ad servers may add support for custom elements and attributes. This library strictly follows specification, generally because two dialects of VAST may conflict with each other. You may write our own dialect by overriding element builder and create any elements and attributes you want.

The VAST dialect is described in \Sokil\Vast\ElementBuilder class. By overriding it you may create instances of your own classes and add there any setters.

First let's create a class for MediaFile and add some custom attributes:

<?php

namespace Acme\Vast\ElementBuilder\Element;

use Sokil\Vast\Creative\InLine\Linear\MediaFile;

class AcmeMediaFile extends MediaFile
{
    public function setMinDuration($seconds)
    {
        $seconds = (int)$seconds;
        if ($seconds <= 0) {
            thow new \InvalidArgumentException('Invalid min duration specified, must be positive int')
        }
        
        $this->domElement->setAttribute('minDuration', $seconds);
        
        return $this;
    }
}

Now we need to override the default element builder and create our own MediaFile factory method:

<?php

namespace Acme\Vast\ElementBuilder;

use Sokil\Vast\ElementBuilder;
use Acme\Vast\ElementBuilder\Element\AcmeMediaFile;

class AcmeElementBuilder extends ElementBuilder
{
    /**
     * <Ad><InLine><Creatives><Creative><Linear><MediaFile>
     *
     * @param \DOMElement $mediaFileDomElement
     *
     * @return AcmeMediaFile
     */
    public function createInLineAdLinearCreativeMediaFile(\DOMElement $mediaFileDomElement)
    {
        return new AcmeMediaFile($mediaFileDomElement);
    }
}

Now we need to confugure VAST factory to use overridden element builder:

<?php

use Acme\Vast\ElementBuilder\AcmeElementBuilder;
use Sokil\Vast\Factory;

$elementBuilder = new AcmeElementBuilder();
$factory = new Factory($elementBuilder);

$document = $factory->create('4.1');

$ad = $document->createInLineAdSection();
$creative = $ad->createLinearCreative();
$mediaFile = $creative->createMediaFile();

$mediaFile->setMinDiration(10);

If you have an AD server and want to add support for your custom tag, create your own library with custom elements and element builder, or add a pull request to this library.

php-vast's People

Contributors

bramdevries avatar dorantor avatar farshidboroomand avatar fb-ts avatar leon486 avatar peter279k avatar simoheinonen avatar sokil avatar vendin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-vast's Issues

Multiple mediaFile

Hi @sokil ,
first of all thanks for the library.

I was wondering, can I add more than one mediafile into the creative? if yes, how? could you please provide me with an example?

 $ad->createLinearCreative()
            ->setDuration(128)
            ->setVideoClicksClickThrough('http://entertainmentserver.com/landing')
            ->addVideoClicksClickTracking('http://ad.server.com/videoclicks/clicktracking')
            ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick')
            ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start')
            ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop')
            ->createMediaFile()
            ->setProgressiveDelivery()
            ->setType('video/mp4')
            ->setHeight(100)
            ->setWidth(100)
            ->setBitrate(2500)
            ->setUrl('http://server.com/media.mp4');

Thanks in advance,
Alessandro

Request for Vast 3.0 function

Hi,

I find your codes so helpful. I'm currently developing an ad pod type ad which is supported on Vast 3.0 but the current code is missing a function for adding sequence eg which is necessary for ad pod to work.

Can you add this code to the Ads.php on your next release? Sokil\Vast\Ad

public function setSequence($id)
{
$this->_domElement->setAttribute('sequence', $id);
return $this;
}

Hope I can get your response as soon as possible.. Thank you :)

getValuesOfArrayNode() broken

When using AbstractAdNode::getDomElement() (using AbstractNode::getValuesOfArrayNode()) an error is thrown because getDomElement() does return DOMText instead of DOMElement.

When changing

protected function getDomElement() { return $this->adDomElement->firstChild; }

to

protected function getDomElement() { return $this->adDomElement; }

it works.

In the following call to AbstractNode::getValuesOfArrayNode() an iteration is done but index 0 is used in every iteration instead of $i, so the iteration is supposed to look like this I think:

for ($i = 0; $i < $domElements->length; $i++) { $values[$i] = $domElements->item($i)->nodeValue; }

What do you think? Are my assumptions correct? Thanks!

Help

Hi Sokil, Will you help me out with setting up the php-vast on my server, so I can run my own vast tag video url's for media campaigns.

Best regards,

Michael

Companion-Node?

Hi,

is it possible to have a companion-zone for video+display or audio+display ads?

Kind regards,
Dirk

Uncaught Exception: Ad type InLine not allowed

I am getting the below exception when i tried to create the VAST 2.0 document as per the READ me file

// create document
$document = \Sokil\Vast\Document::create('2.0');

// insert Ad section
$ad1 = $document->createInLineAdSection()
    ->setId('ad1')
    ->setAdSystem('Ad Server Name')
    ->setAdTitle('Ad Title')
    ->setImpression('http://ad.server.com/impression');

// create creative for ad section
$ad1->createLinearCreative()
    ->setDuration(128)
    ->setVideoClicksClickThrough('http://entertainmentserver.com/landing')
    ->addVideoClicksClickTracking('http://ad.server.com/videoclicks/clicktracking')
    ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick')
    ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start')
    ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop')
    ->createMediaFile()
        ->setProgressiveDelivery()
        ->setType('video/mp4')
        ->setHeight(100)
        ->setWidth(100)
        ->setUrl('http://server.com/media.mp4');

// get dom document
$domDocument = $document->toDomDocument();

// get XML string
echo $document;

//Exception is appearing in the below lines

 // Check Ad type
        $adTypeClassName = '\\Sokil\\Vast\\Ad\\' . $type;
        if(!class_exists($adTypeClassName)) {
            throw new \Exception('Ad type ' . $type . ' not allowed');
        }
        

VideoClicks instead of VideoClips

There is no VideoClips node in VAST. Shouldn't it be VideoClicks in \Ad\InLine\Creative\Linear.php

I think this function is wrong:

private function _getVideoClipsDomElement()
    {
        // create container
        if($this->_videoClicksDomElement) {
            return $this->_videoClicksDomElement;
        }

        $this->_videoClicksDomElement = $this->_domElement->getElementsByTagName('VideoClips')->item(0);
        if($this->_videoClicksDomElement) {
            return $this->_videoClicksDomElement;
        }

        $this->_videoClicksDomElement = $this->_domElement->ownerDocument->createElement('VideoClips');
        $this->_domElement->firstChild->appendChild($this->_videoClicksDomElement);

        return $this->_videoClicksDomElement;
    }

Add extra attr in tags

i need to set some extra attr to Creative tag as below :

.....

where can i set the items in my laravel application.

also i need to define specific events instead of fullScreen & exit fullscreen.

Composer

Hi, I've install the php-vast package, however I am unable to use the the packages namespaces. When I take a look at the composer class map I can not see the sokil namespaces. I have run composer dump-autoload but still no sokil namespaces ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.