Skip to content

Commit 9896997

Browse files
committed
update view interceptor docs
1 parent abac0a8 commit 9896997

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

v1/framework/03-modules/05-view-interceptors.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,53 @@ no context aware available
152152
* `Interceptor::AFTER_SIDEBAR_ITEMS`
153153
* `Interceptor::SIDEBAR_END`
154154

155+
### Head Point
156+
157+
no context aware available
158+
<x-converge::divide
159+
title="interception points"
160+
color="success"
161+
/>
162+
163+
* `Interceptor::HEAD_START`
164+
* `Interceptor::HEAD_END`
165+
166+
These are particularly useful for injecting scripts like analytics tools (e.g., Google Analytics).
167+
You can place your analytics script in a Blade component for clean reuse. For example:``resources/views/components/analytics/gtags.blade.php`` :
168+
169+
```html
170+
@production
171+
<!-- gtags -->
172+
@if (config('services.google.analytics_id'))
173+
<script async
174+
src="https://www.googletagmanager.com/gtag/js?id={{ config('services.google.analytics_id') }}"></script>
175+
<script>
176+
window.dataLayer = window.dataLayer || [];
177+
178+
function gtag() {
179+
dataLayer.push(arguments);
180+
}
181+
gtag('js', new Date());
182+
gtag('config', '{{ config('services.google.analytics_id') }}');
183+
</script>
184+
@endif
185+
@endproduction
186+
```
187+
188+
You can register the component in a specific module or globally via a service provider:
189+
190+
```php
191+
/**
192+
* Bootstrap any application services.
193+
*/
194+
public function boot(): void
195+
{
196+
197+
app(ViewInterceptor::class)
198+
->registerViewInterceptor(Interceptor::HEAD_END, fn() => view('components.analytics.gtags'));
199+
}
200+
```
201+
155202
Other points coming soon...
156203

157204

0 commit comments

Comments
 (0)