New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

martinbutt/laravel-adsense

Display Adsense ads easily in Laravel 6.x, 7.x and 8.x
1,077 10
Install
composer require martinbutt/laravel-adsense
Latest Version:v2.0.1
PHP:^7.2||^8.0
Laravel:6 · 7 · 8
Older releases:5
License:MIT
Last Updated:Aug 20, 2021
Links: GitHub  ·  Packagist
Maintainer: martinbutt

Google Adsense Ads for Laravel 6.x, 7.x and 8.x

Latest Version Total Downloads Build Status StyleCI Scrutinizer Code Coverage License

Package for easily including Google Adsense Ad units in Laravel 6.x, 7.x and 8.x and Lumen. For use with Laravel 5.x use original Mastergalen/Adsense-Ads package.

Installation

1 - Dependency

In your project root run

The first step is using Composer to install the package and automatically update your composer.json file, you can do this by running:

composer require martinbutt/laravel-adsense

2 - Set up config file

Run php artisan config:publish martinbutt/laravel-adsense.

Edit the generated config file in /config/adsense.php to add your ad units

return [
    'client_id' => 'YOUR_CLIENT_ID', //Your Adsense client ID e.g. ca-pub-9508939161510421
    'ads' => [
        'responsive' => [
            'ad_slot' => 1111111111,
            'ad_format' => 'fluid',
            'ad_full_width_responsive' => true,
            'ad_style' => 'display:inline-block'
        ],
        'rectangle' => [
            'ad_slot' => 2222222222,
            'ad_style' => 'display:inline-block;width:300px;height:250px',
            'ad_full_width_responsive' => false,
            'ad_format' => 'auto'
        ]
    ]
];

3 - Register the provider with Laravel

You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your config/app.php file adding the following code at the end of your 'providers' section:

config/app.php

<?php

return [
    // ...
    'providers' => [
        MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider::class,
        // ...
    ],
    // ...
];
Lumen

Go to bootstrap/app.php file and add this line:

<?php
// ...

$app = new Laravel\Lumen\Application(
    dirname(__DIR__)
);

// ...

$app->register(MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider::class);

// ...

return $app;

4 - Register the alias with Laravel

Note: facades are not supported in Lumen.

You may get access to the Google Adsense Ads services using following facades:

  • MartinButt\Laravel\Adsense\Facades\AdsenseFacade

You can setup a short-version aliases for these facades in your config/app.php file. For example:

<?php

return [
    // ...
    'aliases' => [
        'Adsense' => MartinButt\Laravel\Adsense\Facades\AdsenseFacade::class,
        // ...
    ],
    // ...
];

5 - Configuration

Publish config

In your terminal type

php artisan vendor:publish

or

php artisan vendor:publish --provider="MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider"

Lumen does not support this command, for it you should copy the file src/resources/config/adsense.php to config/adsense.php of your project.

In adsense.php configuration file you can determine the properties of the default values and some behaviors.

Usage

Add {!! Adsense::javascript() !!} in your <head> tag.

To show ads, add {!! Adsense::ads('ads_unit') !!}, where ads_unit is one of your ads units in your config file (for example {!! Adsense::ads('responsive') !!}).

Use {!! Adsense::ads('ads_unit') !!} every time you want to show an ad.

Changelog

Please see the CHANGELOG.md file for more information on what has changed recently.

Credits

License

The Google Adsense Ads is open-sourced software licensed under the MIT license.
Please see the LICENSE.md file for more information.

Related Packages

mastergalen/adsense-ads

Display Adsense ads easily in Laravel.

11,253 11
usamamuneerchaudhary/adment

Production-grade ad & Google AdSense manager for Filament v5, placements, respon...

527 10
spotonlive/laravel-facebook-ads

Facebook integration for Laravel

17,057 19
ardyn/adsense

A convenient way to include Google AdSense ads within your pages.

1,676 4
edujugon/laravel-google-ads

Google Adwords API for Laravel

425,821 64

Version History

Version Released PHP Laravel License
v2.0.1 ^7.2||^8.0 ^6.0||^7.0||^8.0 MIT
v2.0 ^7.2||^8.0 ^6.0||^7.0||^8.0 MIT
v1.4 ^7.2 ^6.0||^7.0||^8.0 MIT
v1.3 ^7.2 ^6.0||^7.0 MIT
v1.2 ^7.2 ^6.0 MIT