スタート ガイド

コンバージョンを記録するには、Google 広告のコンバージョン アカウントでコンバージョン トラッキングを有効にする必要があります。このガイドでは、コンバージョン トラッキングが有効になっているかどうかを確認する方法、有効になっていない場合に有効にする方法、既存のコンバージョン アクションに関する情報を取得する方法について詳しく説明します。

ほとんどのコンバージョン アクションでは、トラッキングを行うために追加の手順が必要になります。さまざまなコンバージョン アクションのタイプとその要件について詳しくは、コンバージョン アクションのカテゴリとコンバージョン アクションを作成するをご覧ください。

コンバージョン データまたはユーザーデータをインポートする際は、コンバージョン データを Google と共有する権限があることを確認する必要があります。これは、次のいずれかの方法で行います。

  1. アカウント単位のデフォルトの同意設定を構成します。Google 広告の UI で、[ツール] > [データ マネージャー] > [同意モードの設定] > [デフォルトの同意モードの設定] をクリックします。
  2. インポートした各コンバージョンまたはユーザーデータ ペイロードで同意フィールドを設定します(ClickConversion.consent、CallConversion.consent、UserData.consent など)。

コンバージョンをトラッキングするようにウェブサイトを設定する

ウェブサイトのコンバージョンをトラッキングしている場合や、見込み顧客向けの拡張コンバージョンを実装している場合は、まずウェブサイトのタグ設定を行います。リードの拡張コンバージョン用に Google タグを設定するの手順に沿って設定するか、リードの拡張コンバージョン用に Google タグ マネージャーを設定するの手順に沿って Google タグ マネージャーを使用します。

Google 広告のコンバージョン アカウントでコンバージョン トラッキングを有効にする

アカウントのコンバージョン トラッキングの設定を確認し、コンバージョン アクションを作成または取得する手順は次のとおりです。

コンバージョン トラッキングを有効にする手順

コンバージョン トラッキングの設定に関する情報を取得する

アカウントのコンバージョン トラッキングの設定を確認し、コンバージョン トラッキングが有効になっていることを確認するには、ConversionTrackingSetting の Customer リソースをクエリします。GoogleAdsService.SearchStream を使用して次のクエリを発行します。

SELECT
  customer.conversion_tracking_setting.google_ads_conversion_customer,
  customer.conversion_tracking_setting.conversion_tracking_status,
  customer.conversion_tracking_setting.conversion_tracking_id,
  customer.conversion_tracking_setting.cross_account_conversion_tracking_id
FROM customer

google_ads_conversion_customer フィールドは、このお客様のコンバージョンを作成および管理する Google 広告アカウントを示します。クロスアカウント コンバージョン トラッキングを使用しているお客様の場合は、MCC アカウントの ID です。コンバージョンを作成、管理する Google Ads API リクエストでは、Google 広告のコンバージョンのお客様 ID を customer_id として指定する必要があります。このフィールドは、コンバージョン トラッキングが有効になっていない場合でも入力されます。

conversion_tracking_status フィールドは、コンバージョン トラッキングが有効になっているかどうか、アカウントでクロスアカウント コンバージョン トラッキングが使用されているかどうかを示します。

Google 広告のコンバージョン顧客でコンバージョン アクションを作成する

conversion_tracking_status の値が NOT_CONVERSION_TRACKED の場合、アカウントでコンバージョン トラッキングが有効になっていません。次の例のように、Google 広告のコンバージョン アカウントで ConversionAction を 1 つ以上作成して、コンバージョン トラッキングを有効にします。または、有効にするコンバージョン タイプについて、コンバージョン トラッキングの設定に関する Google 広告ヘルプセンター記事の手順に沿って、UI でコンバージョン アクションを作成することもできます。

Google Ads API を介して送信された場合、拡張コンバージョンは自動的に有効になりますが、Google 広告の管理画面から無効にできます。

サンプルコード

Java

