From c1d5dd2ad457d64c215b54c755cc14eedb0957dd Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Thu, 8 Mar 2018 15:31:17 -0500 Subject: [PATCH] switch from ga to segment analytics --- website/Gemfile | 2 +- website/Gemfile.lock | 10 ++++----- website/Makefile | 3 ++- website/config.rb | 10 +++++++++ website/packer.json | 2 ++ .../source/assets/javascripts/analytics.js | 14 ++++++++++++ .../source/assets/javascripts/application.js | 3 +++ website/source/layouts/layout.erb | 22 ++++++++++++------- 8 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 website/source/assets/javascripts/analytics.js diff --git a/website/Gemfile b/website/Gemfile index d21d35e45..177bf1774 100644 --- a/website/Gemfile +++ b/website/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org" -gem "middleman-hashicorp", "0.3.30" +gem "middleman-hashicorp", "0.3.34" diff --git a/website/Gemfile.lock b/website/Gemfile.lock index e567bf2ed..d1b532862 100644 --- a/website/Gemfile.lock +++ b/website/Gemfile.lock @@ -6,7 +6,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - autoprefixer-rails (8.1.0) + autoprefixer-rails (8.2.0) execjs bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) @@ -78,7 +78,7 @@ GEM rack (>= 1.4.5, < 2.0) thor (>= 0.15.2, < 2.0) tilt (~> 1.4.1, < 2.0) - middleman-hashicorp (0.3.30) + middleman-hashicorp (0.3.34) bootstrap-sass (~> 3.3) builder (~> 3.2) middleman (~> 3.4) @@ -113,9 +113,9 @@ GEM padrino-support (0.12.9) activesupport (>= 3.1) rack (1.6.9) - rack-livereload (0.3.16) + rack-livereload (0.3.17) rack - rack-test (0.8.3) + rack-test (1.0.0) rack (>= 1.0, < 3) rb-fsevent (0.10.3) rb-inotify (0.9.10) @@ -153,7 +153,7 @@ PLATFORMS ruby DEPENDENCIES - middleman-hashicorp (= 0.3.30) + middleman-hashicorp (= 0.3.34) BUNDLED WITH 1.16.1 diff --git a/website/Makefile b/website/Makefile index 4d3d361b7..0991a7753 100644 --- a/website/Makefile +++ b/website/Makefile @@ -1,4 +1,4 @@ -VERSION?="0.3.28" +VERSION?="0.3.34" build: @echo "==> Starting build in Docker..." @@ -7,6 +7,7 @@ build: --rm \ --tty \ --volume "$(shell pwd):/website" \ + -e "ENV=production" \ hashicorp/middleman-hashicorp:${VERSION} \ bundle exec middleman build --verbose --clean diff --git a/website/config.rb b/website/config.rb index 46bdc3be8..f6cbad23b 100644 --- a/website/config.rb +++ b/website/config.rb @@ -7,6 +7,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') + 'qW11yxgipKMsKFKQUCpTVgQUYftYsJj0' + else + '0EXTgkNx0Ydje2PGXVbRhpKKoe5wtzcE' + end + end + # Returns the FQDN of the image URL. # # @param [String] path diff --git a/website/packer.json b/website/packer.json index fd2618f17..4d8b752ae 100644 --- a/website/packer.json +++ b/website/packer.json @@ -3,6 +3,7 @@ "aws_access_key_id": "{{ env `AWS_ACCESS_KEY_ID` }}", "aws_secret_access_key": "{{ env `AWS_SECRET_ACCESS_KEY` }}", "aws_region": "{{ env `AWS_REGION` }}", + "website_environment": "production", "fastly_api_key": "{{ env `FASTLY_API_KEY` }}" }, "builders": [ @@ -22,6 +23,7 @@ "AWS_ACCESS_KEY_ID={{ user `aws_access_key_id` }}", "AWS_SECRET_ACCESS_KEY={{ user `aws_secret_access_key` }}", "AWS_REGION={{ user `aws_region` }}", + "ENV={{ user `website_environment` }}", "FASTLY_API_KEY={{ user `fastly_api_key` }}" ], "inline": [ diff --git a/website/source/assets/javascripts/analytics.js b/website/source/assets/javascripts/analytics.js new file mode 100644 index 000000000..4cfbb8e92 --- /dev/null +++ b/website/source/assets/javascripts/analytics.js @@ -0,0 +1,14 @@ +document.addEventListener('DOMContentLoaded', function() { + track('.downloads .download .details li a', function(el) { + var m = el.href.match(/nomad_(.*?)_(.*?)_(.*?)\.zip/) + return { + event: 'Download', + category: 'Button', + label: 'Nomad | v' + m[1] + ' | ' + m[2] + ' | ' + m[3], + version: m[1], + os: m[2], + architecture: m[3], + product: 'nomad' + } + }) +}) diff --git a/website/source/assets/javascripts/application.js b/website/source/assets/javascripts/application.js index ad181b4cc..51c8914f8 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 d35945497..2dbf350a0 100644 --- a/website/source/layouts/layout.erb +++ b/website/source/layouts/layout.erb @@ -133,14 +133,20 @@