Alternatif Konfigurasi Google Analytics
Alternatif konfigurasi ini digunakan ketika hit google analytics tidak berjalan pada tema badaso linky.
- Di
.env
tambahkan konfigurasi baru pada kunciMIX_ANALYTICS_TRACKING_ID
- Dalam
resources/views
buat folder bernamapartials
- Pada folder resources/views/partials buat file blade dengan nama google-analytics.blade.php dengan isi sebagai berikut:
@php
$measurement_id = env('MIX_ANALYTICS_TRACKING_ID', null);
// output : UA-2155XXXXX-X
@endphp
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="{{ "https://www.googletagmanager.com/gtag/js?id={$measurement_id}" }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ $measurement_id }}');
</script>
<script>
// record location analytics
let href = window.location.href
setInterval(() => {
let listenHref = window.location.href
if (listenHref != href) {
let page_title = document.title
let {
href: page_location,
pathname: page_path
} = window.location
let configurationSet = {
page_title,
page_location,
page_path,
}
gtag('config', '{{ $measurement_id }}', configurationSet);
href = listenHref
}
}, 1000);
</script>
- Didalam
resources/views
buat folder baru bernamavendor/linky-theme
- Salin file
vendor/badaso/linky-theme/src/resources/layout/app.blade.php
ke folderresources/views/vendor/linky-theme
- Panggil
resources/views/partials/google-analytics.blade.php
inresources/views/vendor/linky-theme/app.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
...
<!-- Google Analytics -->
@include('partials.google-analytics')
<!-- End Google Analytics -->
...
</head>
...
</html>