Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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