private void runExample(GoogleAdsClient googleAdsClient, long customerId) {

  // Creates a ConversionAction.
  ConversionAction conversionAction =
      ConversionAction.newBuilder()
          // Note that conversion action names must be unique. If a conversion action already
          // exists with the specified conversion_action_name the create operation will fail with
          // a ConversionActionError.DUPLICATE_NAME error.
          .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime())
          .setCategory(ConversionActionCategory.DEFAULT)
          .setType(ConversionActionType.WEBPAGE)
          .setStatus(ConversionActionStatus.ENABLED)
          .setViewThroughLookbackWindowDays(15L)
          .setValueSettings(
              ValueSettings.newBuilder()
                  .setDefaultValue(23.41)
                  .setAlwaysUseDefaultValue(true)
                  .build())
          .build();

  // Creates the operation.
  ConversionActionOperation operation =
      ConversionActionOperation.newBuilder().setCreate(conversionAction).build();

  try (ConversionActionServiceClient conversionActionServiceClient =
      googleAdsClient.getLatestVersion().createConversionActionServiceClient()) {
    MutateConversionActionsResponse response =
        conversionActionServiceClient.mutateConversionActions(
            Long.toString(customerId), Collections.singletonList(operation));
    System.out.printf("Added %d conversion actions:%n", response.getResultsCount());
    for (MutateConversionActionResult result : response.getResultsList()) {
      System.out.printf(
          "New conversion action added with resource name: '%s'%n", result.getResourceName());
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId)
{
    // Get the ConversionActionService.
    ConversionActionServiceClient conversionActionService =
        client.GetService(Services.V25.ConversionActionService);

    // Note that conversion action names must be unique.
    // If a conversion action already exists with the specified name the create operation
    // will fail with a ConversionAction.DUPLICATE_NAME error.
    string ConversionActionName = "Earth to Mars Cruises Conversion #"
        + ExampleUtilities.GetRandomString();

    // Add a conversion action.
    ConversionAction conversionAction = new ConversionAction()
    {
        Name = ConversionActionName,
        Category = ConversionActionCategory.Default,
        Type = ConversionActionType.Webpage,
        Status = ConversionActionStatus.Enabled,
        ViewThroughLookbackWindowDays = 15,
        ValueSettings = new ConversionAction.Types.ValueSettings()
        {
            DefaultValue = 23.41,
            AlwaysUseDefaultValue = true
        }
    };

    // Create the operation.
    ConversionActionOperation operation = new ConversionActionOperation()
    {
        Create = conversionAction
    };

    try
    {
        // Create the conversion action.
        MutateConversionActionsResponse response =
            conversionActionService.MutateConversionActions(customerId.ToString(),
                    new ConversionActionOperation[] { operation });

        // Display the results.
        foreach (MutateConversionActionResult newConversionAction in response.Results)
        {
            Console.WriteLine($"New conversion action with resource name = " +
                $"'{newConversionAction.ResourceName}' was added.");
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

    public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId)
    {
        // Creates a conversion action.
        $conversionAction = new ConversionAction(
            [
            // Note that conversion action names must be unique.
            // If a conversion action already exists with the specified conversion_action_name
            // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error.
            'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(),
            'category' => ConversionActionCategory::PBDEFAULT,
            'type' => ConversionActionType::WEBPAGE,
            'status' => ConversionActionStatus::ENABLED,
            'view_through_lookback_window_days' => 15,
            'value_settings' => new ValueSettings(
                [
                'default_value' => 23.41,
                'always_use_default_value' => true
                ]
            )
            ]
        );

        // Creates a conversion action operation.
        $conversionActionOperation = new ConversionActionOperation();
        $conversionActionOperation->setCreate($conversionAction);

        // Issues a mutate request to add the conversion action.
        $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient();
        $response = $conversionActionServiceClient->mutateConversionActions(
            MutateConversionActionsRequest::build($customerId, [$conversionActionOperation])
        );

        printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL);

        foreach ($response->getResults() as $addedConversionAction) {
            /**
 * @var ConversionAction $addedConversionAction
*/
            printf(
                "New conversion action added with resource name: '%s'%s",
                $addedConversionAction->getResourceName(),
                PHP_EOL
            );
        }
    }
      

Python

def main(client: GoogleAdsClient, customer_id: str) -> None:
    conversion_action_service: ConversionActionServiceClient = (
        client.get_service("ConversionActionService")
    )

    # Create the operation.
    conversion_action_operation: ConversionActionOperation = client.get_type(
        "ConversionActionOperation"
    )

    # Create conversion action.
    conversion_action: ConversionAction = conversion_action_operation.create

    # Note that conversion action names must be unique. If a conversion action
    # already exists with the specified conversion_action_name, the create
    # operation will fail with a ConversionActionError.DUPLICATE_NAME error.
    conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}"
    conversion_action.type_ = (
        client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS
    )
    conversion_action.category = (
        client.enums.ConversionActionCategoryEnum.DEFAULT
    )
    conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED
    conversion_action.view_through_lookback_window_days = 15

    # Create a value settings object.
    value_settings: ConversionAction.ValueSettings = (
        conversion_action.value_settings
    )
    value_settings.default_value = 15.0
    value_settings.always_use_default_value = True

    # Add the conversion action.
    conversion_action_response: MutateConversionActionsResponse = (
        conversion_action_service.mutate_conversion_actions(
            customer_id=customer_id,
            operations=[conversion_action_operation],
        )
    )

    print(
        "Created conversion action "
        f'"{conversion_action_response.results[0].resource_name}".'
    )
      

Ruby

def add_conversion_action(customer_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new


  # Add a conversion action.
  conversion_action = client.resource.conversion_action do |ca|
    ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}"
    ca.type = :UPLOAD_CLICKS
    ca.category = :DEFAULT
    ca.status = :ENABLED
    ca.view_through_lookback_window_days = 15

    # Create a value settings object.
    ca.value_settings = client.resource.value_settings do |vs|
      vs.default_value = 15
      vs.always_use_default_value = true
    end
  end

  # Create the operation.
  conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action)

  # Add the ad group ad.
  response = client.service.conversion_action.mutate_conversion_actions(
    customer_id: customer_id,
    operations: [conversion_action_operation],
  )

  puts "New conversion action with resource name = #{response.results.first.resource_name}."
