google-apps-script - 使用 Google Script Apps 将受众插入 Google Analytics 时出现问题
问题描述
我有一个 Google 表格,其中包含我想在 Google Analytics 中创建的受众信息。我正在尝试使用 Google Apps 脚本插入这些受众,并采用 Google Sheet 的值。
当我运行我的函数时,我收到了这个错误:analytics.management.remarketingAudience.insert; 错误:无效的 accountId:UA-143962394-1。
如果我更改参数的顺序,那么插入函数调用如下所示:
Analytics.Management.RemarketingAudience.insert(propertyId,accountId,resource2)
我收到此错误:analytics.management.remarketingAudience.insert; 错误:解析错误
你知道我的代码有什么问题吗?
我尝试将资源参数作为 json、对象和字符串传递,但结果是一样的。
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) });
}
解决方案
- 您想通过 Google Apps 脚本使用“再营销受众:插入”的方法。
如果我的理解是正确的,那么这个修改呢?我认为您的请求正文是正确的。那么这个改装怎么样呢?
修改后的脚本:
在使用此脚本之前,请确认是否在 Advanced Google services 中启用了 Google Analytics API。
从:
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)
. 这样resource, accountId, propertyId
就可以确认顺序了。 - 如果您的每个参数
resource, accountId, propertyId
都有问题,则请求会返回错误。届时,请确认参数。
参考:
如果这没有解决您的问题,我深表歉意。
推荐阅读
- c# - 将不同的随机字符组合成一个字符串
- vue.js - 如何获取动态数组的数组长度
- c++ - 如何在 Visual Studio 解决方案的附加库目录中删除 $(Configuration)?
- bash - tar:压缩和删除原始文件并保持目录不变
- java - 存储在字符串资源中的 URL 在 Android 中变成数字
- javascript - Selenium,无法自动下载文件,下载确认一直显示
- matlab - Matlab mex“缺少依赖共享库”
- c++ - 从文件中读取文本时出现编码问题
- c++ - ESP32 OTA 更新在启动时不断崩溃
- intellij-idea - 智能。如何防止终端标签关闭?