PHPackages                             bhargavdetroja/nativephp-google-mobile-ads - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bhargavdetroja/nativephp-google-mobile-ads

ActiveNativephp-plugin[Utility &amp; Helpers](/categories/utility)

bhargavdetroja/nativephp-google-mobile-ads
==========================================

Google Mobile Ads (AdMob) plugin for NativePHP Mobile — Banner, Interstitial, Rewarded, and App Open ads on Android and iOS.

v1.1.1(1mo ago)32MITPHP ^8.2

Since Jun 21Compare

[ Source](https://github.com/BhargavDetroja/google-mobile-ads)[ Packagist](https://packagist.org/packages/bhargavdetroja/nativephp-google-mobile-ads)[ Docs](https://github.com/bhargavdetroja/nativephp-google-mobile-ads)[ RSS](/packages/bhargavdetroja-nativephp-google-mobile-ads/feed)WikiDiscussions Synced 2w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

NativePHP Google Mobile Ads
===========================

[](#nativephp-google-mobile-ads)

Add **Google AdMob** ads to your [NativePHP Mobile](https://nativephp.com) app in minutes. No Kotlin, no Swift, no Gradle edits.

Works with **any frontend** — Livewire, React, Vue, Alpine.js, or plain JavaScript.

Supports **Banner**, **Interstitial**, **Rewarded**, **Rewarded Interstitial**, and **App Open** on Android and iOS.

---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 12+
- NativePHP Mobile 3+
- An [AdMob account](https://admob.google.com) (free)

---

Installation
------------

[](#installation)

### 1. Install the package

[](#1-install-the-package)

```
composer require bhargavdetroja/nativephp-google-mobile-ads
```

### 2. Publish the config

[](#2-publish-the-config)

```
php artisan vendor:publish --tag=google-mobile-ads-config
```

### 3. Add your AdMob IDs to `.env`

[](#3-add-your-admob-ids-to-env)

```
# App IDs — from AdMob console → Apps (one per platform)
ADMOB_APP_ID=ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX       # Android
ADMOB_IOS_APP_ID=ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX   # iOS

# Ad Unit IDs — from AdMob console → Ad units
ADMOB_BANNER_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_INTERSTITIAL_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_REWARDED_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_REWARDED_INTERSTITIAL_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_APP_OPEN_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_ANCHORED_ADAPTIVE_BANNER_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
ADMOB_INLINE_ADAPTIVE_BANNER_AD_UNIT_ID=ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX
```

> **Not ready for real IDs?** Leave the values empty — when `APP_ENV` is not `production`, the plugin automatically uses Google's official demo IDs so you always see real test ads.

### 4. Run native install

[](#4-run-native-install)

```
php artisan native:install --force
```

Both App IDs are injected into native configs automatically from your `.env`. No vendor files to edit.

---

Configuration
-------------

[](#configuration)

`config/google-mobile-ads.php` gives you full control over ad placements, test mode, and the kill-switch.

### Kill-switch

[](#kill-switch)

Disable all ads globally with one env key — useful for premium users or A/B testing.

```
ADMOB_ENABLED=false
```

### Test mode

[](#test-mode)

Automatically on when `APP_ENV != production`. Override if needed:

```
ADMOB_TEST_MODE=true
```

When active, Google's official demo IDs are substituted automatically — your real Ad Unit IDs are never used.

### Named slots

[](#named-slots)

Slots are named ad placements defined in your config. They support different IDs per platform:

```
// config/google-mobile-ads.php
'slots' => [
    'home_banner'    => env('ADMOB_BANNER_AD_UNIT_ID'),

    // Different ID per platform:
    'level_complete' => [
        'android' => env('ADMOB_INTERSTITIAL_ANDROID'),
        'ios'     => env('ADMOB_INTERSTITIAL_IOS'),
    ],
],
```

---

Showing Ads
-----------

[](#showing-ads)

### Option A — Blade component (banner only)

[](#option-a--blade-component-banner-only)

Drop a banner anywhere in your Blade views. Show/hide is handled automatically when the component mounts and unmounts.

```
{{-- Uses the 'banner' slot from your config --}}

{{-- Custom slot name --}}

```

### Option B — PHP Facade

[](#option-b--php-facade)

```
use NativePHP\GoogleMobileAds\Facades\GoogleMobileAds;

// Initialize once on app boot
GoogleMobileAds::initialize();

// Banner
GoogleMobileAds::showBanner('banner', position: 'bottom');
GoogleMobileAds::hideBanner();

// Interstitial — load first, show when ready
GoogleMobileAds::loadInterstitial('interstitial');
GoogleMobileAds::showInterstitial();

// Rewarded
GoogleMobileAds::loadRewarded('rewarded');
GoogleMobileAds::showRewarded();

// Rewarded Interstitial
GoogleMobileAds::loadRewardedInterstitial('rewarded_interstitial');
GoogleMobileAds::showRewardedInterstitial();

// App Open
GoogleMobileAds::loadAppOpen('app_open');
GoogleMobileAds::showAppOpen();
```

### Option C — JavaScript (React, Vue, Alpine, plain JS)

[](#option-c--javascript-react-vue-alpine-plain-js)

The JS bridge accepts raw ad unit IDs. Slot resolution and test-mode substitution happen server-side via the Blade component or PHP Facade.

```
import {
    initialize,
    showBanner, hideBanner,
    loadInterstitial, showInterstitial,
    loadRewarded, showRewarded,
    loadRewardedInterstitial, showRewardedInterstitial,
    loadAppOpen, showAppOpen,
    onAdLoaded, onAdClosed, onRewardEarned, onAdEvent,
} from 'vendor/bhargavdetroja/nativephp-google-mobile-ads/resources/js/index.js';

// Initialize
await initialize();

// Banner — pass the resolved ID from your Blade/PHP layer
await showBanner('ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX', 'bottom', 'adaptive');
await hideBanner();

// Interstitial
await loadInterstitial('ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX');
await showInterstitial();

// Rewarded
await loadRewarded('ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX');
await showRewarded();
```

Pass the resolved ID from Blade so test-mode is respected:

```

    const BANNER_ID = '{{ app("google-mobile-ads")->resolveAdUnitId("banner") }}';
    const REWARDED_ID = '{{ app("google-mobile-ads")->resolveAdUnitId("rewarded") }}';

```

---

Listening to Events
-------------------

[](#listening-to-events)

### In JavaScript — works with any framework

[](#in-javascript--works-with-any-framework)

```
import { onAdLoaded, onAdClosed, onRewardEarned, onAdEvent } from '...';

// Convenience helpers — return an unsubscribe function
const stopLoaded = onAdLoaded(({ adType, adUnitId }) => {
    console.log(`${adType} ad ready`);
});

onAdClosed(({ adType }) => {
    if (adType === 'interstitial') loadInterstitial(INTERSTITIAL_ID); // pre-load next
});

onRewardEarned(({ rewardType, rewardAmount }) => {
    addCoinsToUI(rewardAmount);
});

// Listen to any event by PHP class name
onAdEvent('NativePHP\\GoogleMobileAds\\Events\\AdFailedToLoad', ({ adType, errorMessage }) => {
    console.warn(`${adType} failed: ${errorMessage}`);
});

// Clean up (React/Vue component unmount)
stopLoaded();
```

**React:**

```
useEffect(() => {
    loadRewarded(REWARDED_ID);
    const stop = onRewardEarned(({ rewardAmount }) => addCoins(rewardAmount));
    return stop; // cleans up on unmount
}, []);
```

**Vue:**

```
onMounted(() => {
    loadRewarded(REWARDED_ID);
    const stop = onRewardEarned(({ rewardAmount }) => addCoins(rewardAmount));
    onUnmounted(stop);
});
```

### In PHP — standard Laravel events

[](#in-php--standard-laravel-events)

```
use NativePHP\GoogleMobileAds\Events\RewardEarned;
use NativePHP\GoogleMobileAds\Events\AdLoaded;
use NativePHP\GoogleMobileAds\Events\AdClosed;

// Any Laravel listener, queued job, or Livewire component:
public function handle(RewardEarned $event): void
{
    // $event->rewardType   → e.g. "coins"
    // $event->rewardAmount → e.g. 50
    auth()->user()->increment('coins', $event->rewardAmount);
}
```

Register in `AppServiceProvider`:

```
Event::listen(RewardEarned::class, GrantRewardListener::class);
```

**Livewire:**

```
protected $listeners = [
    AdLoaded::class     => 'onAdLoaded',
    AdClosed::class     => 'onAdClosed',
    RewardEarned::class => 'onRewardEarned',
];
```

---

All Events
----------

[](#all-events)

EventPropertiesWhen it fires`AdLoaded``$adType`, `$adUnitId`Ad is ready to show`AdFailedToLoad``$adType`, `$adUnitId`, `$errorCode`, `$errorMessage`Ad failed to load`AdOpened``$adType`Full-screen ad appeared`AdClosed``$adType`Full-screen ad was dismissed`AdImpression``$adType`Ad recorded an impression`AdClicked``$adType`User tapped the ad`RewardEarned``$rewardType`, `$rewardAmount`User completed a rewarded ad`$adType` values: `banner`, `interstitial`, `rewarded`, `rewarded_interstitial`, `app_open`

---

Going to Production
-------------------

[](#going-to-production)

1. Add your real Ad Unit IDs to `.env`.
2. Set `APP_ENV=production` — test mode turns off automatically.
3. Run `php artisan native:install --force`.
4. Build your release: `php artisan native:run android` / `php artisan native:run ios`.

---

Troubleshooting
---------------

[](#troubleshooting)

**App crashes on iOS launch**`ADMOB_IOS_APP_ID` is missing or wrong in your `.env`. Set it to your real iOS App ID and run `php artisan native:install --force`.

**Ads not showing in development**Test mode is likely on — this is correct behaviour. You should still see Google demo ads. If you see nothing, make sure you called `initialize()` and that you're on a real device (not iOS Simulator).

**`unknown slot` exception**You passed a slot name that isn't defined in `config/google-mobile-ads.php`. Either add it to `slots`, or pass a raw `ca-app-pub-...` ID directly.

**Interstitial/Rewarded "not loaded" error**You must call `load*()` and wait for the `AdLoaded` event before calling `show*()`.

**iOS Simulator shows no ads**Google Mobile Ads SDK does not support iOS Simulator. Use a real iPhone.

**Android emulator shows no ads**The AVD must use a **Google APIs** system image — not plain Android or Google Play.

**Validate plugin setup**

```
php artisan native:plugin:validate
```

---

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f11f8c72cd5d1e81f30795fa51cbcd48adccf2ba1a3bb8facdacb2cdd8bf0e28?d=identicon)[bhargavdetroja](/maintainers/bhargavdetroja)

---

Tags

laraveladsmobileandroidiosnativephpadmobgoogle-mobile-ads

### Embed Badge

![Health badge](/badges/bhargavdetroja-nativephp-google-mobile-ads/health.svg)

```
[![Health](https://phpackages.com/badges/bhargavdetroja-nativephp-google-mobile-ads/health.svg)](https://phpackages.com/packages/bhargavdetroja-nativephp-google-mobile-ads)
```

###  Alternatives

[nativephp/mobile

NativePHP for Mobile

1.1k102.1k123](/packages/nativephp-mobile)[marcin-orlowski/laravel-api-response-builder

Helps building nice, normalized and easy to consume Laravel REST API.

852505.1k4](/packages/marcin-orlowski-laravel-api-response-builder)[chiiya/laravel-passes

Laravel library for creating iOS and Android Wallet Passes

37124.4k](/packages/chiiya-laravel-passes)[codexshaper/laravel-pwa

Laravel Progressive Web App

153.1k](/packages/codexshaper-laravel-pwa)[nativephp/mobile-starter

The skeleton application for NativePHP for Mobile.

203.0k](/packages/nativephp-mobile-starter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