end
      

Perl

sub add_conversion_action {
  my ($api_client, $customer_id) = @_;

  # Note that conversion action names must be unique.
  # If a conversion action already exists with the specified conversion_action_name,
  # the create operation fails with error ConversionActionError.DUPLICATE_NAME.
  my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid();

  # Create a conversion action.
  my $conversion_action =
    Google::Ads::GoogleAds::V25::Resources::ConversionAction->new({
      name                          => $conversion_action_name,
      category                      => DEFAULT,
      type                          => WEBPAGE,
      status                        => ENABLED,
      viewThroughLookbackWindowDays => 15,
      valueSettings                 =>
        Google::Ads::GoogleAds::V25::Resources::ValueSettings->new({
          defaultValue          => 23.41,
          alwaysUseDefaultValue => "true"
        })});

  # Create a conversion action operation.
  my $conversion_action_operation =
    Google::Ads::GoogleAds::V25::Services::ConversionActionService::ConversionActionOperation
    ->new({create => $conversion_action});

  # Add the conversion action.
  my $conversion_actions_response =
    $api_client->ConversionActionService()->mutate({
      customerId => $customer_id,
      operations => [$conversion_action_operation]});

  printf "New conversion action added with resource name: '%s'.\n",
    $conversion_actions_response->{results}[0]{resourceName};

  return 1;
}
      

curl

type が正しい ConversionActionType 値に設定されていることを確認します。Google Ads API でコンバージョン アクションを作成する方法について詳しくは、コンバージョン アクションを作成するをご覧ください。

既存のコンバージョン アクションを取得する

既存のコンバージョン アクションの詳細を取得するには、次のクエリを発行します。リクエストの顧客 ID が、先ほど特定した Google 広告のコンバージョン顧客に設定され、コンバージョン アクション タイプが正しい ConversionActionType 値に設定されていることを確認します。

