定制 yaroslawww/laravel-ad-director 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yaroslawww/laravel-ad-director

Composer 安装命令:

composer require yaroslawww/laravel-ad-director

包简介

Package to help you add advertising to your site.

关键字:

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Package to help you add advertising to your site.

Installation

Install the package via composer:

composer require yaroslawww/laravel-ad-director

Optionally you can publish the config file with:

php artisan vendor:publish --provider="AdDirector\ServiceProvider" --tag="config"

Supported services

Usage

If you use Google Publisher Tags, and use repeated sizes - you can easily configure global sizes with size mapping in any service provider - as GPT is singleton.

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]));
    }
}

On page controller you can configure set of advert locations.

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');
    }
}

Now there time to add scripts to template

<head>
    {!! \AdDirector\Facades\AdDirector::configurationScript() !!}
</head>
<body>
    <div id="header">
        {!! \AdDirector\Facades\AdDirector::adLocation('header-ads') !!}
    </div>
    <div id="content">
        <div>Content</div>
        <div>
            {!! \AdDirector\Facades\AdDirector::adLocation('medium-ads-ads') !!}
        </div>
        <div>Content</div>
    </div>
    <div id="footer">   
        {!! \AdDirector\Facades\AdDirector::adLocation('footer-ads') !!}
    </div>
    <script>
        {{-- There possible to add any js confitions, timeout, etc.. --}}
        {!! \AdDirector\Facades\AdDirector::displayScript() !!}
    </script>
</body>
</html>

Credits

  • Think Studio

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固