def main():
# Refer to the config.py settings file for credentials
service_account_email = config.apiSettings['service_account_email']
key_file_location = config.apiSettings['key_file_location']
print("Reading custom dimensions from property")
scope = ['https://www.googleapis.com/auth/analytics.readonly']
service = get_service('analytics', 'v3', scope, key_file_location, service_account_email)
print("Analyzing available accounts.")
properties = service.management().webproperties().list(accountId='~all').execute()
propertiesList = properties.get("items")
for property in propertiesList:
print ("Exporting:\t"+property["id"]+"\t"+property["name"])
csvname = "exports/"+property["id"] + ".csv"
pchunks = property["id"].split("-")
dimensions = service.management().customDimensions().list(
accountId=pchunks[1],
webPropertyId=property["id"],
).execute()
dimList = dimensions.get("items")
with open(csvname, 'w', newline='') as csvfile:
dimdump = csv.writer(csvfile, delimiter=",")
dimdump.writerow(["Index","Scope","Name","Active"])
for dimension in dimList:
dimdump.writerow([str(dimension["index"]),dimension["scope"],dimension["name"],str(dimension["active"])])
print ("\nDone.\n")
exportAllCustomDimensionsCSV.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录