SELECT
  conversion_action.id,
  conversion_action.resource_name,
  conversion_action.name,
  conversion_action.type,
  conversion_action.category,
  conversion_action.status
FROM conversion_action

WHERE conversion_action.type = 'INSERT_CONVERSION_ACTION_TYPE'

クロスアカウント コンバージョン トラッキング

クロスアカウント コンバージョン トラッキングを使用すると、Google 広告アカウントは、コンバージョンを生成した広告を配信した可能性のある他のアカウントに代わってコンバージョンをインポートできます。これにより、インポート リクエストを行うアカウントを統合できるため、統合を簡素化できます。

Google Ads API でのクロスアカウント コンバージョン トラッキングの有効化

Google Ads API を使用すると、クライアント アカウントの作成時または更新時に、クロス コンバージョン トラッキングを有効にできます。

Customer リソースで、conversion_tracking_setting.google_ads_conversion_customer フィールドを、クライアント アカウントのコンバージョン アクションを管理する MCC アカウントのリソース名に設定します。

クライアント アカウントのコンバージョン顧客を変更するリクエストは、クライアントの新しいコンバージョン顧客となる MCC アカウントから送信する必要があります。これを行うには、login-customer-id をクライアント センター(MCC)アカウント ID に設定します。

クロスアカウント コンバージョン トラッキングを有効にする場合、または既存のクライアント アカウントのコンバージョン トラッキング マネージャーを切り替える場合は、UI でこの変更を行う場合と同じ注意点があります。詳細は以下のとおりです。

  • クライアント アカウントには、新しいコンバージョン トラッキング マネージャーのデフォルトのコンバージョン値のルールとデフォルトの顧客ライフサイクル目標が適用されます。
  • 特定のコンバージョン アクションをターゲットにしているキャンペーンは、コンバージョン マネージャー アカウントのデフォルトのコンバージョン目標を使用するように切り替わります。特定のコンバージョン アクションをターゲットに設定し続けると、クライアント アカウントとマネージャー アカウントで目標が異なる場合があるため、動作に一貫性がなくなる可能性があります。キャンペーンが適切な目標に合わせて最適化されていることを確認します。
  • アカウントが複数の MCC アカウントに属している場合、使用できるのは 1 つの MCC アカウントのコンバージョン アクションのみです。コンバージョン トラッキング アカウントが指定されていない場合、アカウントはデフォルトで自身をコンバージョン トラッキング アカウントとして使用します。

アカウント間のコンバージョンのインポート

クロスアカウント トラッキングが有効になっている場合、クライアント アカウントと MCC アカウントは、広告配信中アカウントに代わってコンバージョンをインポートできます。これにより、インポート ロジックを簡素化できます。インポート時にコンバージョンごとに配信アカウントを特定する必要がなくなり、アカウント ツリーから 1 つのアカウントを選択してすべてのコンバージョンをインポートできます。

コンバージョンを正常にアップロードするには、アップロードするアカウントがコンバージョン アクションにアクセスできる必要があります。クロスアカウント トラッキングの階層では、アカウント ツリー内のコンバージョン アクションの所有者の親(マネージャー)または子孫である場合、アップロード アカウントはアクションにアクセスできます。

次の図は、コンバージョンのインポートの認可構造を示しています。ここで、C1 はコンバージョンを発生させた広告を配信したクライアント アカウント、M2 はコンバージョン アクションの所有者であり、C1 のコンバージョン トラッキングの親です。緑色でハイライト表示されているアカウントは C1 の代わりにコンバージョンをインポートできますが、赤色でハイライト表示されているアカウントはインポートできません。

承認の構造

コンバージョン アクションを作成する

コンバージョンを測定するには、トラッキングするコンバージョン アクションの type に ConversionAction を設定します。たとえば、オンライン購入と電話での問い合わせでは、異なるコンバージョン アクションが必要です。

API で新しいコンバージョン アクションを設定する最適な方法は、コンバージョン アクションの追加コード例を使用することです。このサンプルでは、バックグラウンド認証タスクをすべて処理し、ConversionAction の作成手順を説明します。

ほとんどのコンバージョン アクションでは、トラッキングを行うために追加の手順が必要になります。たとえば、ウェブサイトでコンバージョンをトラッキングするには、ウェブサイトのコンバージョン ページにタグと呼ばれるコード スニペットを追加する必要があります。他のコンバージョン アクション タイプの詳細な要件については、コンバージョンの種類に関する Google 広告ヘルプセンター記事をご覧ください。

クロスアカウント コンバージョン トラッキングを使用している場合、ConversionActionService は次のコンバージョン アクションを返します。

  • アカウントがクロスアカウント コンバージョン トラッキングに使用する MCC アカウントによって定義されたすべてのコンバージョン アクション
  • システム定義のアクションや、マネージャーが所有するアクションなど、お客様が統計情報を蓄積したすべてのコンバージョン アクション(マネージャーが後でリンクを解除した場合も含む)
  • お客様がご自身のアカウントで定義したすべてのアクション
  • リンクされた Google アナリティクス プロパティで作成されたアナリティクス コンバージョン。これには、Google 広告にインポートされていないアナリティクス コンバージョン(ステータスが HIDDEN)のアクションも含まれます。

サンプルコード

次のコード例では、新しいコンバージョン アクションを作成する手順について説明します。具体的には、type が UPLOAD_CLICKS に設定されたコンバージョン アクションを作成します。また、category を DEFAULT に設定します。

次のデフォルト設定が適用されます。

Java

