Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created August 18, 2014 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobsalmela/985c2916aab2df2a9e45 to your computer and use it in GitHub Desktop.
Save jacobsalmela/985c2916aab2df2a9e45 to your computer and use it in GitHub Desktop.
(OS X) Geeklet to display Google Analytics daily vists
#----------VARIABLES--------
# API credentials
clientID=""
clientSecret=""
redirectURI=""
# OAuth tokens and codes
authorizationCode=""
# Once you have these two tokens, the script can run automatically.
accessToken=""
refreshToken=""
profileID=""
desiredMetric="visits"
today=$(date "+%Y-%m-%d")
#----------SCRIPT----------
echo "${bold}GOOGLE ANALYTICS${end}"
printf "\tVisits today:\t"
curl -s "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:$profileID&metrics=ga:$desiredMetric&start-date=$today&end-date=$today&access_token=$accessToken" | tr , '\n' | grep "totalsForAllResults" | cut -d'"' -f6
# Refresh OAuth token
curl -s -d "client_id=$clientID&client_secret=$clientSecret&refresh_token=$refreshToken&grant_type=refresh_token" https://accounts.google.com/o/oauth2/token >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment