adding netlify env variables for google analytics
parent
1cf0eaa8ed
commit
15458d13aa
1
Gemfile
1
Gemfile
|
@ -1,2 +1,3 @@
|
|||
source "https://rubygems.org"
|
||||
gem 'github-pages'
|
||||
gem 'jekyll-environment-variables'
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
{% if jekyll.environment == "production" %}
|
||||
|
||||
gtag('config', '{{ site.google_analytics_id }}');
|
||||
</script>
|
||||
{% 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 %}
|
Loading…
Reference in New Issue