private void runExample(GoogleAdsClient googleAdsClient, long customerId) {

  // Creates a ConversionAction.
  ConversionAction conversionAction =
      ConversionAction.newBuilder()
          // Note that conversion action names must be unique. If a conversion action already
          // exists with the specified conversion_action_name the create operation will fail with
          // a ConversionActionError.DUPLICATE_NAME error.
          .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime())
          .setCategory(ConversionActionCategory.DEFAULT)
          .setType(ConversionActionType.WEBPAGE)
          .setStatus(ConversionActionStatus.ENABLED)
          .setViewThroughLookbackWindowDays(15L)
          .setValueSettings(
              ValueSettings.newBuilder()
                  .setDefaultValue(23.41)
                  .setAlwaysUseDefaultValue(true)
                  .build())
          .build();

  // Creates the operation.
  ConversionActionOperation operation =
      ConversionActionOperation.newBuilder().setCreate(conversionAction).build();

  try (ConversionActionServiceClient conversionActionServiceClient =
      googleAdsClient.getLatestVersion().createConversionActionServiceClient()) {
    MutateConversionActionsResponse response =
        conversionActionServiceClient.mutateConversionActions(
            Long.toString(customerId), Collections.singletonList(operation));
    System.out.printf("Added %d conversion actions:%n", response.getResultsCount());
    for (MutateConversionActionResult result : response.getResultsList()) {
      System.out.printf(
          "New conversion action added with resource name: '%s'%n", result.getResourceName());
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId)
{
    // Get the ConversionActionService.
    ConversionActionServiceClient conversionActionService =
        client.GetService(Services.V25.ConversionActionService);

    // Note that conversion action names must be unique.
    // If a conversion action already exists with the specified name the create operation
    // will fail with a ConversionAction.DUPLICATE_NAME error.
    string ConversionActionName = "Earth to Mars Cruises Conversion #"
        + ExampleUtilities.GetRandomString();

    // Add a conversion action.
    ConversionAction conversionAction = new ConversionAction()
    {
        Name = ConversionActionName,
        Category = ConversionActionCategory.Default,
        Type = ConversionActionType.Webpage,
        Status = ConversionActionStatus.Enabled,
        ViewThroughLookbackWindowDays = 15,
        ValueSettings = new ConversionAction.Types.ValueSettings()
        {
            DefaultValue = 23.41,
            AlwaysUseDefaultValue = true
        }
    };

    // Create the operation.
    ConversionActionOperation operation = new ConversionActionOperation()
    {
        Create = conversionAction
    };

    try
    {
        // Create the conversion action.
        MutateConversionActionsResponse response =
            conversionActionService.MutateConversionActions(customerId.ToString(),
                    new ConversionActionOperation[] { operation });

        // Display the results.
        foreach (MutateConversionActionResult newConversionAction in response.Results)
        {
            Console.WriteLine($"New conversion action with resource name = " +
                $"'{newConversionAction.ResourceName}' was added.");
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

    public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId)
    {
        // Creates a conversion action.
        $conversionAction = new ConversionAction(
            [
            // Note that conversion action names must be unique.
            // If a conversion action already exists with the specified conversion_action_name
            // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error.
            'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(),
            'category' => ConversionActionCategory::PBDEFAULT,
            'type' => ConversionActionType::WEBPAGE,
            'status' => ConversionActionStatus::ENABLED,
            'view_through_lookback_window_days' => 15,
            'value_settings' => new ValueSettings(
                [
                'default_value' => 23.41,
                'always_use_default_value' => true
                ]
            )
            ]
        );

        // Creates a conversion action operation.
        $conversionActionOperation = new ConversionActionOperation();
        $conversionActionOperation->setCreate($conversionAction);

        // Issues a mutate request to add the conversion action.
        $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient();
        $response = $conversionActionServiceClient->mutateConversionActions(
            MutateConversionActionsRequest::build($customerId, [$conversionActionOperation])
        );

        printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL);

        foreach ($response->getResults() as $addedConversionAction) {
            /**
 * @var ConversionAction $addedConversionAction
*/
            printf(
                "New conversion action added with resource name: '%s'%s",
                $addedConversionAction->getResourceName(),
                PHP_EOL
            );
        }
    }
      

Python

def main(client: GoogleAdsClient, customer_id: str) -> None:
    conversion_action_service: ConversionActionServiceClient = (
        client.get_service("ConversionActionService")
    )

    # Create the operation.
    conversion_action_operation: ConversionActionOperation = client.get_type(
        "ConversionActionOperation"
    )

    # Create conversion action.
    conversion_action: ConversionAction = conversion_action_operation.create

    # Note that conversion action names must be unique. If a conversion action
    # already exists with the specified conversion_action_name, the create
    # operation will fail with a ConversionActionError.DUPLICATE_NAME error.
    conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}"
    conversion_action.type_ = (
        client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS
    )
    conversion_action.category = (
        client.enums.ConversionActionCategoryEnum.DEFAULT
    )
    conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED
    conversion_action.view_through_lookback_window_days = 15

    # Create a value settings object.
    value_settings: ConversionAction.ValueSettings = (
        conversion_action.value_settings
    )
    value_settings.default_value = 15.0
    value_settings.always_use_default_value = True

    # Add the conversion action.
    conversion_action_response: MutateConversionActionsResponse = (
        conversion_action_service.mutate_conversion_actions(
            customer_id=customer_id,
            operations=[conversion_action_operation],
        )
    )

    print(
        "Created conversion action "
        f'"{conversion_action_response.results[0].resource_name}".'
    )
      

Ruby

def add_conversion_action(customer_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new


  # Add a conversion action.
  conversion_action = client.resource.conversion_action do |ca|
    ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}"
    ca.type = :UPLOAD_CLICKS
    ca.category = :DEFAULT
    ca.status = :ENABLED
    ca.view_through_lookback_window_days = 15

    # Create a value settings object.
    ca.value_settings = client.resource.value_settings do |vs|
      vs.default_value = 15
      vs.always_use_default_value = true
    end
  end

  # Create the operation.
  conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action)

  # Add the ad group ad.
  response = client.service.conversion_action.mutate_conversion_actions(
    customer_id: customer_id,
    operations: [conversion_action_operation],
  )

  puts "New conversion action with resource name = #{response.results.first.resource_name}."
end
      

Perl

