shakaran/adstxtparser

A open source implemation in PHP of Ads.txt Specification Version 1.0.1 (OpenRTB working group)

1.0 2018-06-14 00:28 UTC

This package is auto-updated.

Last update: 2024-10-29 13:28:42 UTC


README

PRs Welcome Build Status Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

A open source implentation in PHP of Ads.txt Specification Version 1.0.1 (OpenRTB working group)

Graph Ads.txt

Note: ADS = Authorized Digital Sellers DSP = Demand Side Platforms

WHAT IS ADS.TXT?

Ads.txt is an initiative by the Interactive Advertising Bureau to enable publishers to take control over who can sell their ad inventory.

Since 01 Nov 2017 Google is filtering traffic based on ads.txt

It is a simple logic of the textfile as mechanism to fight adfraud

Widely accepted and implemented by more and more publishers, ssp and dsp.

Can prevent advertisers from buying invalid traffic.

Check more info about it.

Donate

I am a freelancer Senior Backend Engineer working on my free time for develop this.

If you want pay me some beer or severals to appreciate the efforts:

paypal

Setup

Install with composer with only:

composer require shakaran/adstxtparser

TECHNICAL NOTES

Requires PHP 7.0+.

How to use

A quick use to instanciate and run over a domain is:

use AdsTxtParser\Parser;

$parser = new Parser();
$parser->readExternalFile('http://estaticos.elmundo.es');

Note: that you only have to pass as argument the domain.

After you already fetch the data in the Parser object, you can query about errors:

$errors = $parser->getErrors();

Or warnings:

$warnings = $parser->getWarnings();

Or get the variables defined:

$variables = $parser->getVariables();

Or get the fields defined:

$fields = $parser->getFields();

Or get the comments defined:

$comments = $parser->getComments();

Even more complex operations, as know the list of resellers:

$resellers = $parser->getResellers();

Or the list or directs:

$directs = $parser->getDirects();

A complex example using all the options could be:

try
        {
            // By default localhost
            $parser = new Parser();
            $parser->readExternalFile('http://estaticos.elmundo.es');

            // More examples to test:
            // https://elpais.com/ads.txt
            // https://www.elconfidencial.com/ads.txt
        }
        catch(AdsFileNotFound $e)
        {
            echo $e->getMessage();
        }

        $comments = $parser->getComments();
        // var_dump($comments);

        $errors = $parser->getErrors();
        //var_dump($errors);

        $warnings = $parser->getWarnings();
        // var_dump($warnings);

        $fields = $parser->getFields();
        // var_dump($fields);

        $variables = $parser->getVariables();
        //var_dump($variables);

        $resellers = $parser->getResellers();
        //var_dump(count($resellers));

        $directs = $parser->getDirects();
        //var_dump(count($directs));

Tests

Executing the tests:

Run a local webserver under Test directory:

cd Tests; sudo php -S localhost:80
vendor/phpunvendor/phpunit/phpunit/phpunit --configuration=Tests/phpunit.xml --include-path=Tests

License

AGPLv3 or later, see LICENSE file for more details.