Google Analytics Configuration Alternative
Alternatif konfigurasi ini digunakan ketika hit google analytics tidak berjalan pada badaso landy theme
- Pada
.env
tambahkan konfigurasi baru pada kunciMIX_ANALYTICS_TRACKING_ID
- Pada
resources/views
buat folder dengan namapartials
- Pada folder
resources/views/partials
buat file blade dengan namagoogle-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>
- Pada
resources/views
buat folder dengan namavendor/landy-theme
- Salin file
vendor/badaso/landy-theme/src/resources/views/app.blade.php
ke folderresources/views/vendor/landy-theme
- Memanggil
resources/views/partials/google-analytics.blade.php
padaresources/views/vendor/landy-theme/app.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
...
<!-- Google Analytics -->
@include('partials.google-analytics')
<!-- End Google Analytics -->
...
</head>
...
</html>