← 返回目录
来源:Google Ads API 官方文档 · 中文版 · 本地归档

广告系列级转化目标

在效果最大化广告系列中,转化目标有助于引导 Google 的算法优化广告投放和预算分配,使其与您选择的广告系列出价策略保持一致。您可以明确地将客户目标的子集应用于效果最大化广告系列。如果您未明确为广告系列设置转化目标,系统会默认使用所有客户级转化目标。

如需为效果最大化广告系列设置广告系列转化目标,请按以下步骤操作:

  1. 检索所有 CustomerConversionGoals。

    SELECT
      customer_conversion_goal.category,
      customer_conversion_goal.origin
    FROM customer_conversion_goal
    
  2. 将每个 CustomerConversionGoal 复制为 CampaignConversionGoal 对象。如果您想根据 category 和 origin 的唯一组合将目标应用于效果最大化广告系列,请将 biddable 字段设置为 TRUE。否则,请将 biddable 设为 FALSE。biddable 字段用于指定是否应使用 CampaignConversionGoal。

  3. 发出 mutate 请求,以使用更新后的 biddable 字段值更新所有 CampaignConversionGoals。

    Java

    /** Retrieves the list of customer conversion goals. */
    private static List<CustomerConversionGoal> getCustomerConversionGoals(
        GoogleAdsClient googleAdsClient, long customerId) {
      String query =
          "SELECT customer_conversion_goal.category, customer_conversion_goal.origin "
              + "FROM customer_conversion_goal";
    
      List<CustomerConversionGoal> customerConversionGoals = new ArrayList<>();
      try (GoogleAdsServiceClient googleAdsServiceClient =
          googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
        // The number of conversion goals is typically less than 50, so we use
        // GoogleAdsService.search instead of search_stream.
        SearchPagedResponse response =
            googleAdsServiceClient.search(Long.toString(customerId), query);
        for (GoogleAdsRow googleAdsRow : response.iterateAll()) {
          customerConversionGoals.add(googleAdsRow.getCustomerConversionGoal());
        }
      }
    
      return customerConversionGoals;
    }
    
    /** Creates a list of MutateOperations that override customer conversion goals. */
    private static List<MutateOperation> createConversionGoalOperations(
        long customerId, List<CustomerConversionGoal> customerConversionGoals) {
      List<MutateOperation> mutateOperations = new ArrayList<>();
      // To override the customer conversion goals, we will change the
      // biddability of each of the customer conversion goals so that only
      // the desired conversion goal is biddable in this campaign.
      for (CustomerConversionGoal customerConversionGoal : customerConversionGoals) {
        ConversionActionCategory category = customerConversionGoal.getCategory();
        ConversionOrigin origin = customerConversionGoal.getOrigin();
        String campaignConversionGoalResourceName =
            ResourceNames.campaignConversionGoal(
                customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, category, origin);
        CampaignConversionGoal.Builder campaignConversionGoalBuilder =
            CampaignConversionGoal.newBuilder().setResourceName(campaignConversionGoalResourceName);
        // Change the biddability for the campaign conversion goal.
        // Set biddability to True for the desired (category, origin).
        // Set biddability to False for all other conversion goals.
        // Note:
        //  1- It is assumed that this Conversion Action
        //     (category=PURCHASE, origin=WEBSITE) exists in this account.
        //  2- More than one goal can be biddable if desired. This example
        //     shows only one.
        if (category == ConversionActionCategory.PURCHASE && origin == ConversionOrigin.WEBSITE) {
          campaignConversionGoalBuilder.setBiddable(true);
        } else {
          campaignConversionGoalBuilder.setBiddable(false);
        }
        CampaignConversionGoal campaignConversionGoal = campaignConversionGoalBuilder.build();
        CampaignConversionGoalOperation campaignConversionGoalOperation =
            CampaignConversionGoalOperation.newBuilder()
                .setUpdate(campaignConversionGoal)
                .setUpdateMask(FieldMasks.allSetFieldsOf(campaignConversionGoal))
                .build();
        mutateOperations.add(
            MutateOperation.newBuilder()
                .setCampaignConversionGoalOperation(campaignConversionGoalOperation)
                .build());
      }
      return mutateOperations;
    }
    
          

    C#

    /// <summary>
    /// Creates a MutateOperation that links an asset to an asset group.
    /// </summary>
    /// <param name="fieldType">The field type of the asset to be linked.</param>
    /// <param name="linkedEntityResourceName">The resource name of the entity (asset group or
    /// campaign) to link the asset to.</param>
    /// <param name="assetResourceName">The resource name of the text asset to be
    /// linked.</param>
    /// <param name="brandGuidelinesEnabled">Whether or not to enable brand guidelines.</param>
    /// <returns>A MutateOperation that links an asset to an asset group.</returns>
    private MutateOperation CreateLinkAssetOperation(
        AssetFieldType fieldType,
        string linkedEntityResourceName,
        string assetResourceName,
        bool brandGuidelinesEnabled = false)
    { if (brandGuidelinesEnabled)
        {
            return new MutateOperation()
            {
                CampaignAssetOperation = new CampaignAssetOperation()
                {
                    Create = new CampaignAsset()
                    {
                        FieldType = fieldType,
                        Campaign = linkedEntityResourceName,
                        Asset = assetResourceName
                    }
                }
            };
        } else
        {   return new MutateOperation()
            {
                AssetGroupAssetOperation = new AssetGroupAssetOperation()
                {
                    Create = new AssetGroupAsset()
                    {
                        FieldType = fieldType,
                        AssetGroup = linkedEntityResourceName,
                        Asset = assetResourceName
                    }
                }
            };
        }
    }
    
          

    PHP

    private static function getCustomerConversionGoals(
        GoogleAdsClient $googleAdsClient,
        int $customerId
    ): array {
        $customerConversionGoals = [];
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        // Creates a query that retrieves all customer conversion goals.
        $query = 'SELECT customer_conversion_goal.category, customer_conversion_goal.origin ' .
            'FROM customer_conversion_goal';
        // The number of conversion goals is typically less than 50 so we use a search request
        // instead of search stream.
        $response =
            $googleAdsServiceClient->search(SearchGoogleAdsRequest::build($customerId, $query));
    
        // Iterates over all rows in all pages and builds the list of conversion goals.
        foreach ($response->iterateAllElements() as $googleAdsRow) {
            /** @var GoogleAdsRow $googleAdsRow */
            $customerConversionGoals[] = [
                'category' => $googleAdsRow->getCustomerConversionGoal()->getCategory(),
                'origin' => $googleAdsRow->getCustomerConversionGoal()->getOrigin()
            ];
        }
    
        return $customerConversionGoals;
    }
    
    /**
     * Creates a list of MutateOperations that override customer conversion goals.
     *
     * @param int $customerId the customer ID
     * @param array $customerConversionGoals the list of customer conversion goals that will be
     *      overridden
     * @return MutateOperation[] a list of MutateOperations that update campaign conversion goals
     */
    private static function createConversionGoalOperations(
        int $customerId,
        array $customerConversionGoals
    ): array {
        $operations = [];
    
        // To override the customer conversion goals, we will change the biddability of each of the
        // customer conversion goals so that only the desired conversion goal is biddable in this
        // campaign.
        foreach ($customerConversionGoals as $customerConversionGoal) {
            $campaignConversionGoal = new CampaignConversionGoal([
                'resource_name' => ResourceNames::forCampaignConversionGoal(
                    $customerId,
                    self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID,
                    ConversionActionCategory::name($customerConversionGoal['category']),
                    ConversionOrigin::name($customerConversionGoal['origin'])
                )
            ]);
            // Changes the biddability for the campaign conversion goal.
            // Sets biddability to true for the desired (category, origin).
            // Sets biddability to false for all other conversion goals.
            // Note:
            //  1- It is assumed that this Conversion Action
            //     (category=PURCHASE, origin=WEBSITE) exists in this account.
            //  2- More than one goal can be biddable if desired. This example
            //     shows only one.
            if (
                $customerConversionGoal["category"] === ConversionActionCategory::PURCHASE
                && $customerConversionGoal["origin"] === ConversionOrigin::WEBSITE
            ) {
                $campaignConversionGoal->setBiddable(true);
            } else {
                $campaignConversionGoal->setBiddable(false);
            }
    
            $operations[] = new MutateOperation([
                'campaign_conversion_goal_operation' => new CampaignConversionGoalOperation([
                    'update' => $campaignConversionGoal,
                    // Sets the update mask on the operation. Here the update mask will be a list
                    // of all the fields that were set on the update object.
                    'update_mask' => FieldMasks::allSetFieldsOf($campaignConversionGoal)
                ])
            ]);
        }
    
        return $operations;
    }
在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →