adding netlify env variables for google analytics

pull/1/head
Robert Austin 2019-02-18 10:38:00 +10:00
parent 1cf0eaa8ed
commit 15458d13aa
4 changed files with 36 additions and 12 deletions

View File

@ -1,2 +1,3 @@
source "https://rubygems.org"
gem 'github-pages'
gem 'github-pages'
gem 'jekyll-environment-variables'

View File

@ -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)
@ -243,6 +245,7 @@ PLATFORMS
DEPENDENCIES
github-pages
jekyll-environment-variables
BUNDLED WITH
1.17.1

View File

@ -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.

View File

@ -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 %}