Keep AdSense rendering limited to anonymous visitors.

Show guest-only ad units on public pages and skip the AdSense script entirely for signed-in users.
This commit is contained in:
test
2026-09-20 14:49:34 +02:00
parent 37100ced3f
commit 17df4d0ad7
8 changed files with 135 additions and 8 deletions
+2 -1
View File
@@ -9,13 +9,14 @@
Renders nothing when:
- GOOGLE_ADSENSE_PUBLISHER_ID is not set in .env
- The visitor is authenticated
- User has not given consent (handled client-side via CSS class .ads-disabled)
--}}
@php
$publisherId = config('services.google_adsense.publisher_id');
@endphp
@if($publisherId)
@if($publisherId && ! auth()->check())
<div class="ad-unit-wrapper {{ $attributes->get('class', '') }}">
<ins class="adsbygoogle"
style="display:block"
+6 -2
View File
@@ -261,8 +261,8 @@
@inertiaHead
@endif
@if(config('services.google_adsense.publisher_id'))
{{-- Google AdSense — consent-gated loader --}}
@if(auth()->guest() && config('services.google_adsense.publisher_id'))
{{-- Google AdSense — guests only, consent-gated loader --}}
{{-- Script is only injected after the user accepts all cookies. --}}
{{-- If consent was given on a previous visit it fires on page load. --}}
<script>
@@ -297,6 +297,10 @@
})();
</script>
@endif
@guest
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6457864535683080" crossorigin="anonymous"></script>
@endguest
</head>
@php
$authBgRoutes = [
+13 -1
View File
@@ -100,8 +100,20 @@
@include('web.home.sections.news', ['items' => $props['news'] ?? []])
@include('web.home.sections.cta', ['isLoggedIn' => true])
@else
@foreach ($guestArtworkSections as $section)
@foreach ($guestArtworkSections as $index => $section)
@include('web.home.sections.artwork-section', $section)
@if($index === 0)
{{-- Skinbase Dashboard Horizontal — guests only --}}
<div class="mt-14 flex justify-center px-4 sm:px-6 lg:px-8">
<ins class="adsbygoogle w-full max-w-3xl"
style="display:block;text-align:center"
data-ad-client="ca-pub-6457864535683080"
data-ad-slot="8766048277"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
@endif
@endforeach
@include('web.home.sections.collections', ['collections' => $props['collections_trending'] ?: ($props['collections_featured'] ?: ($props['collections_editorial'] ?? []))])
@include('web.home.sections.world-spotlight', ['world' => $props['world_spotlight'] ?? null])