AdsTxtParser
[
][3]
, (*1)
, (*2)
A open source implentation in PHP of Ads.txt Specification Version 1.0.1 (OpenRTB working group), (*3)
, (*4)
Note:
ADS = Authorized Digital Sellers
DSP = Demand Side Platforms, (*5)
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., (*6)
Since 01 Nov 2017 Google is filtering traffic based on ads.txt, (*7)
It is a simple logic of the textfile as mechanism to fight adfraud, (*8)
Widely accepted and implemented by more and more publishers, ssp and dsp., (*9)
Can prevent advertisers from buying invalid traffic., (*10)
Check more info about it., (*11)
Donate
I am a freelancer Senior Backend Engineer working on my free time for develop this., (*12)
If you want pay me some beer or severals to appreciate the efforts:, (*13)
, (*14)
Setup
Install with composer with only:, (*15)
composer require shakaran/adstxtparser
TECHNICAL NOTES
Requires PHP 7.0+., (*16)
How to use
A quick use to instanciate and run over a domain is:, (*17)
use AdsTxtParser\Parser;
$parser = new Parser();
$parser->readExternalFile('http://estaticos.elmundo.es');
Note: that you only have to pass as argument the domain., (*18)
After you already fetch the data in the Parser object,
you can query about errors:, (*19)
$errors = $parser->getErrors();
Or warnings:, (*20)
$warnings = $parser->getWarnings();
Or get the variables defined:, (*21)
$variables = $parser->getVariables();
Or get the fields defined:, (*22)
$fields = $parser->getFields();
Or get the comments defined:, (*23)
$comments = $parser->getComments();
Even more complex operations, as know the list of resellers:, (*24)
$resellers = $parser->getResellers();
Or the list or directs:, (*25)
$directs = $parser->getDirects();
A complex example using all the options could be:, (*26)
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:, (*27)
Run a local webserver under Test directory:, (*28)
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., (*29)