Analytics - Google - v1.0.0
Configuration Reference
Complete reference for config/analytics-google.php. Publish with:
php artisan vendor:publish --tag=analytics-google-config
The published file is the source of truth — this page mirrors it and explains each key.
Sections
Client-side tracking
'tracking' => [
'measurement_id' => env( 'GA4_MEASUREMENT_ID' ),
'enabled' => env( 'GA4_TRACKING_ENABLED', true ),
'config' => [
'anonymize_ip' => true,
],
'respect_consent' => true,
],
measurement_id— The GA4 measurement ID (G-XXXXXXX). Leave empty to disable the@ga4Snippetdirective entirely; it emits nothing when this is missing so a shared layout is safe across environments.enabled— Master switch for the tracker. Whenfalse,Gtag::render()returns an empty string regardless of measurement ID. Handy for staging or CI.config— Extragtag('config', ...)options serialized to JSON in the emitted snippet. Keep values to primitives (strings, bools, numbers) — the encoder usesJSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOTso nothing can break out of the surrounding<script>tag, but complex objects still make the resulting snippet noisy.respect_consent— Whentrue(default), the emitted snippet setsgtag('consent', 'default', { analytics_storage: 'denied' })unlesswindow.__apAnalyticsConsent.analytics === true. Set tofalseto fire tracking unconditionally on every page load.
Full details on the emitted markup and the consent flag: Client-Side Tracking and Consent Integration.
Server-side reporting
'reporting' => [
'property_id' => env( 'GA4_PROPERTY_ID' ),
'api_base' => 'https://analyticsdata.googleapis.com/v1beta',
'timeout' => 30,
'cache_ttl' => 300,
],
property_id— The GA4 numeric property ID Data API queries target. Overridable per call via the third argument toGa4DataClient::runReport(). Missing when a query runs →ReportingException::missingConfiguration().api_base— Base URL for the GA4 Data API. Rarely needs to change; kept configurable so tests can point at a fake server.timeout— Request timeout for a singlerunReportcall, in seconds. Trips aReportingException::transportFailure()onConnectionException.cache_ttl— Cache TTL in seconds. Set to0to disable caching. Cache keys are hashed from(connection identity, property ID, request payload)so distinct users cannot see each other's cached rows.
Provider registration
'provider_name' => 'google-ga4',
provider_name— The name this package registers under with theartisanpack-ui/analyticsparent'sextend()API. Add this name toartisanpack.analytics.active_providerson the parent to route tracking through its consent gate. See Analytics Parent Integration.
OAuth scopes
'scopes' => [
'https://www.googleapis.com/auth/analytics.readonly',
],
scopes— The Google OAuth scopes this package needs. Contributed to the base package'sScopeRegistryvia theap.google.scopesfilter hook when both are installed. Only affects the base's consent screen — this key does nothing when the base is missing.
HTTP routes
'routes' => [
'enabled' => true,
'prefix' => 'analytics-google',
'middleware' => [ 'web', 'auth' ],
],
enabled— Whenfalse, the two reporting routes are not registered. Correct choice for headless / API-only apps. The Livewire components still work — they call the fetchers directly.prefix— Prefix mounted under/. Full route paths become<prefix>/overviewand<prefix>/top-content.middleware— Middleware stack applied to the two routes.webmounts them under the session guard the auth middleware needs;authrequires an authenticated user so the controllers can resolve aGoogleConnection.
Full endpoint reference: HTTP Endpoints.
Related pages
- Environment variables — every env var this package reads.
- Configuration — the same content organized by task rather than by section.
- HTTP Endpoints — response shapes and error codes for the two reporting routes.