Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds analytics #58

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group :jekyll_plugins do
gem 'jekyll-scholar'
gem 'jekyll-archives'
gem "jekyll-resize", git: "https://github.com/UCSD-E4E/jekyll-resize"
gem "jekyll-environment-variables"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ GEM
webrick (~> 1.7)
jekyll-archives (2.2.1)
jekyll (>= 3.6, < 5.0)
jekyll-environment-variables (1.0.1)
jekyll (>= 3.0, < 5.x)
jekyll-feed (0.17.0)
jekyll (>= 3.7, < 5.0)
jekyll-redirect-from (0.16.0)
Expand Down Expand Up @@ -138,6 +140,7 @@ DEPENDENCIES
http_parser.rb (~> 0.6.0)
jekyll (~> 4.3.4)
jekyll-archives
jekyll-environment-variables
jekyll-feed (~> 0.12)
jekyll-redirect-from
jekyll-resize!
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ plugins:
- jekyll-feed
- jekyll-seo-tag
- jekyll-redirect-from
- jekyll-environment-variables

whitelist:
- jekyll-redirect-from
Expand Down
15 changes: 6 additions & 9 deletions _includes/google-analytics.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.env.google_analytics }}"></script>
<script>
if(!(window.doNotTrack === "1" || navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1")) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

ga('create', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
}
gtag('config', '{{ site.env.google_analytics }}');
</script>

2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<link rel="shortcut icon" type="image/png" href={{"/assets/favicon-48x48.png" | absolute_url}}>
<link rel="manifest" href={{"/site.webmanifest" | absolute_url}}>
{%- feed_meta -%}
{%- if jekyll.environment == 'production' and site.google_analytics -%}
{%- if jekyll.environment == 'production' and site.env.google_analytics -%}
{%- include google-analytics.html -%}
{%- endif -%}
</head>
Loading