PHP code example of yaroslawww / laravel-ad-director
1. Go to this page and download the library: Download yaroslawww/laravel-ad-director library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yaroslawww / laravel-ad-director example snippets
use AdDirector\Facades\AdDirector;
use AdDirector\GPT\SizeMap;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
AdDirector::gpt()
// Add size with mapping example
::addSize('leaderboard', new \AdDirector\GPT\Size(
// Allowed sizes
[[728, 90], [320, 50]],
// Responsive size map
(new SizeMap())
// Tablet
->addSize([1024, 768], [728, 90])
->addSize([980, 690], [728, 90])
// Desktop
->addSize([1050, 200], [728, 90])
// Mobile
->addSize([640, 480], [320, 50])
// Any size
->addSize([0, 0], [320, 50])
))
// Add static size without responsive
::addSize('medium_rectangle', new \AdDirector\GPT\Size([300, 250]));
}
}
use AdDirector\Facades\AdDirector;
use AdDirector\GPT\Slot;
class FrontpageController extends Controller
{
public function __invoke()
{
AdDirector::gpt()
->addLocation(Slot::make(
'/1234567/FOO_Leaderboard',
// Size name from global config
'leaderboard',
// Optional, if not set will be generated automatically
'div-gpt-ad-1234567890001-0'
// Location identifier, if not set will be used slot's adUnitPath
)
// Set targeting
->addTarget('foo', 'bar')
->addTarget('baz', ['foo', 'bar'])
, 'header-ads')
->addLocation(Slot::make(
'/1234567/FOO_Medium',
'medium_rectangle',
), 'medium-ads')
->addLocation(Slot::make(
'/1234567/BAR_Leaderboard',
// Manually set custom size
new \AdDirector\GPT\Size(
[[728, 90], [320, 50]],
(new SizeMap())
->addSize([1024, 768], [728, 90])
->addSize([640, 480], [320, 50])
->addSize([0, 0], [320, 50])
),
), 'footer-ads');
return view('frontpage');
}
}