workadventure/front/templater.sh
Jean-Philippe Evrard e2f400472f 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).
2021-01-19 12:17:05 +01:00

27 lines
1 KiB
Bash
Executable file

#!/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 -->#${TRACKING_NUMBER:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile"
fi
echo "Templating ${generated_file_index} from ${template_file_index}"
sed "/<!-- TRACK CODE -->/r ${tmp_trackcodefile}" "${template_file_index}" > "${generated_file_index}"
rm "${tmp_trackcodefile}"