Unverified Commit 65daf096 authored by Daniel's avatar Daniel Committed by GitHub

Made google analytics disabled by default (#198)

* Made google analytics disabled by default
parent 85ce0f9f
...@@ -8,6 +8,7 @@ const configCustom: AppConfigCustom = { ...@@ -8,6 +8,7 @@ const configCustom: AppConfigCustom = {
showAllTags: true, showAllTags: true,
}, },
google: { google: {
enabled: false,
key: 'default-key', key: 'default-key',
sampleRate: 100, sampleRate: 100,
}, },
......
...@@ -6,6 +6,7 @@ const configDefault: AppConfig = { ...@@ -6,6 +6,7 @@ const configDefault: AppConfig = {
showAllTags: true, showAllTags: true,
}, },
google: { google: {
enabled: false,
key: 'default-key', key: 'default-key',
sampleRate: 100, sampleRate: 100,
}, },
......
...@@ -29,6 +29,7 @@ export interface AppConfigCustom { ...@@ -29,6 +29,7 @@ export interface AppConfigCustom {
* Sample Rate - The percentage of users (0 - 100) to track site speed. * Sample Rate - The percentage of users (0 - 100) to track site speed.
*/ */
interface GoogleAnalyticsConfig { interface GoogleAnalyticsConfig {
enabled: boolean;
key: string; key: string;
sampleRate: number; sampleRate: number;
} }
......
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= htmlWebpackPlugin.options.config.google.key%>"></script>
<script>
const google = <%= JSON.stringify(htmlWebpackPlugin.options.config.google) %>;
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', google.key);
gtag('create', google.key, { 'siteSpeedSampleRate': google.sampleRate });
</script>
<script type="text/javascript">
// Feature detects Navigation Timing API support.
if (window.performance) {
// Gets the number of milliseconds since page load
// (and rounds the result since the value must be an integer).
const timeSincePageLoad = Math.round(performance.now());
// Sends the timing event to Google Analytics.
gtag('event', 'timing_complete', {
'name': 'load',
'value': timeSincePageLoad,
'event_category': 'JS Dependencies'
});
}
</script>
<html> <html>
<head> <head>
<!-- Global site tag (gtag.js) - Google Analytics --> {% if <%= htmlWebpackPlugin.options.config.google.enabled%> %}
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= htmlWebpackPlugin.options.config.google.key%>"></script> {% include 'fragments/google-analytics-loader.html' %}
<script> {% endif %}
const google = <%= JSON.stringify(htmlWebpackPlugin.options.config.google) %>;
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', google.key);
gtag('create', google.key, { 'siteSpeedSampleRate': google.sampleRate });
</script>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="shortcut icon" href="/static/images/favicon.png"> <link rel="shortcut icon" href="/static/images/favicon.png">
<link href="/static/dist/main.css" type="text/css" rel="stylesheet"/> <link href="/static/dist/main.css" type="text/css" rel="stylesheet"/>
...@@ -20,19 +13,7 @@ ...@@ -20,19 +13,7 @@
<script src="/static/dist/vendors.js" type="text/javascript"></script> <script src="/static/dist/vendors.js" type="text/javascript"></script>
<script src="/static/dist/main.js" type="text/javascript"></script> <script src="/static/dist/main.js" type="text/javascript"></script>
</body> </body>
<script type="text/javascript"> {% if <%= htmlWebpackPlugin.options.config.google.enabled%> %}
// Feature detects Navigation Timing API support. {% include 'fragments/google-analytics-post-loader.html' %}
if (window.performance) { {% endif %}
// Gets the number of milliseconds since page load
// (and rounds the result since the value must be an integer).
const timeSincePageLoad = Math.round(performance.now());
// Sends the timing event to Google Analytics.
gtag('event', 'timing_complete', {
'name': 'load',
'value': timeSincePageLoad,
'event_category': 'JS Dependencies'
});
}
</script>
</html> </html>
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs';
import * as webpack from 'webpack'; import * as webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import appConfig from './js/config/config'; import appConfig from './js/config/config';
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file));
});
return filelist;
};
const templatesList = walkSync('templates');
const htmlWebpackPluginConfig = templatesList.map(file => {
return new HtmlWebpackPlugin({
filename: file,
template: file,
config: appConfig,
inject: false,
});
});
const config: webpack.Configuration = { const config: webpack.Configuration = {
entry: { entry: {
main: ['babel-polyfill', path.join(__dirname, '/css/styles.scss'), path.join(__dirname, '/js/index.tsx')], main: ['babel-polyfill', path.join(__dirname, '/css/styles.scss'), path.join(__dirname, '/js/index.tsx')],
...@@ -51,17 +70,7 @@ const config: webpack.Configuration = { ...@@ -51,17 +70,7 @@ const config: webpack.Configuration = {
}, },
plugins: [ plugins: [
new MiniCssExtractPlugin(), new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({ ...htmlWebpackPluginConfig,
template: path.join(__dirname, 'templates/index.html'),
filename: 'templates/index.html',
config: appConfig,
inject: false,
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'templates/email.html'),
filename: 'templates/email.html',
inject: false,
}),
], ],
optimization: { optimization: {
splitChunks: { splitChunks: {
......
...@@ -8,7 +8,7 @@ from flask import Response, jsonify, make_response ...@@ -8,7 +8,7 @@ from flask import Response, jsonify, make_response
from amundsen_application import create_app from amundsen_application import create_app
from amundsen_application.base.base_mail_client import BaseMailClient from amundsen_application.base.base_mail_client import BaseMailClient
local_app = create_app('amundsen_application.config.LocalConfig', 'static/templates') local_app = create_app('amundsen_application.config.TestConfig', 'tests/templates')
class MockMailClient(BaseMailClient): class MockMailClient(BaseMailClient):
......
...@@ -10,7 +10,7 @@ from amundsen_application.api.metadata.v0 import \ ...@@ -10,7 +10,7 @@ from amundsen_application.api.metadata.v0 import \
from amundsen_application.tests.test_utils import TEST_USER_ID from amundsen_application.tests.test_utils import TEST_USER_ID
local_app = create_app('amundsen_application.config.TestConfig') local_app = create_app('amundsen_application.config.TestConfig', 'tests/templates')
class MetadataTest(unittest.TestCase): class MetadataTest(unittest.TestCase):
......
...@@ -7,7 +7,7 @@ from http import HTTPStatus ...@@ -7,7 +7,7 @@ from http import HTTPStatus
from amundsen_application import create_app from amundsen_application import create_app
from amundsen_application.api.search.v0 import _create_url_with_field, SEARCH_ENDPOINT from amundsen_application.api.search.v0 import _create_url_with_field, SEARCH_ENDPOINT
local_app = create_app('amundsen_application.config.LocalConfig', 'static/templates') local_app = create_app('amundsen_application.config.TestConfig', 'tests/templates')
class SearchTest(unittest.TestCase): class SearchTest(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment