matomo tracking

This commit is contained in:
Valentin 2024-05-13 00:35:28 +02:00
parent ae86c1e824
commit e10ddb1a11
5 changed files with 59 additions and 5 deletions

19
assets/matomo.html Normal file
View File

@ -0,0 +1,19 @@
<!-- Matomo -->
<script>
var matomoSiteId = '';
var matomoInstanceUrl = '';
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=`//${matomoInstanceUrl}/`;
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', matomoSiteId]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->

View File

@ -52,6 +52,7 @@ npx directus users create --email \"${directus_admin_email}\" \
npx directus users create --email \"website@${DOMAIN_NAME}\" --password \"${website_password}\" --role \"${website_role_uuid}\"" www-data npx directus users create --email \"website@${DOMAIN_NAME}\" --password \"${website_password}\" --role \"${website_role_uuid}\"" www-data
WEBSITE_TOKEN=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n') WEBSITE_TOKEN=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e \ mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e \
"UPDATE directus.directus_roles SET icon='robot' WHERE name='Website'" "UPDATE directus.directus_roles SET icon='robot' WHERE name='Website'"
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e \ mariadb -u directus -p${DB_DIRECTUS_PASSWORD} -e \

27
bin/setup_matomo.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
echo -e "${PURPLE}${BOLD}Add a new website to track from the Matomo interface as an admin user${RESET}"
echo -e "${PURPLE}${BOLD}All website → Add a new Website → Website${RESET}"
echo -e "${PURPLE}${BOLD}Fill in the following informations :${RESET}"
echo -e "${BLUE}${BOLD}Website name :${RESET}${BLUE}${DOMAIN_NAME}${RESET}"
echo -e "${BLUE}${BOLD}Urls :${RESET}${BLUE}https://${DOMAIN_NAME}/${RESET}"
echo -e "${PURPLE}${BOLD}Enter the Matomo instance URL :${RESET}${PURPLE} ie : matomo.example.com${RESET}"
read -s matomo_url
echo -e "${PURPLE}${BOLD}Find the website ID at the following URL${RESET}"
echo -e "${PURPLE}https://${matomo_url}/index.php?module=SitesManager${RESET}"
echo -e "${PURPLE}${BOLD}Enter the Website ID :${RESET}"
read -s matomo_website_id
get_username
temp_matomo_script = /home/$username/matomo.html
index_file = /var/www/html/public/index.html
cp assets/matomo.html $temp_matomo_script
sed -i "s/var matomoSiteId = '';/var matomoSiteId = '$matomo_website_id';/g" $temp_matomo_script
sed -i "s/var matomoInstanceUrl = '';/var matomoInstanceUrl = '$matomo_url';/g" $temp_matomo_script
sed -i '/<\/head>/i\'"$(cat $temp_matomo_script)"'' $index_file
rm $temp_matomo_script

View File

@ -8,7 +8,7 @@ echo -e "${BLUE}${BOLD}Authorization Header ${RESET}${ORANGE}Generate a safe str
echo -e "${PURPLE}${BOLD}Enter the Authorization Header${RESET}" echo -e "${PURPLE}${BOLD}Enter the Authorization Header${RESET}"
read -s auth_header read -s auth_header
# check if the build flow already exists and get the auth header from there if so # TODO: check if the build flow already exists and get the auth header from there if so
install_pkg php install_pkg php
install_pkg php-fpm install_pkg php-fpm
@ -47,7 +47,7 @@ if [[ -z "$DB_DIRECTUS_PASSWORD" ]]; then
echo echo
fi fi
FLOW_EXISTS=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} directus -e "SELECT COUNT(*) FROM directus_flows WHERE name='build';") | awk '{print $2}') flow_exists=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} directus -e "SELECT COUNT(*) FROM directus_flows WHERE name='build';") | awk '{print $2}')
website_role_uuid=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} \ website_role_uuid=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} \
-e "SELECT id FROM directus.directus_roles WHERE name='Website'") | awk '{print $2}') -e "SELECT id FROM directus.directus_roles WHERE name='Website'") | awk '{print $2}')
@ -55,9 +55,9 @@ website_role_uuid=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} \
website_user_uuid=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} \ website_user_uuid=$(echo $(mariadb -u directus -p${DB_DIRECTUS_PASSWORD} \
-e "SELECT id FROM directus.directus_users WHERE role='${website_role_uuid}'") | awk '{print $2}') -e "SELECT id FROM directus.directus_users WHERE role='${website_role_uuid}'") | awk '{print $2}')
if [ $FLOW_EXISTS -eq 0 ]; then if [ $flow_exists -eq 0 ]; then
flow_id="fdd75914-80dd-44ac-9d62-c7a08bc9cae6" flow_id=$(uuidgen)
operation_id="371b1b41-312d-4df6-ab68-336b416e1f16" operation_id=$(uuidgen)
mariadb -u directus -p${DB_DIRECTUS_PASSWORD} directus -e \ mariadb -u directus -p${DB_DIRECTUS_PASSWORD} directus -e \
"INSERT INTO directus_flows (id, name, icon, color, description, status, \`trigger\`, accountability, options, operation, user_created) \ "INSERT INTO directus_flows (id, name, icon, color, description, status, \`trigger\`, accountability, options, operation, user_created) \

View File

@ -10,6 +10,7 @@
## reboot a running system ## reboot a running system
## MATOMO ## MATOMO
## NODE EXPORTER ## NODE EXPORTER
## setup webhook : get auth header
. bin/functions.sh . bin/functions.sh
. bin/variables.sh . bin/variables.sh
@ -95,6 +96,12 @@ read answer
if [[ "$answer" == "y" ]]; then if [[ "$answer" == "y" ]]; then
. bin/install_nuxt_front.sh . bin/install_nuxt_front.sh
echo -e "${PURPLE}${BOLD}Track with Matomo ? (y/N) ${RESET}"
read answer
if [[ "$answer" == "y" ]]; then
. bin/setup_matomo.sh
fi
echo -e "${PURPLE}${BOLD}Setup a webhook ? (y/N) ${RESET}" echo -e "${PURPLE}${BOLD}Setup a webhook ? (y/N) ${RESET}"
read answer read answer
if [[ "$answer" == "y" ]]; then if [[ "$answer" == "y" ]]; then