Skip to content

Commit

Permalink
adding netlify env variables for google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
JugglerX committed Feb 18, 2019
1 parent 1cf0eaa commit 15458d1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,2 +1,3 @@
source "https://rubygems.org"
gem 'github-pages'
gem 'github-pages'
gem 'jekyll-environment-variables'
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -114,6 +114,8 @@ GEM
rouge (~> 2)
jekyll-default-layout (0.1.4)
jekyll (~> 3.0)
jekyll-environment-variables (1.0.0)
jekyll (~> 3.0)
jekyll-feed (0.11.0)
jekyll (~> 3.3)
jekyll-gist (1.5.0)
Expand Down Expand Up @@ -243,6 +245,7 @@ PLATFORMS

DEPENDENCIES
github-pages
jekyll-environment-variables

BUNDLED WITH
1.17.1
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -25,4 +25,4 @@ Serif is a beautiful small business theme for Jekyll. It contains content types

To run the theme locally, navigate to the theme directory and run `bundle install` to install the dependencies, then run `jekyll serve` or `bundle exec jekyll serve` to start the Jekyll server.

I would recommend checking the [Deployment Methods](https://jekyllrb.com/docs/deployment-methods/) page on Jekyll website.
I would recommend checking the [Deployment Methods](https://jekyllrb.com/docs/deployment-methods/) page on Jekyll website.
40 changes: 30 additions & 10 deletions _includes/google-analytics.html
@@ -1,11 +1,31 @@
{% if site.google_analytics_id %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{ site.google_analytics_id }}');
</script>
{% if jekyll.environment == "production" %}

{% assign gid = site.env.NETLIFY_GOOGLE_ANALYTICS_ID %}
{{ gid }}

{% if gid %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ gid }}"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ $gid }}');
</script>
{% else %}
{% if site.google_analytics_id %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics_id }}');
</script>
{% endif %}
{% endif %}
{% endif %}

0 comments on commit 15458d1

Please sign in to comment.