adwords api 广告系列转化目标设置

googleads/google-ads-php v19.1.0. 广告系列如何设置自定义转化目标,通过代码如何实现?

使用 Google Ads API 中的 ConversionActionService。利用 ConversionActionService 类获取现有转化操作的列表,然后用 ConversionActionOperation 类来创建或更新转化操作。最后,使用 ConversionTracker 类来跟踪转化数据。

这是来自于Google Ads API 文档给出的示例代码:

// 获取 ConversionActionService 实例
$conversionActionService = $googleAdsClient->getConversionActionService();

// 获取现有的 ConversionAction 操作
$query = "SELECT conversion_action.id, conversion_action.name, conversion_action.type FROM conversion_action";
$response = $conversionActionService->search($query);

// 创建 ConversionAction 操作
$conversionActionOperation = new ConversionActionOperation();
$conversionAction = new ConversionAction();
$conversionAction->setName('My Conversion Action');
$conversionAction->setType(ConversionActionType::UPLOAD_CLICKS);
$conversionActionOperation->setCreate($conversionAction);

// 更新 ConversionAction 操作
$conversionActionOperation = new ConversionActionOperation();
$conversionAction = new ConversionAction();
$conversionAction->setId('INSERT_CONVERSION_ACTION_ID_HERE');
$conversionAction->setName('My Updated Conversion Action');
$conversionActionOperation->setUpdate($conversionAction);

// 创建 ConversionTracker 实例
$conversionTracker = new ConversionTracker();
$conversionTracker->setConversionName('My Conversion');
$conversionTracker->setConversionValue(100);
$conversionTracker->setConversionTime('2022-01-01T00:00:00');
$conversionTracker->setConversionCurrencyCode('USD');
$conversionTracker->setConversionQuantity(1);

// 跟踪转化数据
$conversionTrackerOperation = new ConversionTrackerOperation();
$conversionTrackerOperation->setCreate($conversionTracker);
$conversionTrackerService->mutate([$conversionTrackerOperation]);



要通过代码设置自定义转化目标,您需要执行以下步骤:

  1. 安装 Google Ads API PHP客户端库

    composer require google/ads-googleads
    
  2. 使用OAuth 2.0进行身份验证和授权

  3. 设置Google Ads Client对象,并将其配置为使用身份验证令牌。创建客户端对象时,我们可以指定开发者帐户操作的客户ID。

    use Google\Ads\GoogleAds\V6\Services\ConversionActionServiceClient;
    use Google\Ads\GoogleAds\Lib\V6\GoogleAdsClient;
    
    $googleAdsClient = GoogleAdsClient::Builder()
         ->withOAuth2Credential($oAuth2Credential)
         ->withDeveloperToken($developerToken)
         ->withLoginCustomerId($customerId)
         ->build();
    
  4. 得到ConversionActionServiceClient并调用createConversionAction()方法创建转化行动。

      $conversionActionServiceClient =
          $googleAdsClient->getConversionActionServiceClient();
    
      $conversionActionOperation = new ConversionActionOperation();
      $conversionAction = new ConversionAction();
    
      $conversionAction->setName('Mars cruise customers #' . uniqid());
      $conversionAction->setType(ConversionActionType::PURCHASE);
      $conversionAction->setCategory(ConversionActionCategory::DEFAULT_CATEGORY);
      $conversionAction->setViewThroughLookbackWindowDays(15);
      $conversionAction->setValueSettings(new ValueSettings(['default_value' => 23.41]));
    
      $conversionActionOperation->setCreate($conversionAction);
    
      $response = $conversionActionServiceClient->mutateConversionActions(
          $customerId,
          [$conversionActionOperation]
      );
      printf(
          "Created conversion action with resource name '%s'.\n",
          $response->getResults()[0]->getResourceName()
      );
    

    在此示例中,我们创建一个名称为“ Mars cruise customers #26f9c”的新转化动作,其类型为“ PURCHASE”,类别为“默认类别”。我们还指定了查看后期的天数和转化值设置。

  5. 完成后清理资源。

以下答案由GPT-3.5大模型与博主波罗歌共同编写:
首先,使用 Google Ads API 设置自定义转化目标需要遵循以下步骤:

  1. 创建自定义转化操作: 在 Google Ads 界面上创建一个自定义转化操作,以定义自定义转化的名称、转化类型和转化列等参数。

  2. 获取转化操作 ID: 在创建自定义转化操作完成后,可以在 Google Ads 界面上找到该操作的 ID 。将该 ID 用于设置或更新广告系列的转化目标。

  3. 创建或更新广告系列: 使用 Google Ads API 创建或更新广告系列,并使用转化操作 ID 指定自定义转化目标。

接下来是如何通过 Google Ads API 的 PHP 版本实现设置自定义转化目标的代码示例,代码如下:

use Google\Ads\GoogleAds\Util\V3\ResourceNames;
use Google\Ads\GoogleAds\V3\Services\CampaignOperation;
use Google\Ads\GoogleAds\V3\Services\CampaignServiceClient;
use Google\Ads\GoogleAds\V3\Resources\Campaign;
use Google\Ads\GoogleAds\V3\Common\ManualCpc;
use Google\Ads\GoogleAds\V3\Common\CampaignBudget;
use Google\Ads\GoogleAds\V3\Common\FrequencyCap;
use Google\Ads\GoogleAds\V3\Common\CustomParameter;
use Google\Ads\GoogleAds\V3\Common\CustomParameters;
use Google\Ads\GoogleAds\V3\Common\TrackingSetting;
use Google\Ads\GoogleAds\V3\Common\RemarketingSetting;
use Google\Ads\GoogleAds\V3\Common\ConversionTrackingSetting;

$client = new GoogleAdsClient();

$campaignResourceName = ResourceNames::forCampaign($customerId, $campaignId);

$campaign = new Campaign([
    'resource_name' => $campaignResourceName,
    'name' => 'Test Campaign Updated',
    'status' => 'PAUSED',
    'advertising_channel_type' => 'SEARCH',
    'manual_cpc' => new ManualCpc(),
    'campaign_budget' => new CampaignBudget([
        'resource_name' => ResourceNames::forCampaignBudget($customerId, $campaignBudgetId)
    ]),
    'frequency_cap' => new FrequencyCap([
        'impressions' => 3
    ]),
    'custom_parameters' => new CustomParameters([
        'parameters' => [
            new CustomParameter([
                'key' => 'promoCode',
                'value' => 'Holidays2014'
            ])
        ]
    ]),
    'tracking_setting' => new TrackingSetting([
        'tracking_url_template' => 'http://tracker.example.com/?u={lpurl}'
    ]),
    'remarketing_setting' => new RemarketingSetting([
        'google_global_site_tag' => 
        '<!-- Global site tag (gtag.js) - Google Ads: AW-123456789 -->'
    ]),
    'conversion_tracking_setting' => new ConversionTrackingSetting([
        'conversion_tracking_id' => 123,
        'conversion_tracking_id_type' => 'GOOGLE_ADS',
        'selective_optimization' => 0,
        'conversion_action' => ResourceNames::forConversionAction($customerId, $conversionActionId)
    ])
]);

$campaignOperation = new CampaignOperation();
$campaignOperation->setUpdate($campaign);

$campaignServiceClient = $client->getCampaignServiceClient();
$response = $campaignServiceClient->mutateCampaigns($customerId, [$campaignOperation]);

printf("Campaign with ID %d was updated.%s", $response->getResults()[0]->getResourceName() . PHP_EOL);

请注意,上述代码仅在示例场景下工作。对于真实的情况,需要根据具体的业务需求对代码进行更改。
如果我的回答解决了您的问题,请采纳!

该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
要设置广告系列的自定义转化目标,可以使用Google Ads API提供的ConversionActionService。下面是设置自定义转化目标的代码示例:

use Google\Ads\GoogleAds\V8\Services\ConversionActionServiceClient;

