BASH, cURL script to retrieve Google Analytics data

Last week I wrote this PowerShell code to retrieve Google Analytics data. Below is similar code in BASH using the cURL command.

#!/bin/bash
stty -echo
read -p "Password: " password; echo
stty echo
RESULT=$(curl -s https://www.google.com/accounts/ClientLogin \
--data-urlencode [email protected] --data-urlencode Passwd=$password \
-d accountType=GOOGLE \
-d source=YourSource \
-d service=analytics)


AUTH=$(echo "$RESULT" | grep 'Auth=' | sed  s/Auth=//)

curl -s "https://www.google.com/analytics/feeds/data?ids=ga%3AXXXXXXXX&metrics=ga%3Avisits&start-date=2012-05-01&end-date=2012-05-31&max-results=50" \
--request GET --header "Authorization: GoogleLogin auth=$AUTH"

#Done

Comments are closed.