Add Yandex Metrika integration for tracking; update FindSliderBySlugTask to ensure active slides are filtered correctly based on time; enhance app.blade.php for conditional Yandex Metrika script inclusion based on environment.
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Containers\Widget\Tasks;
|
||||
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Carbon; // Убедитесь, что Carbon импортирован
|
||||
|
||||
class FindSliderBySlugTask
|
||||
{
|
||||
@@ -13,7 +13,7 @@ class FindSliderBySlugTask
|
||||
$cacheKey = 'slider_' . $slug;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHour(), function () use ($slug) {
|
||||
$now = Carbon::now(); // Получаем текущее время один раз
|
||||
$now = Carbon::now();
|
||||
|
||||
$slider = Slider::query()
|
||||
->where('slug', $slug)
|
||||
@@ -21,7 +21,13 @@ class FindSliderBySlugTask
|
||||
->with(['slides' => function($query) use ($now) {
|
||||
$query->where('is_active', true)
|
||||
->where('start_time', '<=', $now)
|
||||
->where('end_time', '>=', $now);
|
||||
// Добавляем условие для end_time
|
||||
->where(function ($q) use ($now) {
|
||||
// Показываем слайд, если end_time еще не наступил
|
||||
$q->where('end_time', '>=', $now)
|
||||
// ИЛИ если end_time вообще не указан (NULL)
|
||||
->orWhereNull('end_time');
|
||||
});
|
||||
}])
|
||||
->firstOrFail();
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class HandleInertiaRequests extends Middleware
|
||||
}
|
||||
return 'empty';
|
||||
},
|
||||
'yandex_metrika_id' => config('services.yandex_metrika.id'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ class HandleInertiaRequests extends Middleware
|
||||
}
|
||||
return 'empty';
|
||||
},
|
||||
'yandex_metrika_id' => config('services.yandex_metrika.id'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,8 @@ return [
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'yandex_metrika' => [
|
||||
'id' => env('YANDEX_METRIKA_ID'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
+10
-6
@@ -5,22 +5,17 @@ import 'virtual:svg-icons-register'
|
||||
|
||||
|
||||
import { createSSRApp, h } from 'vue';
|
||||
import { createInertiaApp } from '@inertiajs/vue3';
|
||||
import { createInertiaApp, router } from '@inertiajs/vue3';
|
||||
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
|
||||
import {linksReform} from "@/mixins/LinksReform.js";
|
||||
import cookieMixin from "@/mixins/cookieMixin.js";
|
||||
import store from '@/store/index.js';
|
||||
import '@vuepic/vue-datepicker/dist/main.css';
|
||||
|
||||
|
||||
|
||||
// const appName = import.meta.env.VITE_APP_NAME || 'НТГСПИ';
|
||||
|
||||
createInertiaApp({
|
||||
resolve: name => {
|
||||
const pages = import.meta.glob('./Pages/**/*.vue')
|
||||
return pages[`./Pages/${name}.vue`]()
|
||||
// resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue'))
|
||||
},
|
||||
setup({ el, App, props, plugin }) {
|
||||
return createSSRApp({ render: () => h(App, props) })
|
||||
@@ -37,4 +32,13 @@ createInertiaApp({
|
||||
},
|
||||
});
|
||||
|
||||
router.on('navigate', (event) => {
|
||||
const metrikaId = event.detail.page.props.yandex_metrika_id;
|
||||
|
||||
if (metrikaId && typeof ym === 'function') {
|
||||
ym(metrikaId, 'hit', window.location.href, {
|
||||
title: document.title,
|
||||
referer: event.detail.page.props.ziggy?.previous_url || document.referrer,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
@if (env('NGINX_ENV') === 'prod')
|
||||
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
|
||||
@endif
|
||||
{{-- <title inertia>{{ config('app.name', 'Laravel') }}</title>--}}
|
||||
{{-- <title inertia>{{ config('app.name', 'Laravel') }}</title>--}}
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
@@ -49,13 +49,32 @@
|
||||
scroll-padding: 6rem;
|
||||
scroll-behavior: smooth !important;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
<body class="">
|
||||
@inertia
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@if(config('services.yandex_metrika.id') && app()->environment('production'))
|
||||
<!-- Yandex.Metrika counter -->
|
||||
<script type="text/javascript">
|
||||
(function(m,e,t,r,i,k,a){
|
||||
m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||
m[i].l=1*new Date();
|
||||
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
||||
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
|
||||
})(window, document,'script','https://mc.yandex.ru/metrika/tag.js', 'ym');
|
||||
|
||||
ym({{ config('services.yandex_metrika.id') }}, 'init', {
|
||||
defer: true,
|
||||
webvisor:true,
|
||||
clickmap:true,
|
||||
ecommerce:"dataLayer",
|
||||
accurateTrackBounce:true,
|
||||
trackLinks:true
|
||||
});
|
||||
</script>
|
||||
<noscript><div><img src="https://mc.yandex.ru/watch/{{ config('services.yandex_metrika.id') }}" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||
<!-- /Yandex.Metrika counter -->
|
||||
@endif
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user