// 设置自定义转化目标
$conversionActionServiceClient = new ConversionActionServiceClient();
$conversionAction = $conversionActionServiceClient->mutateConversionActions(
    $customerId,
    [
        (new ConversionAction())
            ->setName('My Custom Conversion Action')
            ->setType(ConversionActionType::UPLOAD_CLICKS)
            ->setCategory(ConversionActionCategory::DEFAULT)
            ->setStatus(ConversionActionStatus::ENABLED)
            ->setViewThroughLookbackWindowDays(30)
            ->setClickThroughLookbackWindowDays(7)
            ->setConversionValueRule(
                (new ValueRule())
                    ->setConversionValueRuleOperands([
                        (new ValueRuleOperand())
                            ->setConstantOperand(
                                (new ConstantOperand())
                                    ->setType(ConstantOperandType::BOOLEAN)
                                    ->setBooleanValue(true)
                            )
                    ])
            )
            ->setConversionValueRules([
                (new ConversionValueRule())
                    ->setConversionValueRuleOperands([
                        (new ValueRuleOperand())
                            ->setEventOperand(
                                (new EventOperand())
                                    ->setMatchType(EventMatchType::EXACT)
                                    ->setEventType('MY_CUSTOM_EVENT_TYPE')
                            ),
                        (new ValueRuleOperand())
                            ->setConstantOperand(
                                (new ConstantOperand())
                                    ->setType(ConstantOperandType::BOOLEAN)
                                    ->setBooleanValue(true)
                            )
                    ])
                    ->setConversionValue(1.0)
            ])
    ]
)->getResults()[0];

// 设置广告系列转化目标
$campaignServiceClient = new CampaignServiceClient();
$campaign = (new Campaign())
    ->setResourceName($campaignResourceName)
    ->setConversionTrackingSettings(
        (new ConversionTrackingSettings())
            ->setConversionTrackingId($conversionAction->getId())
            ->setCrossAccountConversionTrackingId($crossAccountConversionTrackingId)
    );
$campaignServiceClient->mutateCampaigns($customerId, [$campaign]);

在上述代码中,首先创建了一个自定义转化目标,并设置了转化目标的名称、类型、状态、回传窗口等属性,以及转化价值的规则。然后,使用ConversionActionServiceClientmutateConversionActions方法创建自定义转化目标。

接着,使用CampaignServiceClient获取要设置转化目标的广告系列,将自定义转化目标的ID设置到ConversionTrackingSettings中,并使用mutateCampaigns方法更新广告系列的转化跟踪设置。

需要注意的是,上述代码中使用了Google Ads API的PHP客户端库googleads/google-ads-php的V8版本,如果您使用的是其他版本的客户端库,代码可能会有所不同。

希望对您有所帮助。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

引用chatGPT作答,要设置自定义转化目标,您需要执行以下步骤:

1.创建自定义转化操作(ConversionAction)对象,并设置相关属性,例如转化名称,转化类型等等。

2.调用 ConversionActionService 的 mutate() 方法,将自定义转化操作对象作为参数传递,以创建自定义转化。

3.获取新创建的自定义转化的 ID。

4.将自定义转化 ID 分配给广告系列的 conversionAction 属性。

下面是一个示例代码,用于创建自定义转化并将其应用于广告系列:

// Create a ConversionActionServiceClient instance
$conversionActionServiceClient = new ConversionActionServiceClient();

// Create a ConversionActionOperation instance
$operation = new ConversionActionOperation();
$conversionAction = new ConversionAction();

// Set the name and type of the conversion action
$conversionAction->setName('My Conversion Action');
$conversionAction->setType(ConversionActionType::PURCHASE);

// Set any additional properties as necessary
// ...

// Add the conversion action to the operation
$operation->setCreate($conversionAction);

// Call the mutate() method to create the conversion action
$response = $conversionActionServiceClient->mutate([$operation]);
$conversionAction = $response->getResults()[0];

// Get the ID of the new conversion action
$conversionActionId = $conversionAction->getId();

// Create a CampaignServiceClient instance
$campaignServiceClient = new CampaignServiceClient();

// Create a CampaignOperation instance
$operation = new CampaignOperation();
$campaign = new Campaign();

// Set the ID of the conversion action to use for the campaign
$campaign->setConversionAction($conversionActionId);

// Set any additional properties as necessary
// ...

// Add the campaign to the operation
$operation->setUpdate($campaign);

// Call the mutate() method to update the campaign with the new conversion action
$response = $campaignServiceClient->mutate([$operation]);
$campaign = $response->getResults()[0];