Enabled Google Analytics tracking via configuration

This commit is contained in:
Chris Kankiewicz
2020-01-23 11:17:53 -07:00
parent 6611aecfba
commit 82bf3c47d3
4 changed files with 25 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ HIDE_VCS_FILES=true
DISPLAY_READMES=true
GOOGLE_ANALYTICS_ID=false
DATE_FORMAT="Y-m-d H:i:s"
MAX_HASH_SIZE=1000000000

View File

@@ -10,6 +10,14 @@ return [
*/
'dark_mode' => Helpers::env('DARK_MODE'),
/**
* Your Google analytics tracking ID.
* Expected format: 'UA-123456789-0'.
*
* Default value: false
*/
'google_analytics_id' => Helpers::env('GOOGLE_ANALYTICS_ID'),
/**
* Default date format. For additional info on date formatting see:
* https://www.php.net/manual/en/function.date.php.

View File

@@ -0,0 +1,11 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config("google_analytics_id") }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
{% if config('google_analytics_id', false) %}
gtag('config', '{{ config("google_analytics_id") }}');
{% endif %}
</script>

View File

@@ -6,6 +6,10 @@
<link rel="icon" href="{{ config('dark_mode') ? asset('images/favicon.dark.png') : asset('images/favicon.light.png') }}">
<link rel="stylesheet" href="{{ asset('app.css') }}">
{% if config('google_analytics_id', false) %}
{% include 'components/google-analytics.twig' %}
{% endif %}
<title>{{ path == '.' ? 'Home' : path }} &bull; Directory Lister</title>
<div id="app" class="flex flex-col min-h-screen font-sans {{ config('dark_mode') ? 'dark-mode' : 'light-mode' }}">