Skip to content

Commit

Permalink
Add Google Analytics 4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ipasechnikov committed Feb 4, 2023
1 parent 9011f75 commit 23db376
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ The `index.md` page should use layout `home`, which is the layout that displays

Another thing you can do to customize the index page is show the description of your blog between the title and the menu. To do this, just edit `_config.yml` and change `theme_config.show_description` to `true`.

### Enabling Google Analytics

To enable Google Analytics, add the following lines to your Jekyll site:

```yaml
google_analytics: G-XXXXXXXX
```

Google Analytics will only appear in production, i.e., `JEKYLL_ENV=production`

### Pro tips

#### Dark mode for images
Expand Down
9 changes: 9 additions & 0 deletions _includes/google_analytics.html
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 4 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" />
Expand Down

0 comments on commit 23db376

Please sign in to comment.