Created
August 18, 2014 23:33
-
-
Save jacobsalmela/985c2916aab2df2a9e45 to your computer and use it in GitHub Desktop.
(OS X) Geeklet to display Google Analytics daily vists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------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