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 = {
showAllTags: true,
},
google: {
enabled: false,
key: 'default-key',
sampleRate: 100,
},
......
......@@ -6,6 +6,7 @@ const configDefault: AppConfig = {
showAllTags: true,
},
google: {
enabled: false,
key: 'default-key',
sampleRate: 100,
},
......
......@@ -29,6 +29,7 @@ export interface AppConfigCustom {
* Sample Rate - The percentage of users (0 - 100) to track site speed.
*/
interface GoogleAnalyticsConfig {
enabled: boolean;
key: string;
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>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<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>
{% if <%= htmlWebpackPlugin.options.config.google.enabled%> %}
{% include 'fragments/google-analytics-loader.html' %}
{% endif %}
<meta charset="utf-8">
<link rel="shortcut icon" href="/static/images/favicon.png">
<link href="/static/dist/main.css" type="text/css" rel="stylesheet"/>
......@@ -20,19 +13,7 @@
<script src="/static/dist/vendors.js" type="text/javascript"></script>
<script src="/static/dist/main.js" type="text/javascript"></script>
</body>
<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>
{% if <%= htmlWebpackPlugin.options.config.google.enabled%> %}
{% include 'fragments/google-analytics-post-loader.html' %}
{% endif %}
</html>
import * as path from 'path';
import * as fs from 'fs';
import * as webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
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 = {
entry: {
main: ['babel-polyfill', path.join(__dirname, '/css/styles.scss'), path.join(__dirname, '/js/index.tsx')],
......@@ -51,17 +70,7 @@ const config: webpack.Configuration = {
},
plugins: [
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
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,
}),
...htmlWebpackPluginConfig,
],
optimization: {
splitChunks: {
......
......@@ -8,7 +8,7 @@ from flask import Response, jsonify, make_response
from amundsen_application import create_app
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):
......
......@@ -10,7 +10,7 @@ from amundsen_application.api.metadata.v0 import \
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):
......
......@@ -7,7 +7,7 @@ from http import HTTPStatus
from amundsen_application import create_app
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):
......
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