sub add_conversion_action {
  my ($api_client, $customer_id) = @_;

  # Note that conversion action names must be unique.
  # If a conversion action already exists with the specified conversion_action_name,
  # the create operation fails with error ConversionActionError.DUPLICATE_NAME.
  my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid();

  # Create a conversion action.
  my $conversion_action =
    Google::Ads::GoogleAds::V25::Resources::ConversionAction->new({
      name                          => $conversion_action_name,
      category                      => DEFAULT,
      type                          => WEBPAGE,
      status                        => ENABLED,
      viewThroughLookbackWindowDays => 15,
      valueSettings                 =>
        Google::Ads::GoogleAds::V25::Resources::ValueSettings->new({
          defaultValue          => 23.41,
          alwaysUseDefaultValue => "true"
        })});

  # Create a conversion action operation.
  my $conversion_action_operation =
    Google::Ads::GoogleAds::V25::Services::ConversionActionService::ConversionActionOperation
    ->new({create => $conversion_action});

  # Add the conversion action.
  my $conversion_actions_response =
    $api_client->ConversionActionService()->mutate({
      customerId => $customer_id,
      operations => [$conversion_action_operation]});

  printf "New conversion action added with resource name: '%s'.\n",
    $conversion_actions_response->{results}[0]{resourceName};

  return 1;
}
      

curl

この例は、クライアント ライブラリの Remarketing フォルダと、コード例のコレクション(コンバージョン アクションの追加コード例)で確認できます。

検証

Google 広告と Google 広告 API はさまざまなコンバージョン アクションをサポートしているため、一部の検証ルールはアクションの type に基づいて異なります。

コンバージョン アクションの作成時に最もよく発生するエラーは DUPLICATE_NAME です。各コンバージョン アクションに一意の名前を使用していることを確認します。

ConversionAction フィールドを設定する際のヒントをいくつかご紹介します。

すべての列挙型フィールド
列挙型フィールドを UNKNOWN に設定しようとすると、RequestError.INVALID_ENUM_VALUE エラーが発生します。
app_id
app_id 属性は不変であり、新しいアプリ コンバージョンを作成するときにのみ設定できます。
attribution_model_settings
これを非推奨のオプションに設定すると、CANNOT_SET_RULE_BASED_ATTRIBUTION_MODELS エラーが発生します。Google 広告は GOOGLE_ADS_LAST_CLICK と GOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN のみをサポートしています。
click_through_lookback_window_days

この属性を許容範囲外の値に設定すると、RangeError.TOO_LOW または RangeError.TOO_HIGH エラーが発生します。

この属性は、AD_CALL または WEBSITE_CALL コンバージョン アクションの場合、1 ~ 60 日の範囲で指定する必要があります。その他のほとんどのコンバージョン アクションでは、1 ~ 90 日の範囲で設定できます。

include_in_conversions_metric

create オペレーションまたは update オペレーションでこの値を設定すると、FieldError.IMMUTABLE_FIELD エラーで失敗します。代わりに、コンバージョン目標ガイドの説明に沿って primary_for_goal を設定してください。

phone_call_duration_seconds

通話以外のコンバージョン アクションでこの属性を設定しようとすると、FieldError.VALUE_MUST_BE_UNSET エラーが発生します。

type

type 属性は不変であり、新しいコンバージョンを作成するときにのみ設定できます。

type が UNKNOWN に等しいコンバージョン アクションを更新すると、MutateError.MUTATE_NOT_ALLOWED エラーが発生します。

value_settings

WEBSITE_CALL または AD_CALL コンバージョン アクションの value_settings では、always_use_default_value を true に設定する必要があります。この値の作成または更新時に false の値を指定すると、INVALID_VALUE エラーが発生します。

view_through_lookback_window_days

この属性を許容範囲外の値に設定すると、RangeError.TOO_LOW または RangeError.TOO_HIGH エラーが発生します。ほとんどのコンバージョン アクションでは、1 ~ 30 日の範囲で指定できます。

この属性は、AD_CALL または WEBSITE_CALL コンバージョン アクションには設定できません。値を指定すると、VALUE_MUST_BE_UNSET エラーが発生します。