36 lines
1.4 KiB
PHP
Executable File
36 lines
1.4 KiB
PHP
Executable File
@php
|
|
$host = request()?->getHost();
|
|
|
|
if (! is_string($host) || $host === '') {
|
|
$host = parse_url((string) config('app.public_url', config('app.url', '')), PHP_URL_HOST) ?: null;
|
|
}
|
|
|
|
$host = is_string($host) ? strtolower(trim($host)) : null;
|
|
$siteMode = strtolower(trim((string) config('netgescon.maintenance.site_mode', config('netgescon.site_mode', 'app'))));
|
|
$measurementMap = (array) config('services.google.analytics_measurement_ids', []);
|
|
$hostMap = (array) ($measurementMap['hosts'] ?? []);
|
|
$modeMap = (array) ($measurementMap['modes'] ?? []);
|
|
$measurementId = '';
|
|
|
|
if (is_string($host) && $host !== '' && array_key_exists($host, $hostMap)) {
|
|
$measurementId = trim((string) $hostMap[$host]);
|
|
}
|
|
|
|
if ($measurementId === '' && $siteMode !== '' && array_key_exists($siteMode, $modeMap)) {
|
|
$measurementId = trim((string) $modeMap[$siteMode]);
|
|
}
|
|
|
|
if ($measurementId === '') {
|
|
$measurementId = trim((string) config('services.google.analytics_measurement_id', ''));
|
|
}
|
|
@endphp
|
|
|
|
@if ($measurementId !== '')
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id={{ $measurementId }}"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
gtag('config', '{{ $measurementId }}');
|
|
</script>
|
|
@endif |