From 7cbfbc094aa72435fb088c71e2d5b3f39bc60182 Mon Sep 17 00:00:00 2001
From: Ilia Pasechnikov <ilia.pasechnikov@gmail.com>
Date: Sat, 4 Feb 2023 11:45:23 +0900
Subject: [PATCH] Add Google Analytics 4 support

---
 _includes/google_analytics.html | 9 +++++++++
 _includes/head.html             | 4 ++++
 2 files changed, 13 insertions(+)
 create mode 100644 _includes/google_analytics.html

diff --git a/_includes/google_analytics.html b/_includes/google_analytics.html
new file mode 100644
index 000000000..32b3c9b8c
--- /dev/null
+++ b/_includes/google_analytics.html
@@ -0,0 +1,9 @@
+<!-- Google tag (gtag.js) -->
+<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
+<script>
+  window.dataLayer = window.dataLayer || [];
+  function gtag(){dataLayer.push(arguments);}
+  gtag('js', new Date());
+
+  gtag('config', '{{ site.google_analytics }}');
+</script>
\ No newline at end of file
diff --git a/_includes/head.html b/_includes/head.html
index 77daa89c0..9b89e6e9e 100644
--- a/_includes/head.html
+++ b/_includes/head.html
@@ -13,6 +13,10 @@
 
   {%-seo title=false-%}
   {%-feed_meta-%}
+  
+  {%- if jekyll.environment == 'production' and site.google_analytics -%}
+    {%- include google_analytics.html -%}
+  {%- endif -%}
 
   <link rel="shortcut icon" type="image/x-icon" href="{{ site.favicon | relative_url }}" />
   <link rel="stylesheet" href="{{ "/assets/css/main.css" | relative_url }}" />