From db959c16c52d41c815fe5ef0fbfec996d794305d Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Thu, 8 Mar 2018 15:48:43 -0500 Subject: [PATCH] switch web analytics from ga to segment --- website/Gemfile | 2 +- website/Gemfile.lock | 8 ++--- website/Makefile | 3 +- website/config.rb | 10 +++++++ website/packer.json | 2 ++ .../source/assets/javascripts/analytics.js | 14 +++++++++ .../source/assets/javascripts/application.js | 2 ++ website/source/layouts/layout.erb | 29 +++++++++---------- 8 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 website/source/assets/javascripts/analytics.js diff --git a/website/Gemfile b/website/Gemfile index f32e3eb11..975949205 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.35" diff --git a/website/Gemfile.lock b/website/Gemfile.lock index 65af3c225..c335225a8 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.1) + autoprefixer-rails (8.2.0) execjs bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) @@ -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.35) BUNDLED WITH 1.16.1 diff --git a/website/Makefile b/website/Makefile index ccc3ae634..7497725e4 100644 --- a/website/Makefile +++ b/website/Makefile @@ -1,4 +1,4 @@ -VERSION?="0.3.29" +VERSION?="0.3.35" 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 52536a432..d2b8c6c81 100644 --- a/website/config.rb +++ b/website/config.rb @@ -11,6 +11,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') + 'wFMyBE4PJCZttWfu0pNhYdWr7ygW0io4' + 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 301ed3d12..c57fa74ef 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..c9e0d801a --- /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(/vagrant_(.*?)_(.*?)_(.*?)\.zip/) + return { + event: 'Download', + category: 'Button', + label: 'Vagrant | v' + m[1] + ' | ' + m[2] + ' | ' + m[3], + version: m[1], + os: m[2], + architecture: m[3], + product: 'vagrant' + } + }) +}) diff --git a/website/source/assets/javascripts/application.js b/website/source/assets/javascripts/application.js index a7f2d9d6b..5ddc2b27c 100644 --- a/website/source/assets/javascripts/application.js +++ b/website/source/assets/javascripts/application.js @@ -3,5 +3,7 @@ //= require hashicorp/mega-nav //= require hashicorp/sidebar +//= require hashicorp/analytics //= require _vmware +//= require analytics diff --git a/website/source/layouts/layout.erb b/website/source/layouts/layout.erb index a623c93da..5926471d3 100644 --- a/website/source/layouts/layout.erb +++ b/website/source/layouts/layout.erb @@ -34,13 +34,6 @@ <%= javascript_include_tag "application" %> - - - @@ -121,14 +114,20 @@