Skip to content

Commit

Permalink
api: update shlink_link to add OS and Hardware information to click…
Browse files Browse the repository at this point in the history
… user agent

Also unify all click commands to use `shlink_link`. Extended `shlink_link` to parse an optional 3rd input argument when clicking is desirable regardless of whether analytics are enabled (or the user preference is set)
  • Loading branch information
theofficialgman committed Sep 16, 2024
1 parent 4ed092d commit ad560c1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
34 changes: 11 additions & 23 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -1379,43 +1379,31 @@ app_prefix_category() { #lists all apps in a category with format "category/app"
fi
}

# bitly_link() { #Runs whenever an app is installed/uninstalled to tally the number of users for each app
# #This cannot possibly be used to identify you, or any information about you.
# #It simply "clicks" a bitly link - a shortened URL - so that the total number of clicks can be tallied to determine how popular a certain app is.
# app="$1"
# trigger="$2"
#
# [ -z "$app" ] && error "bitly_link(): requires an app argument"
# [ -z "$trigger" ] && error "bitly_link(): requires a trigger argument"
#
# #if the 'Enable Analytics' setting is enabled
# if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
# #determine the name of the link to "click"
# bitlylink="https://bit.ly/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')"
# #click it
# curl -L --user-agent "Pi-Apps Raspberry Pi app store" "$bitlylink" &>/dev/null &
# fi
# }

bitly_link() { #compatibility function pointing to shlink_link (incase old manage script is running with new api)
shlink_link "$@"
}

shlink_link() { #Runs whenever an app is installed/uninstalled to tally the number of users for each app
#This cannot possibly be used to identify you, or any information about you.
#It simply "clicks" a shlink link - a shortened URL - so that the total number of clicks can be tallied to determine how popular a certain app is.
app="$1"
trigger="$2"
local app="$1"
local trigger="$2"

[ -z "$app" ] && error "shlink_link(): requires an app argument"
[ -z "$trigger" ] && error "shlink_link(): requires a trigger argument"

#if the 'Enable Analytics' setting is enabled
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics" 2>/dev/null)" != 'No' ]; then
#obtain model name
get_model &>/dev/null
local model="$(echo $model | tr -d '"'\; | head -1)"
#obtain operating system name
local os_name="$(cat /etc/os-release | grep PRETTY_NAME | tr -d '"'\; | awk -F= '{print $2}' | head -1)"

#determine the name of the link to "click"
shlinklink="https://analytics.pi-apps.io/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')/track"
local shlinklink="https://analytics.pi-apps.io/pi-apps-$trigger-$(echo "$app" | tr -d ' ' | sed 's/[^a-zA-Z0-9]//g')/track"
#click it
curl -s -X 'GET' "$shlinklink" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
curl -s -X 'GET' "$shlinklink" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store; $model; $os_name" >/dev/null &
fi
}

Expand Down
7 changes: 2 additions & 5 deletions gui
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ mkdir -p "${DIRECTORY}/data/status" "${DIRECTORY}/data/update-status" \
"${DIRECTORY}/updater" set-status &
trap "kill $! &>/dev/null" EXIT #kill the above subprocess on exit

#Click pi-apps usage link every time the GUI is run only if the 'Enable Analytics' setting is enabled
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
#click it
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-active-usage/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
fi
#Click pi-apps usage link every time the GUI is run
shlink_link usage active
}

#Determine the app list mode. Allowed values: 'yad-*', 'xlunch-*'
Expand Down
2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ elif [ ! -d "$DIRECTORY" ];then
error "Pi-Apps download failed!\ngit clone output was: $output"
fi
#click new installation analytics link
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-install-script/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
"${DIRECTORY}/api" shlink_link script install
fi

#Past this point, DIRECTORY variable populated with valid pi-apps directory
Expand Down
4 changes: 1 addition & 3 deletions uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ function error {
DIRECTORY="$(readlink -f "$(dirname "$0")")"

#click new uninstallation analytics link
if [ "$(cat "${DIRECTORY}/data/settings/Enable analytics")" == 'Yes' ];then
curl -s -X 'GET' "https://analytics.pi-apps.io/pi-apps-uninstall-script/track" -H 'accept: image/gif' -A "Pi-Apps Raspberry Pi app store" >/dev/null &
fi
"${DIRECTORY}/api" shlink_link script uninstall

if [ -z "$(dpkg-query -W --showformat='${Status}\n' yad 2>/dev/null | grep "install ok installed")" ];then
zenity --title='Pi-Apps' --window-icon="${DIRECTORY}/icons/logo.png" \
Expand Down

0 comments on commit ad560c1

Please sign in to comment.