Skip to content

Install on Laravel

Terminal window
composer require terragamingmedia/laravel-ads

The service provider is discovered automatically. To publish the config file:

Terminal window
php artisan vendor:publish --tag=tgm-config
Terminal window
TGM_HOST=tgmads.example.com

Once your CNAME is verified, the host is all you need. Before that, use the shared host and your ids:

Terminal window
TGM_HOST=cdn.terramedia-sandbox.com
TGM_PROPERTY=PROP-…
TGM_PUBLISHER=PUB-…
TGM_IN_ARTICLE_UNIT=TGM-…-INART
TGM_ARTICLE_SELECTOR=".post-content"

TGM_ENABLED=false turns the tag off, for example on local environments.

In the <head> of your main layout:

<x-tgm-site-tag />

or @tgmSiteTag. With a Content Security Policy, the component adds the nonce from Vite::cspNonce() (or spatie/laravel-csp) automatically. You can also pass nonce="…".

In any Blade view:

<x-tgm-ad unit="TGM-ABC-HRS01" />

or @tgmAd('TGM-ABC-HRS01'). The same unit can appear more than once per page. In-article ads are automatic.

  • Inertia (React or Vue): keep <x-tgm-site-tag /> in app.blade.php and place units with the React or Vue package (<TgmAd unit="…" />). See React and Vue.
  • Livewire wire:navigate and Turbo update the URL with pushState. The tag starts a new page view by itself. Wrap the floating unit in @persist('tgm-floating') so it survives navigation.