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']
sourceCSV = 'inputs/cdims20.csv'
propertyId = input('Enter the property ID (in the format UA-XXXXXXXX-Y): ')
separator = input('Which separator are you using in the CSV file? (,/;): ')
accountBits = propertyId.split('-')
accountId = accountBits[1]
print("Updating custom dimensions from CSV")
scope = ['https://www.googleapis.com/auth/analytics.edit']
service = get_service('analytics', 'v3', scope, key_file_location, service_account_email)
with open(sourceCSV) as csvfile:
numline = len(csvfile.readlines())
csvfile.seek(0)
myreader = csv.reader(csvfile, delimiter=separator)
next(myreader)
i = 0
for row in myreader:
customDimensionId = ("ga:dimension" + str(row[0]))
newDim = service.management().customDimensions().update(
accountId=accountId,
webPropertyId=propertyId,
customDimensionId= customDimensionId,
body={
'name':row[1],
'scope':row[2],
'active': row[3]
}
).execute()
progress(i,numline)
i += 1
print ("\n\nDone.")
评论列表
文章目录