再营销受众群体:update

需要授权

更新现有再营销受众群体。 查看示例

请求

HTTP 请求

PUT https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/remarketingAudiences/remarketingAudienceId

参数

参数名称 说明
路径参数
accountId string 要更新的再营销受众群体的帐号 ID。
remarketingAudienceId string 要更新的再营销受众群体的 ID。
webPropertyId string 要更新的再营销受众群体的网络媒体资源 ID。

授权

此请求需要获得下列范围的授权(详细了解身份验证和授权)。

范围
https://www.googleapis.com/auth/analytics.edit

请求正文

在请求正文中提供一个再营销受众群体资源

响应

如果成功,此方法将在响应正文中返回再营销受众群体资源

示例

备注:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

/*
 * This request updates an existing Remarketing Audience.
 */
// Create the LinkedForeignAccount object.
LinkedForeignAccount linkedAdAccount = new LinkedForeignAccount();
linkedAdAccount.setType("ADWORDS_LINKS");
linkedAdAccount.setAccountId(linkedAccountId);

// Create the IncludeConditions object.
IncludeConditions includeConditions = new IncludeConditions();
includeConditions.setIsSmartList(false);
includeConditions.setDaysToLookBack(7);
includeConditions.setMembershipDurationDays(30);
includeConditions.setSegment("users::condition::ga:browser==Chrome");

// Create the AudienceDefinition object.
AudienceDefinition audienceDefinition = new AudienceDefinition();
audienceDefinition.setIncludeConditions(includeConditions);

// Create the RemarketingAudience object.
RemarketingAudience audience = new RemarketingAudience();
audience.setName("Update Simple Audience");
audience.setLinkedViews(Arrays.asList(viewId));
audience.setLinkedAdAccounts(Arrays.asList(linkedAdAccount));
audience.setAudienceType("SIMPLE");
audience.setAudienceDefinition(audienceDefinition);

try {
  analytics
      .management()
      .remarketingAudience()
      .update(accountId, propertyId, remarketingAudienceId, audience)
      .execute();
} catch (GoogleJsonResponseException e) {
  System.err.println(
      "There was a service error: "
          + e.getDetails().getCode()
          + " : "
          + e.getDetails().getMessage());
}

PHP

使用 PHP 客户端库

/*
 * This request updates an existing Remarketing Audience.
 */
// Create the LinkedForeignAccount object.
Google_Service_Analytics_LinkedForeignAccount $linkedAdAccount = new Google_Service_Analytics_LinkedForeignAccount();
$linkedAdAccount->setType("ADWORDS_LINKS");
$linkedAdAccount->setAccountId(linkedAccountId);

// Create the IncludeConditions object.
Google_Service_Analytics_IncludeConditions $includeConditions = new Google_Service_Analytics_IncludeConditions();
$includeConditions->setIsSmartList(false);
$includeConditions->setDaysToLookBack(7);
$includeConditions->setMembershipDurationDays(30);
$includeConditions->setSegment("users::condition::ga:browser==Chrome");

// Create the AudienceDefinition object.
Google_Service_Analytics_RemarketingAudienceAudienceDefinition $audienceDefinition = new Google_Service_Analytics_RemarketingAudienceAudienceDefinition();
$audienceDefinition->setIncludeConditions($includeConditions);

// Create the RemarketingAudience object.
Google_Service_Analytics_RemarketingAudience $audience = new Google_Service_Analytics_RemarketingAudience();
$audience->setName("Update Simple Audience");
$audience->setLinkedViews(Arrays.asList(viewId));
$audience->setLinkedAdAccounts(Arrays.asList($linkedAdAccount));
$audience->setAudienceType("SIMPLE");
$audience->setAudienceDefinition($audienceDefinition);

try {
  $analytics->management_remarketingAudience->update($accountId, $propertyId, remarketingAudienceId, $audience);
} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

Python

使用 Python 客户端库

# Note: This code assumes you have an authorized Analytics service object.
# See the Remarketing Audiences Developer Guide for details.

# This request updates an existing Remarketing Audience.
try:
  analytics.management().remarketingAudience().update(
      accountId=accountId,
      webPropertyId=propertyId,
      remarketingAudienceId=remarketingAudienceId,
      body={
        'name': 'Update Simple Audience',
        'linkedViews': [viewId],
        'linkedAdAccounts': [{
            'type': 'ADWORDS_LINKS',
            'linkedAccountId': linkedAccountId
        }],
        'audienceType': 'SIMPLE',
        'audienceDefinition': {
          'includeConditions': {
            'isSmartList': False,
            'daysToLookBack': 7,
            'membershipDurationDays': 30,
            'segment': 'users::condition::ga:browser==Chrome'
          }
        }
      }
    ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

JavaScript

使用 JavaScript 客户端库

/**
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Unsampled Reports Developer Guide for details.
 */

/**
 * This request updates an existing Remarketing Audience.
 */
function updateRemarketingAudience(accountId, propertyId, viewId, audienceId) {
  let request = gapi.client.analytics.management.remarketingAudience.update(
    {
      'accountId': accountId,
      'webPropertyId': propertyId,
      'remarketingAudienceId': audienceId
      'resource': {
        'name': 'Update Simple Audience',
        'linkedViews': [viewId],
        'linkedAdAccounts': [{
            'type': 'ADWORDS_LINKS',
            'linkedAccountId': '202-867-5309'
        }],
        'audienceType': 'SIMPLE',
        'audienceDefinition': {
          'includeConditions': {
            'isSmartList': False,
            'daysToLookBack': 7,
            'membershipDurationDays': 30,
            'segment': 'users::condition::ga:browser==Chrome'
          }
        }
      }
    });
  request.execute(function (response) { /* handle the response */ });
}