From cc60b04d5108a5c65adabef15e12ef33fd0c729e Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 22 Aug 2023 22:48:47 +0100 Subject: [PATCH] feat: add dynamic payload generation for Google Analytics This commit adds the ability to dynamically generate the payload for sending events to Google Analytics. The payload now includes properties such as `discordalert`, `emailalert`, `gotifyalert`, and more, based on their respective values. This allows for more flexibility in customizing the payload sent to Google Analytics. The code changes can be found in `info_stats.sh`. --- lgsm/modules/info_stats.sh | 50 ++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/lgsm/modules/info_stats.sh b/lgsm/modules/info_stats.sh index f942732a5..8c8a6d0de 100644 --- a/lgsm/modules/info_stats.sh +++ b/lgsm/modules/info_stats.sh @@ -61,8 +61,7 @@ memusedroundup="$(((memused + 99) / 100 * 100))" # Install Property - UA-165287622-2 # Hardware Property - UA-165287622-3 -curl -X POST "https://www.google-analytics.com/mp/collect?api_secret=A-OzP02TSMWt4_vHi6ZpUw&measurement_id=G-0CR8V7EMT5" -H "Content-Type: application/json" -d " -{ +payload="{ \"client_id\": \"${uuidinstance}\", \"events\": [ { @@ -83,22 +82,47 @@ curl -X POST "https://www.google-analytics.com/mp/collect?api_secret=A-OzP02TSMW \"uuidinstall\": \"${uuidinstall}\", \"uuidinstance\": \"${uuidinstance}\", \"version\": \"${version}\", - \"virtualenvironment\": \"${virtualenvironment}\", - \"discordalert\": \"${discordalert}\", - \"emailalert\": \"${emailalert}\", - \"gotifyalert\": \"${gotifyalert}\", - \"iftttalert\": \"${iftttalert}\", - \"mailgunalert\": \"${mailgunalert}\", - \"pushbulletalert\": \"${pushbulletalert}\", - \"pushoveralert\": \"${pushoveralert}\", - \"rocketchatalert\": \"${rocketchatalert}\", - \"slackalert\": \"${slackalert}\", - \"telegramalert\": \"${telegramalert}\" + \"virtualenvironment\": \"${virtualenvironment}\"," + +if [ "${discordalert}" == "on" ]; then + payload="${payload}, \"discordalert\": \"${discordalert}\"" +fi +if [ "${emailalert}" == "on" ]; then + payload="${payload}, \"emailalert\": \"${emailalert}\"" +fi +if [ "${gotifyalert}" == "on" ]; then + payload="${payload}, \"gotifyalert\": \"${gotifyalert}\"" +fi +if [ "${iftttalert}" == "on" ]; then + payload="${payload}, \"iftttalert\": \"${iftttalert}\"" +fi +if [ "${mailgunalert}" == "on" ]; then + payload="${payload}, \"mailgunalert\": \"${mailgunalert}\"" +fi +if [ "${pushbulletalert}" == "on" ]; then + payload="${payload}, \"pushbulletalert\": \"${pushbulletalert}\"" +fi +if [ "${pushoveralert}" == "on" ]; then + payload="${payload}, \"pushoveralert\": \"${pushoveralert}\"" +fi +if [ "${rocketchatalert}" == "on" ]; then + payload="${payload}, \"rocketchatalert\": \"${rocketchatalert}\"" +fi +if [ "${slackalert}" == "on" ]; then + payload="${payload}, \"slackalert\": \"${slackalert}\"" +fi +if [ "${telegramalert}" == "on" ]; then + payload="${payload}, \"telegramalert\": \"${telegramalert}\"" +fi + +payload="${payload} } } ] }" +curl -X POST "https://www.google-analytics.com/mp/collect?api_secret=A-OzP02TSMWt4_vHi6ZpUw&measurement_id=G-0CR8V7EMT5" -H "Content-Type: application/json" -d "${payload}" + curl -X POST https://stats.linuxgsm.com/api/event \ -H 'User-Agent: curl' \ -H 'Content-Type: application/json' \