From e2f400472fd6576064be1035f50c8596f03a3b55 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Tue, 19 Jan 2021 10:46:53 +0100 Subject: [PATCH 1/5] Template google analytics data Without this patch, the index.html contains google analytics at all times, including for people self-hosting it. This is a problem for privacy reasons, and only people wanting to have analytics on their instances should be able to enable them. This fixes it by making sure the index.html page is templated to sideload content from ANALYTICS_CODE_PATH (which itself is also templated, for convenience). --- front/.gitignore | 3 ++- front/Dockerfile | 1 + front/dist/ga.html.tmpl | 9 ++++++++ front/dist/{index.html => index.html.tmpl} | 11 ++------- front/templater.sh | 26 ++++++++++++++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 front/dist/ga.html.tmpl rename front/dist/{index.html => index.html.tmpl} (95%) create mode 100755 front/templater.sh diff --git a/front/.gitignore b/front/.gitignore index e77b54d0..b6f01e2c 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -5,4 +5,5 @@ /dist/webpack.config.js /dist/webpack.config.js.map /dist/src -*.sh \ No newline at end of file +*.sh +!templater.sh diff --git a/front/Dockerfile b/front/Dockerfile index 6c79ad6e..b0d17877 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -11,5 +11,6 @@ COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/h RUN yarn install ENV NODE_ENV=production +ENV STARTUP_COMMAND_0="./templater.sh" ENV STARTUP_COMMAND_1="yarn run build" ENV APACHE_DOCUMENT_ROOT=dist/ diff --git a/front/dist/ga.html.tmpl b/front/dist/ga.html.tmpl new file mode 100644 index 00000000..ace84b39 --- /dev/null +++ b/front/dist/ga.html.tmpl @@ -0,0 +1,9 @@ + + + diff --git a/front/dist/index.html b/front/dist/index.html.tmpl similarity index 95% rename from front/dist/index.html rename to front/dist/index.html.tmpl index 9a197822..a2b44788 100644 --- a/front/dist/index.html +++ b/front/dist/index.html.tmpl @@ -6,15 +6,8 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> - - - + + diff --git a/front/templater.sh b/front/templater.sh new file mode 100755 index 00000000..aa6534b3 --- /dev/null +++ b/front/templater.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -x +set -o nounset errexit +template_file_index=dist/index.html.tmpl +generated_file_index=dist/index.html +tmp_trackcodefile=/tmp/trackcode + +# To inject tracking code, you have two choices: +# 1) Template using the provided google analytics +# 2) Insert with your own provided code, by overriding the ANALYTICS_CODE_PATH +# The ANALYTICS_CODE_PATH is the location of a file inside the container +ANALYTICS_CODE_PATH="${ANALYTICS_CODE_PATH:-dist/ga.html.tmpl}" + +if [[ "${INSERT_ANALYTICS:-NO}" == "NO" ]]; then + echo "" > "${tmp_trackcodefile}" +fi + +# Automatically insert analytics if TRACKING_NUMBER is set +if [[ "${TRACKING_NUMBER:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then + echo "Templating code from ${ANALYTICS_CODE_PATH}" + sed "s##${TRACKING_NUMBER:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile" +fi + +echo "Templating ${generated_file_index} from ${template_file_index}" +sed "//r ${tmp_trackcodefile}" "${template_file_index}" > "${generated_file_index}" +rm "${tmp_trackcodefile}" From fd89d54ed9e8d47ee1901851477c400f74ee72b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 20 Jan 2021 16:57:30 +0100 Subject: [PATCH 2/5] Adding GA tracking in test envs --- deeployer.libsonnet | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 8770ba6f..c49bb00e 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -78,7 +78,8 @@ "TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443", "TURN_USER": "workadventure", "TURN_PASSWORD": "WorkAdventure123", - "JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false" + "JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false", + "TRACKING_NUMBER": "UA-10196481-11" } }, "uploader": { From 15b3e87bd1488dadcec847f8f2f172e433156694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 20 Jan 2021 17:30:11 +0100 Subject: [PATCH 3/5] Renaming TRACKING_NUMBER to GA_TRACKING_ID --- front/templater.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/front/templater.sh b/front/templater.sh index aa6534b3..e63617c5 100755 --- a/front/templater.sh +++ b/front/templater.sh @@ -15,10 +15,10 @@ if [[ "${INSERT_ANALYTICS:-NO}" == "NO" ]]; then echo "" > "${tmp_trackcodefile}" fi -# Automatically insert analytics if TRACKING_NUMBER is set -if [[ "${TRACKING_NUMBER:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then +# Automatically insert analytics if GA_TRACKING_ID is set +if [[ "${GA_TRACKING_ID:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then echo "Templating code from ${ANALYTICS_CODE_PATH}" - sed "s##${TRACKING_NUMBER:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile" + sed "s##${GA_TRACKING_ID:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile" fi echo "Templating ${generated_file_index} from ${template_file_index}" From 9e469a4a8f99082383ef898d4470c2a0c01f3e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 20 Jan 2021 17:30:26 +0100 Subject: [PATCH 4/5] Removing Google Analytics tracking from test environments --- deeployer.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeployer.libsonnet b/deeployer.libsonnet index c49bb00e..83f102d3 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -79,7 +79,7 @@ "TURN_USER": "workadventure", "TURN_PASSWORD": "WorkAdventure123", "JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false", - "TRACKING_NUMBER": "UA-10196481-11" + //"GA_TRACKING_ID": "UA-10196481-11" } }, "uploader": { From f87f3889df05c8ddd2e76500d79392b2e8456911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 20 Jan 2021 17:36:50 +0100 Subject: [PATCH 5/5] Running templater in CI phase --- .github/workflows/continuous_integration.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 47b28d72..8072e606 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -39,6 +39,10 @@ jobs: run: yarn run proto && yarn run copy-to-front working-directory: "messages" + - name: "Create index.html" + run: ./templater.sh + working-directory: "front" + - name: "Build" run: yarn run build env: