Created
May 11, 2011 22:11
-
-
Save willcritchlow/967503 to your computer and use it in GitHub Desktop.
The most basic Google Analytics access in python
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
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