From b0937ff94d90e856238cb89571fa50fa0071dabd Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Thu, 8 Mar 2018 15:43:41 -0500 Subject: [PATCH 1/2] switch analytics from ga to segment --- website/Makefile | 2 +- website/config.rb | 10 ++++++++++ website/source/assets/javascripts/analytics.js | 9 +++++++++ .../source/assets/javascripts/application.js | 3 +++ website/source/layouts/layout.erb | 18 ++++++++++-------- 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 website/source/assets/javascripts/analytics.js diff --git a/website/Makefile b/website/Makefile index 82b2cedc1..934ed941e 100644 --- a/website/Makefile +++ b/website/Makefile @@ -8,7 +8,7 @@ build: --tty \ --volume "$(shell pwd):/website" \ hashicorp/middleman-hashicorp:${VERSION} \ - bundle exec middleman build --verbose --clean + ENV=production bundle exec middleman build --verbose --clean website: @echo "==> Starting website in Docker..." diff --git a/website/config.rb b/website/config.rb index 63b2de323..38ef7eb6f 100644 --- a/website/config.rb +++ b/website/config.rb @@ -8,6 +8,16 @@ activate :hashicorp do |h| end helpers do + # Returns a segment tracking ID such that local development is not + # tracked to production systems. + def segmentId() + if (ENV['ENV'] == 'production') + 'AjXdfmTTk1I9q9dfyePuDFHBrz1tCO3l' + else + '0EXTgkNx0Ydje2PGXVbRhpKKoe5wtzcE' + end + end + # Returns the FQDN of the image URL. # # @param [String] path diff --git a/website/source/assets/javascripts/analytics.js b/website/source/assets/javascripts/analytics.js new file mode 100644 index 000000000..17ca06dd9 --- /dev/null +++ b/website/source/assets/javascripts/analytics.js @@ -0,0 +1,9 @@ +document.addEventListener('DOMContentLoaded', () => { + track('.downloads .download a', el => { + return { + event: 'Download', + category: 'Button', + label: `Packer | v${el.href.match(/\/(\d+\.\d+\.\d+)\//)[1]}` + } + }) +}) diff --git a/website/source/assets/javascripts/application.js b/website/source/assets/javascripts/application.js index 5d2365e14..ae70e571d 100644 --- a/website/source/assets/javascripts/application.js +++ b/website/source/assets/javascripts/application.js @@ -3,3 +3,6 @@ //= require hashicorp/mega-nav //= require hashicorp/sidebar +//= require hashicorp/analytics + +//= require analytics diff --git a/website/source/layouts/layout.erb b/website/source/layouts/layout.erb index ab0f53361..aa476c059 100644 --- a/website/source/layouts/layout.erb +++ b/website/source/layouts/layout.erb @@ -119,14 +119,16 @@ - +