I have a Google Sheet with the information of the audiences that I want to create in Google Analytics. I'm trying to insert that audiences using Google Apps Script, taking the values of the Google Sheet.
When I run my function, I get this error: analytics.management.remarketingAudience.insert; error: invalid accountId: UA-143962394-1.
If I change the orders of the parameters, so the insert function call looks like this:
Analytics.Management.RemarketingAudience.insert(propertyId,accountId,resource2)
I get this error: analytics.management.remarketingAudience.insert; error: Parse Error
Do you know what is wrong with my code?
I tried to pass resource parameter as json, object and string but the result was the same.
function createAudience(){
var data = readSpreadsheetData()
Logger.log(data)
var resource = {
name: data.audiences[0].name,
linkedViews: [getViewId(data.country)],
linkedAdAccounts: [{
type: data.audiences[0].type,
linkedAccountId: data.audiences[0].linkedAccountId
}],
audienceType: data.audiences[0].audienceType,
stateBasedAudienceDefinition: {
includeConditions: {
daysToLookBack: data.audiences[0].daysToLookBack,
segment: data.audiences[0].segment,
membershipDurationDays: data.audiences[0].membershipDurationDays,
isSmartList: data.audiences[0].isSmartList
},
}
}
var accountId = data.accountId, propertyId = getPropertyId(data.country)
Logger.log(resource)
var request = Analytics.Management.RemarketingAudience.insert(accountId,propertyId,resource)
request.execute(function (response) { Logger.log(response) });
}
If my understanding is correct, how about this modification? I think that your request body is correct. So how about this modification?
Before you use this script, please confirm whether Google Analytics API is enabled at Advanced Google services.
var request = Analytics.Management.RemarketingAudience.insert(accountId,propertyId,resource)
request.execute(function (response) { Logger.log(response) });
var response = Analytics.Management.RemarketingAudience.insert(resource,accountId,propertyId);
Logger.log(response);
Analytics.Management.RemarketingAudience.insert(resource, accountId, webPropertyId)
. So the order of resource, accountId, propertyId
can be confirmed.resource, accountId, propertyId
has the issues, the request returns an error. At that time, please confirm the parameters.If this didn't resolve your issue, I apologize.