Skip to content

Instantly share code, notes, and snippets.

@willcritchlow
Created May 11, 2011 22:11
Show Gist options
  • Save willcritchlow/967503 to your computer and use it in GitHub Desktop.
Save willcritchlow/967503 to your computer and use it in GitHub Desktop.
The most basic Google Analytics access in python
import gdata.analytics.service
from datetime import date, timedelta
from xml.dom.minidom import parseString
def main():
client = gdata.analytics.service.AnalyticsDataService()
client.ClientLogin('<your email here>', '<your password here>')
today = date.today()
q = gdata.analytics.service.DataQuery(
ids='ga:<your GA ID here>',
dimensions='ga:pagePath',
metrics='ga:pageviews',
filters='ga:pagepath=~^/store',
sort='-ga:pageviews',
start_date=today - timedelta(days=7),
end_date=today,
start_index='',
max_results='50')
gadata = client.AnalyticsDataFeed(q.ToUri())
xml = parseString(str(gadata))
for title in xml.getElementsByTagName("ns0:title"):
for child in title.childNodes:
print child.data
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment