2015-02-02 3 views
0

Google 웹 로그 분석 계정 링크가 여러 웹 사이트에 있습니다. http://blog.yhathq.com/posts/pandas-google-analytics.html 다음 팬더 용 GA API를 설정했지만 어떻게 웹 사이트에서 다른 웹 사이트로 전환 할 수 있는지 이해하지 못했습니다.팬더 Google Analytics API - 계정 전환 방법

temp_df = ga.read_ga(metrics, 
        dimensions=dimensions, 
        start_date=start_date, 
        end_date=end_date, 
        index_col=0, 
        filters=filters, 
        start_index=start_index 
       ) 

그러나이 어떻게 호스트를 변경할 수 있습니다

내가 사용하는 파이썬을 통해 GA에 연결하는거야?

답변

0

당신은 account_id, property_idprofile_id 매개 변수를 추가해야합니다 :

temp_df = ga.read_ga(metrics, 
       dimensions=dimensions, 
       start_date=start_date, 
       end_date=end_date, 
       index_col=0, 
       filters=filters, 
       account_id=account, 
       property_id=property, 
       profile_id=profile, 
       start_index=start_index) 

더 많은 문서는 여기에서 찾을 수 있습니다을 : 나는 패키징하는 것이 유용 발견했습니다 http://pandas.pydata.org/pandas-docs/stable/remote_data.html#remote-data-ga

내 모든 계정 정보 별도의 JSON 파일에 넣으십시오.

{ 
    "site1": { 
     "acct": "123456", 
     "prop": "UA-123456-1", 
     "view": "098345983" 
    }, 
    "site2": { 
     "acct": "987654", 
     "prop": "UA-987654-1", 
     "view": "398475987" 
    }, 
    "site3": { 
     "acct": "456789", 
     "prop": "UA-456789-1", 
     "view": "938745876" 
    } 
} 

그런 다음 해당 계정을 다음과 같이 내 스크립트로 가져 오십시오.

import json 

# p as path, gc as google analytics credentials 
with open('/Path/To/Your/JSON/Goes/Here/google_analytics_accounts.json') as p: 
    gc = json.load(p) 
    p.close() 

그래서 나는이 DataFrame에 Google 웹 로그 분석을 읽을 때 필요한 중 자격 증명을 사용할 수 :

temp_df = ga.read_ga(metrics, 
       dimensions=dimensions, 
       start_date=start_date, 
       end_date=end_date, 
       index_col=0, 
       filters=filters, 
       account_id=gc['site1']['acct'], 
       property_id=gc['site1']['prop'], 
       profile_id=gc['site1']['view'], 
       start_index=start_index) 
관련 문제