From 5e97f36c6c64fa2ba29fd47912c32ca6527b27e5 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Thu, 8 Mar 2018 15:21:18 -0500 Subject: [PATCH] switch analytics from ga to segment --- website/Gemfile | 2 +- website/Gemfile.lock | 29 ++++++++----------- 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 | 27 ++++++++--------- 8 files changed, 56 insertions(+), 34 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 8958e299f..d1b532862 100644 --- a/website/Gemfile.lock +++ b/website/Gemfile.lock @@ -1,16 +1,3 @@ -GIT - remote: https://github.com/hashicorp/middleman-hashicorp - revision: 9cd0ee84bfd883d1805a1756ab98e6a54303fd61 - specs: - middleman-hashicorp (0.3.29) - bootstrap-sass (~> 3.3) - builder (~> 3.2) - middleman (~> 3.4) - middleman-livereload (~> 3.4) - middleman-syntax (~> 3.0) - redcarpet (~> 3.3) - turbolinks (~> 5.0) - GEM remote: https://rubygems.org/ specs: @@ -19,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) @@ -91,6 +78,14 @@ GEM rack (>= 1.4.5, < 2.0) thor (>= 0.15.2, < 2.0) tilt (~> 1.4.1, < 2.0) + middleman-hashicorp (0.3.34) + bootstrap-sass (~> 3.3) + builder (~> 3.2) + middleman (~> 3.4) + middleman-livereload (~> 3.4) + middleman-syntax (~> 3.0) + redcarpet (~> 3.3) + turbolinks (~> 5.0) middleman-livereload (3.4.6) em-websocket (~> 0.5.1) middleman-core (>= 3.3) @@ -118,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) @@ -158,7 +153,7 @@ PLATFORMS ruby DEPENDENCIES - middleman-hashicorp! + 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 74a882852..09bbad4a1 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') + 'IyzLrqXkox5KJ8XL4fo8vTYNGfiKlTCm' + 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 cbfb5c565..d1657eb69 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..b4a4f4597 --- /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(/consul_(.*?)_(.*?)_(.*?)\.zip/) + return { + event: 'Download', + category: 'Button', + label: 'Consul | v' + m[1] + ' | ' + m[2] + ' | ' + m[3], + version: m[1], + os: m[2], + architecture: m[3], + product: 'consul' + } + }) +}) 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 84af29d2f..2df76b669 100644 --- a/website/source/layouts/layout.erb +++ b/website/source/layouts/layout.erb @@ -34,13 +34,6 @@ <%= javascript_include_tag "application" %> - - - @@ -123,14 +116,18 @@