def analitics(start_date, end_date): try: from googleanalytics import Connection from googleanalytics.data import DataPoint, DataSet import datetime google_account_email = '*****@*****.**' # agregue el email de la cuenta de google analytics o la cuenta con que se registro google_account_password = '******' # UTILICE SU CUENTA POR FAVOR # SI METES EL PASSWORD MAL TE VA TIRAR 403 ERROR connection = Connection(google_account_email, google_account_password) accounts = connection.get_accounts() # aqui estan todas mis cuentas #print accounts[2].profile_id # aqui saque uno de mis cuentas para saber que hay enn esa lista dir(accounts[2]) y asi conoces mas aparte del profile_id # accounts[2].profile_id esto me devolvio 23492578 # para entender mejor https://github.com/clintecker/python-googleanalytics/blob/master/USAGE.md # a mi pagina con id 23492578 le voy a calcular unos analytics account = connection.get_account(accounts[0].profile_id) #data = account.get_data(start_date, end_date, metrics=['visits'],dimensions=['city']) # tire el querys filters = [] data_source = account.get_data(start_date=start_date, end_date=end_date, dimensions=['source'], metrics=['visits', ], sort=['-visits', ], filters=filters) data_source = map(lambda source: {'nombre': source[0][0], 'valor': source[1][0]}, data_source.list) ###################################################################################################################################################### data_city = account.get_data(start_date, end_date, metrics=['visits'], dimensions=['city'], sort=['-visits', ]) # tire el querys data_city = map(lambda source: {'nombre': source[0][0], 'valor': source[1][0]}, data_city.list) return data_city, data_source except: return [], []
def analitics(start_date, end_date): try: from googleanalytics import Connection from googleanalytics.data import DataPoint, DataSet import datetime google_account_email = '*****@*****.**' # agregue el email de la cuenta de google analytics o la cuenta con que se registro google_account_password = '******' # UTILICE SU CUENTA POR FAVOR # SI METES EL PASSWORD MAL TE VA TIRAR 403 ERROR connection = Connection(google_account_email, google_account_password) accounts = connection.get_accounts() # aqui estan todas mis cuentas #print accounts[2].profile_id # aqui saque uno de mis cuentas para saber que hay enn esa lista dir(accounts[2]) y asi conoces mas aparte del profile_id # accounts[2].profile_id esto me devolvio 23492578 # para entender mejor https://github.com/clintecker/python-googleanalytics/blob/master/USAGE.md # a mi pagina con id 23492578 le voy a calcular unos analytics account = connection.get_account(accounts[0].profile_id) #data = account.get_data(start_date, end_date, metrics=['visits'],dimensions=['city']) # tire el querys filters = [] data_source = account.get_data(start_date=start_date, end_date=end_date, dimensions=['source'], metrics=[ 'visits', ], sort=[ '-visits', ], filters=filters) data_source = map( lambda source: { 'nombre': source[0][0], 'valor': source[1][0] }, data_source.list) ###################################################################################################################################################### data_city = account.get_data(start_date, end_date, metrics=['visits'], dimensions=['city'], sort=[ '-visits', ]) # tire el querys data_city = map( lambda source: { 'nombre': source[0][0], 'valor': source[1][0] }, data_city.list) return data_city, data_source except: return [], []
def get_accounts(): connection = Connection(settings.OPPS_GANALYTICS_ACCOUNT, settings.OPPS_GANALYTICS_PASSWORD, settings.OPPS_GANALYTICS_APIKEY) accounts = connection.get_accounts() for a in accounts: obj, create = Account.objects.get_or_create(profile_id=a.profile_id, account_id=a.account_id, account_name=a.account_name, title=a.title) if not create: obj.account_id = a.account_id obj.account_name = a.account_name obj.title = a.title obj.save()
def get_analytics_connection(): connection = Connection('*****@*****.**', 's0d4!SODA@') #connection = Connection('email', 'senha') account = connection.get_accounts()[3] return account
# # It uses a python googleanalytics lib # You can download it at: # http://tinyurl.com/python-googleanalytics # # By Johann Vivot # # Example to get Accounts from googleanalytics import Connection connection = Connection('*****@*****.**', 'xxxx') accounts = connection.get_accounts() # Example to get Pageviews account = connection.get_account('9060294') start_date = datetime.date(2011, 10, 21) end_date = datetime.date(2011, 10, 21) data = account.get_data(start_date, end_date, metrics=['pageviews']) data.list