diff --git a/.env.example b/.env.example index 50f7c07..a55b15d 100644 --- a/.env.example +++ b/.env.example @@ -5,5 +5,8 @@ NINTENDO_SESSION_ID= # Provided by: https://www.reddit.com/user/thejellydude SALMON_RUN_CALENDAR_ICS_URL=https://calendar.google.com/calendar/ical/7e5g474p0ng7vaejkg3mkomhks%40group.calendar.google.com/public/basic.ics +# (Optional) Google Analytics tracking ID +GOOGLE_ANALYTICS_ID= + # (Optional) Sentry error reporting (https://sentry.io) SENTRY_DSN= diff --git a/src/html/index.html b/src/html/index.html index e5e4ccf..d8318d3 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -12,6 +12,9 @@ + <% for (var css in htmlWebpackPlugin.files.css) { %> + + <% } %> @@ -23,5 +26,9 @@
+ <% for (var chunk in htmlWebpackPlugin.files.chunks) { %> + + <% } %> + diff --git a/src/js/analytics.js b/src/js/analytics.js new file mode 100644 index 0000000..96c5696 --- /dev/null +++ b/src/js/analytics.js @@ -0,0 +1,5 @@ +if (GOOGLE_ANALYTICS_ID) { + window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; + ga('create', GOOGLE_ANALYTICS_ID, 'auto'); + ga('send', 'pageview'); +} diff --git a/src/js/main.js b/src/js/main.js index 45a4c5a..a4ec2d8 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -5,3 +5,6 @@ import './filters.js'; // Start the Vue app with our root component import App from './components/App.vue'; new Vue(App).$mount('#app'); + +// Start analytics +require('./analytics'); diff --git a/webpack.config.js b/webpack.config.js index 94d9100..e2678a0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,7 @@ +require('dotenv').config(); const path = require('path'); const glob = require('glob'); +const webpack = require('webpack'); const CleanWebpackPlugin = require('clean-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); @@ -79,6 +81,9 @@ module.exports = function(env) { // 'public/assets/css/*', // 'public/assets/js/*', // ]), + new webpack.DefinePlugin({ + 'GOOGLE_ANALYTICS_ID': JSON.stringify(process.env.GOOGLE_ANALYTICS_ID), + }), // Extract CSS to a separate file new ExtractTextPlugin({ filename: 'assets/css/[name].[contenthash:6].css', @@ -102,6 +107,7 @@ module.exports = function(env) { }), // Build HTML new HtmlWebpackPlugin({ + inject: false, filename: 'index.html', template: 'src/html/index.html', minify: { collapseWhitespace: true },