一般的な入稿タスク

このページでは、DCM/DFA Reporting and Tracking API を使用して一般的な入稿作業を行う方法について説明します。

コーディングに関する一般的なヒント

  • 必須およびオプションのプロパティとパラメータ - API 呼び出しに必須のプロパティまたはパラメータについては、リファレンス ドキュメントをご覧ください。
  • ワイルドカードによる名前の検索 - ワイルドカードとしてアスタリスク(*)を使用して、オブジェクトの名前を検索できます。アスタリスクは 0 個以上の任意の文字に一致します。API は暗黙的な部分文字列検索もサポートしているため、「abc」を検索すると暗黙的に「*abc*」が検索されます。
  • 更新とパッチの違い - 既存のオブジェクトを変更するには、次の 2 つの方法があります。
    1. 更新 - オブジェクトを更新すると、挿入時にすべてのフィールドが上書きされます。更新するオブジェクトを読み込み、そのオブジェクトに変更を加えることが重要です。それ以外の場合、更新リクエストに存在しないフィールドは設定されません。
    2. パッチ - パッチの場合、挿入時に指定したフィールドのみが上書きされます。この場合は、新しいオブジェクトを作成して更新するオブジェクトと同じ ID を割り当て、更新するフィールドを設定して、パッチ リクエストを実行します。
  • サイズ - 物理的サイズは、sizes サービスで定義される Size オブジェクトで表します。アカウントには標準サイズのセットが用意されており、このリストに独自のカスタムサイズを追加できます。
  • 日付と時刻 - 日付と時刻は、ローカル タイムゾーンを使用して RFC 3339 形式で保存できます。API から返される値はすべて UTC です。これは、設定したタイムゾーン(デフォルトではアメリカ/ニューヨーク時間)で日付と時刻が表示されるウェブサイトとは異なります。

広告主を作成する

C#

  1. Advertiser オブジェクトを作成し、必須の name プロパティと status プロパティを設定します。
    // Create the advertiser structure.
    Advertiser advertiser = new Advertiser();
    advertiser.Name = advertiserName;
    advertiser.Status = "APPROVED";
    
  2. advertisers.insert() を呼び出して広告主を保存します。
    // Create the advertiser.
    Advertiser result = service.Advertisers.Insert(advertiser, profileId).Execute();
    

Java

  1. Advertiser オブジェクトを作成し、必須の name プロパティと status プロパティを設定します。
    // Create the advertiser structure.
    Advertiser advertiser = new Advertiser();
    advertiser.setName(advertiserName);
    advertiser.setStatus("APPROVED");
    
  2. advertisers.insert() を呼び出して広告主を保存します。
    // Create the advertiser.
    Advertiser result = reporting.advertisers().insert(profileId, advertiser).execute();
    

PHP

  1. Advertiser オブジェクトを作成し、必須の name プロパティと status プロパティを設定します。
    $advertiser = new Google_Service_Dfareporting_Advertiser();
    $advertiser->setName($values['advertiser_name']);
    $advertiser->setStatus('APPROVED');
    
  2. advertisers.insert() を呼び出して広告主を保存します。
    $result = $this->service->advertisers->insert(
        $values['user_profile_id'],
        $advertiser
    );
    

Python

  1. Advertiser オブジェクトを作成し、必須の name プロパティと status プロパティを設定します。
    # Construct and save advertiser.
    advertiser = {
        'name': 'Test Advertiser',
        'status': 'APPROVED'
    }
    
  2. advertisers.insert() を呼び出して広告主を保存します。
    request = service.advertisers().insert(
        profileId=profile_id, body=advertiser)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. Advertiser オブジェクトを作成し、必須の name プロパティと status プロパティを設定します。
    # Create a new advertiser resource to insert.
    advertiser = DfareportingUtils::API_NAMESPACE::Advertiser.new(
      name: format('Example Advertiser #%s', SecureRandom.hex(3)),
      status: 'APPROVED'
    )
    
  2. advertisers.insert() を呼び出して広告主を保存します。
    # Insert the advertiser.
    result = service.insert_advertiser(profile_id, advertiser)
    

キャンペーンを作成する

C#

  1. Campaign オブジェクトを作成し、次の必須プロパティを設定します。

    • advertiserId - このキャンペーンを関連付ける広告主。
    • name - この広告主のすべてのキャンペーンで一意である必要があります。
    • defaultLandingPageId - このキャンペーンに広告が割り当てられていない場合、ユーザーが広告をクリックしたときに表示されるランディング ページ。既存のランディング ページを検索するには、advertiserLandingPages.list を呼び出します。新しいランディング ページを作成するには、advertiserLandingPages.insert を呼び出します。
    • 開始日終了日 - 将来の日付を指定する必要があります。日付は日単位で正確に指定できます。詳しくは、一般的なコーディング情報の日付と時刻の項目をご覧ください。個々の広告の日付は終了日を過ぎることがあり、キャンペーンの終了日までに契約が満たされていない場合に、パブリッシャーは指定された数のアクションについて契約の履行を試みることができます。
    // Locate an advertiser landing page to use as a default.
    LandingPage defaultLandingPage = getAdvertiserLandingPage(service, profileId, advertiserId);
    
    // Create the campaign structure.
    Campaign campaign = new Campaign();
    campaign.Name = campaignName;
    campaign.AdvertiserId = advertiserId;
    campaign.Archived = false;
    campaign.DefaultLandingPageId = defaultLandingPage.Id;
    
    // Set the campaign start date. This example uses today's date.
    campaign.StartDate =
        DfaReportingDateConverterUtil.convertToDateString(DateTime.Now);
    
    // Set the campaign end date. This example uses one month from today's date.
    campaign.EndDate =
        DfaReportingDateConverterUtil.convertToDateString(DateTime.Now.AddMonths(1));
    
  2. campaigns.insert() を呼び出してキャンペーンを保存します。

    // Insert the campaign.
    Campaign result = service.Campaigns.Insert(campaign, profileId).Execute();
    

Java

  1. Campaign オブジェクトを作成し、次の必須プロパティを設定します。

    • advertiserId - このキャンペーンを関連付ける広告主。
    • name - この広告主のすべてのキャンペーンで一意である必要があります。
    • defaultLandingPageId - このキャンペーンに広告が割り当てられていない場合、ユーザーが広告をクリックしたときに表示されるランディング ページ。既存のランディング ページを検索するには、advertiserLandingPages.list を呼び出します。新しいランディング ページを作成するには、advertiserLandingPages.insert を呼び出します。
    • 開始日終了日 - 将来の日付を指定する必要があります。日付は日単位で正確に指定できます。詳しくは、一般的なコーディング情報の日付と時刻の項目をご覧ください。個々の広告の日付は終了日を過ぎることがあり、キャンペーンの終了日までに契約が満たされていない場合に、パブリッシャーは指定された数のアクションについて契約の履行を試みることができます。
    // Locate an advertiser landing page to use as a default.
    LandingPage defaultLandingPage = getAdvertiserLandingPage(reporting, profileId, advertiserId);
    
    // Create the campaign structure.
    Campaign campaign = new Campaign();
    campaign.setName(campaignName);
    campaign.setAdvertiserId(advertiserId);
    campaign.setArchived(false);
    campaign.setDefaultLandingPageId(defaultLandingPage.getId());
    
    // Set the campaign start date. This example uses today's date.
    Calendar today = Calendar.getInstance();
    DateTime startDate = new DateTime(true, today.getTimeInMillis(), null);
    campaign.setStartDate(startDate);
    
    // Set the campaign end date. This example uses one month from today's date.
    Calendar nextMonth = Calendar.getInstance();
    nextMonth.add(Calendar.MONTH, 1);
    DateTime endDate = new DateTime(true, nextMonth.getTimeInMillis(), null);
    campaign.setEndDate(endDate);
    
  2. campaigns.insert() を呼び出してキャンペーンを保存します。

    // Insert the campaign.
    Campaign result = reporting.campaigns().insert(profileId, campaign).execute();
    

PHP

  1. Campaign オブジェクトを作成し、次の必須プロパティを設定します。

    • advertiserId - このキャンペーンを関連付ける広告主。
    • name - この広告主のすべてのキャンペーンで一意である必要があります。
    • defaultLandingPageId - このキャンペーンに広告が割り当てられていない場合、ユーザーが広告をクリックしたときに表示されるランディング ページ。既存のランディング ページを検索するには、advertiserLandingPages.list を呼び出します。新しいランディング ページを作成するには、advertiserLandingPages.insert を呼び出します。
    • 開始日終了日 - 将来の日付を指定する必要があります。日付は日単位で正確に指定できます。詳しくは、一般的なコーディング情報の日付と時刻の項目をご覧ください。個々の広告の日付は終了日を過ぎることがあり、キャンペーンの終了日までに契約が満たされていない場合に、パブリッシャーは指定された数のアクションについて契約の履行を試みることができます。
    $startDate = new DateTime('today');
    $endDate = new DateTime('+1 month');
    
    $campaign = new Google_Service_Dfareporting_Campaign();
    $campaign->setAdvertiserId($values['advertiser_id']);
    $campaign->setDefaultLandingPageId($values['default_landing_page_id']);
    $campaign->setName($values['campaign_name']);
    $campaign->setStartDate($startDate->format('Y-m-d'));
    $campaign->setEndDate($endDate->format('Y-m-d'));
    
  2. campaigns.insert() を呼び出してキャンペーンを保存します。

    $result = $this->service->campaigns->insert(
        $values['user_profile_id'],
        $campaign
    );
    

Python

  1. Campaign オブジェクトを作成し、次の必須プロパティを設定します。

    • advertiserId - このキャンペーンを関連付ける広告主。
    • name - この広告主のすべてのキャンペーンで一意である必要があります。
    • defaultLandingPageId - このキャンペーンに広告が割り当てられていない場合、ユーザーが広告をクリックしたときに表示されるランディング ページ。既存のランディング ページを検索するには、advertiserLandingPages.list を呼び出します。新しいランディング ページを作成するには、advertiserLandingPages.insert を呼び出します。
    • 開始日終了日 - 将来の日付を指定する必要があります。日付は日単位で正確に指定できます。詳しくは、一般的なコーディング情報の日付と時刻の項目をご覧ください。個々の広告の日付は終了日を過ぎることがあり、キャンペーンの終了日までに契約が満たされていない場合に、パブリッシャーは指定された数のアクションについて契約の履行を試みることができます。
    # Locate an advertiser landing page to use as a default.
    default_landing_page = get_advertiser_landing_page(service, profile_id,
                                                       advertiser_id)
    
    # Construct and save campaign.
    campaign = {
        'name': 'Test Campaign #%s' % uuid.uuid4(),
        'advertiserId': advertiser_id,
        'archived': 'false',
        'defaultLandingPageId': default_landing_page['id'],
        'startDate': '2015-01-01',
        'endDate': '2020-01-01'
    }
    
  2. campaigns.insert() を呼び出してキャンペーンを保存します。

    request = service.campaigns().insert(profileId=profile_id, body=campaign)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. Campaign オブジェクトを作成し、次の必須プロパティを設定します。

    • advertiserId - このキャンペーンを関連付ける広告主。
    • name - この広告主のすべてのキャンペーンで一意である必要があります。
    • defaultLandingPageId - このキャンペーンに広告が割り当てられていない場合、ユーザーが広告をクリックしたときに表示されるランディング ページ。既存のランディング ページを検索するには、advertiserLandingPages.list を呼び出します。新しいランディング ページを作成するには、advertiserLandingPages.insert を呼び出します。
    • 開始日終了日 - 将来の日付を指定する必要があります。日付は日単位で正確に指定できます。詳しくは、一般的なコーディング情報の日付と時刻の項目をご覧ください。個々の広告の日付は終了日を過ぎることがあり、キャンペーンの終了日までに契約が満たされていない場合に、パブリッシャーは指定された数のアクションについて契約の履行を試みることができます。
    # Locate an advertiser landing page to use as a default.
    default_landing_page = get_advertiser_landing_page(service, profile_id,
      advertiser_id)
    
    # Create a new campaign resource to insert.
    campaign = DfareportingUtils::API_NAMESPACE::Campaign.new(
      advertiser_id: advertiser_id,
      archived: false,
      default_landing_page_id: default_landing_page.id,
      name: format('Example Campaign #%s', SecureRandom.hex(3)),
      start_date: '2014-01-01',
      end_date: '2020-01-01'
    )
    
  2. campaigns.insert() を呼び出してキャンペーンを保存します。

    # Insert the campaign.
    result = service.insert_campaign(profile_id, campaign)
    

プレースメントを作成する

C#

  1. Placement オブジェクトを作成して、必要なプレースメント プロパティ(campaignIdsiteId など)を設定します。また、ウェブサイトと交渉したプレースメントについて、そのタイプとサイズを正確に設定してください。
    // Create the placement.
    Placement placement = new Placement();
    placement.Name = placementName;
    placement.CampaignId = campaignId;
    placement.Compatibility = "DISPLAY";
    placement.PaymentSource = "PLACEMENT_AGENCY_PAID";
    placement.SiteId = dfaSiteId;
    placement.TagFormats = new List<string>() { "PLACEMENT_TAG_STANDARD" };
    
    // Set the size of the placement.
    Size size = new Size();
    size.Id = sizeId;
    placement.Size = size;
    
  2. プレースメントに割り当てる新しい PricingSchedule オブジェクトを作成します。
    // Set the pricing schedule for the placement.
    PricingSchedule pricingSchedule = new PricingSchedule();
    pricingSchedule.EndDate = campaign.EndDate;
    pricingSchedule.PricingType = "PRICING_TYPE_CPM";
    pricingSchedule.StartDate = campaign.StartDate;
    placement.PricingSchedule = pricingSchedule;
    
  3. placements.insert() を呼び出して Placement オブジェクトを保存します。広告またはクリエイティブに割り当てる場合は、返された ID を必ず保管してください。
    // Insert the placement.
    Placement result = service.Placements.Insert(placement, profileId).Execute();
    

Java

  1. Placement オブジェクトを作成して、必要なプレースメント プロパティ(campaignIdsiteId など)を設定します。また、ウェブサイトと交渉したプレースメントについて、そのタイプとサイズを正確に設定してください。
    // Create the placement.
    Placement placement = new Placement();
    placement.setName(placementName);
    placement.setCampaignId(campaignId);
    placement.setCompatibility("DISPLAY");
    placement.setPaymentSource("PLACEMENT_AGENCY_PAID");
    placement.setSiteId(dfaSiteId);
    placement.setTagFormats(ImmutableList.of("PLACEMENT_TAG_STANDARD"));
    
    // Set the size of the placement.
    Size size = new Size();
    size.setId(sizeId);
    placement.setSize(size);
    
  2. プレースメントに割り当てる新しい PricingSchedule オブジェクトを作成します。
    // Set the pricing schedule for the placement.
    PricingSchedule pricingSchedule = new PricingSchedule();
    pricingSchedule.setEndDate(campaign.getEndDate());
    pricingSchedule.setPricingType("PRICING_TYPE_CPM");
    pricingSchedule.setStartDate(campaign.getStartDate());
    placement.setPricingSchedule(pricingSchedule);
    
  3. placements.insert() を呼び出して Placement オブジェクトを保存します。広告またはクリエイティブに割り当てる場合は、返された ID を必ず保管してください。
    // Insert the placement.
    Placement result = reporting.placements().insert(profileId, placement).execute();
    

PHP

  1. Placement オブジェクトを作成して、必要なプレースメント プロパティ(campaignIdsiteId など)を設定します。また、ウェブサイトと交渉したプレースメントについて、そのタイプとサイズを正確に設定してください。
    $placement = new Google_Service_Dfareporting_Placement();
    $placement->setCampaignId($values['campaign_id']);
    $placement->setCompatibility('DISPLAY');
    $placement->setName($values['placement_name']);
    $placement->setPaymentSource('PLACEMENT_AGENCY_PAID');
    $placement->setSiteId($values['site_id']);
    $placement->setTagFormats(['PLACEMENT_TAG_STANDARD']);
    
    // Set the size of the placement.
    $size = new Google_Service_Dfareporting_Size();
    $size->setId($values['size_id']);
    $placement->setSize($size);
    
  2. プレースメントに割り当てる新しい PricingSchedule オブジェクトを作成します。
    // Set the pricing schedule for the placement.
    $pricingSchedule = new Google_Service_Dfareporting_PricingSchedule();
    $pricingSchedule->setEndDate($campaign->getEndDate());
    $pricingSchedule->setPricingType('PRICING_TYPE_CPM');
    $pricingSchedule->setStartDate($campaign->getStartDate());
    $placement->setPricingSchedule($pricingSchedule);
    
  3. placements.insert() を呼び出して Placement オブジェクトを保存します。広告またはクリエイティブに割り当てる場合は、返された ID を必ず保管してください。
    // Insert the placement.
    $result = $this->service->placements->insert(
        $values['user_profile_id'],
        $placement
    );
    

Python

  1. Placement オブジェクトを作成して、必要なプレースメント プロパティ(campaignIdsiteId など)を設定します。また、ウェブサイトと交渉したプレースメントについて、そのタイプとサイズを正確に設定してください。
    # Construct and save placement.
    placement = {
        'name': 'Test Placement',
        'campaignId': campaign_id,
        'compatibility': 'DISPLAY',
        'siteId': site_id,
        'size': {
            'height': '1',
            'width': '1'
        },
        'paymentSource': 'PLACEMENT_AGENCY_PAID',
        'tagFormats': ['PLACEMENT_TAG_STANDARD']
    }
    
  2. プレースメントに割り当てる新しい PricingSchedule オブジェクトを作成します。
    # Set the pricing schedule for the placement.
    placement['pricingSchedule'] = {
        'startDate': campaign['startDate'],
        'endDate': campaign['endDate'],
        'pricingType': 'PRICING_TYPE_CPM'
    }
    
  3. placements.insert() を呼び出して Placement オブジェクトを保存します。広告またはクリエイティブに割り当てる場合は、返された ID を必ず保管してください。
    request = service.placements().insert(profileId=profile_id, body=placement)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. Placement オブジェクトを作成して、必要なプレースメント プロパティ(campaignIdsiteId など)を設定します。また、ウェブサイトと交渉したプレースメントについて、そのタイプとサイズを正確に設定してください。
    # Create a new placement resource to insert.
    placement = DfareportingUtils::API_NAMESPACE::Placement.new(
      campaign_id: campaign_id,
      compatibility: 'DISPLAY',
      name: 'Example Placement',
      payment_source: 'PLACEMENT_AGENCY_PAID',
      site_id: site_id,
      size: DfareportingUtils::API_NAMESPACE::Size.new(
        height: 1,
        width: 1
      ),
      tag_formats: ['PLACEMENT_TAG_STANDARD']
    )
    
  2. プレースメントに割り当てる新しい PricingSchedule オブジェクトを作成します。
    # Set the pricing schedule for the placement.
    placement.pricing_schedule =
      DfareportingUtils::API_NAMESPACE::PricingSchedule.new(
        end_date: campaign.end_date,
        pricing_type: 'PRICING_TYPE_CPM',
        start_date: campaign.start_date
      )
    
  3. placements.insert() を呼び出して Placement オブジェクトを保存します。広告またはクリエイティブに割り当てる場合は、返された ID を必ず保管してください。
    # Insert the placement strategy.
    result = service.insert_placement(profile_id, placement)
    

素材をアップロード

メディア アップロードと呼ばれるプロセスを使用して、さまざまな種類のアセットをアップロードできます。このプロセスはどのクリエイティブ タイプでもほぼ同じですが、タイプによっては、特定のプロパティを正しく使用するためにメタデータとして渡すことが必要になる場合があります。

C#

  1. assetIdentifier オブジェクトを作成し、必須プロパティを設定します。アセットの種類や使用方法に関係なく、すべてのアセットで assetIdentifier を指定する必要があります。アセットをクリエイティブに割り当てると、このオブジェクトを使用してアセットを参照します。次のプロパティは必須です。

    • name プロパティ。サーバー上のアセットの名前になります。名前には、.png、.gif などのファイル形式を示す拡張子を含める必要があります。ブラウザにはアセット名として公開されますが、元のファイル名と同じにする必要はありません。この名前は、サーバー上で名前が一意になるようにキャンペーン マネージャー 360 によって変更される場合があります。戻り値を調べて、名前が変更されていないかご確認ください。
    • type プロパティ。アセットのタイプを識別します。このプロパティによって、このアセットに関連付けることができるクリエイティブのタイプが決まります。
    // Create the creative asset ID and Metadata.
    CreativeAssetId assetId = new CreativeAssetId();
    assetId.Name = Path.GetFileName(assetFile);
    assetId.Type = assetType;
    
  2. creativeAssets.insert() を呼び出してファイルをアップロードします。マルチパート アップロードを実行し、同じリクエストの一部として assetIdentifier とファイル コンテンツの両方を渡します。正常に処理されると、CreativeAsset リソースと assetIdentifier が返されます。これを使用して、このアセットをクリエイティブに割り当てることができます。

    // Prepare an input stream.
    FileStream assetContent = new FileStream(assetFile, FileMode.Open, FileAccess.Read);
    
    
    CreativeAssetMetadata metaData = new CreativeAssetMetadata();
    metaData.AssetIdentifier = assetId;
    
    // Insert the creative.
    String mimeType = determineMimeType(assetFile, assetType);
    CreativeAssetsResource.InsertMediaUpload request =
        Service.CreativeAssets.Insert(metaData, ProfileId, AdvertiserId, assetContent, mimeType);
    
    IUploadProgress progress = request.Upload();
    if (UploadStatus.Failed.Equals(progress.Status)) {
        throw progress.Exception;
    }
    

Java

  1. assetIdentifier オブジェクトを作成し、必須プロパティを設定します。アセットの種類や使用方法に関係なく、すべてのアセットで assetIdentifier を指定する必要があります。アセットをクリエイティブに割り当てると、このオブジェクトを使用してアセットを参照します。次のプロパティは必須です。

    • name プロパティ。サーバー上のアセットの名前になります。名前には、.png、.gif などのファイル形式を示す拡張子を含める必要があります。ブラウザにはアセット名として公開されますが、元のファイル名と同じにする必要はありません。この名前は、サーバー上で名前が一意になるようにキャンペーン マネージャー 360 によって変更される場合があります。戻り値を調べて、名前が変更されていないかご確認ください。
    • type プロパティ。アセットのタイプを識別します。このプロパティによって、このアセットに関連付けることができるクリエイティブのタイプが決まります。
    // Create the creative asset ID and Metadata.
    CreativeAssetId assetId = new CreativeAssetId();
    assetId.setName(assetName);
    assetId.setType(assetType);
    
  2. creativeAssets.insert() を呼び出してファイルをアップロードします。マルチパート アップロードを実行し、同じリクエストの一部として assetIdentifier とファイル コンテンツの両方を渡します。正常に処理されると、CreativeAsset リソースと assetIdentifier が返されます。これを使用して、このアセットをクリエイティブに割り当てることができます。

    // Open the asset file.
    File file = new File(assetFile);
    
    // Prepare an input stream.
    String contentType = getMimeType(assetFile);
    InputStreamContent assetContent =
        new InputStreamContent(contentType, new BufferedInputStream(new FileInputStream(file)));
    assetContent.setLength(file.length());
    
    
    CreativeAssetMetadata metaData = new CreativeAssetMetadata();
    metaData.setAssetIdentifier(assetId);
    
    // Insert the creative.
    CreativeAssetMetadata result = reporting.creativeAssets()
        .insert(profileId, advertiserId, metaData, assetContent).execute();
    

PHP

  1. assetIdentifier オブジェクトを作成し、必須プロパティを設定します。アセットの種類や使用方法に関係なく、すべてのアセットで assetIdentifier を指定する必要があります。アセットをクリエイティブに割り当てると、このオブジェクトを使用してアセットを参照します。次のプロパティは必須です。

    • name プロパティ。サーバー上のアセットの名前になります。名前には、.png、.gif などのファイル形式を示す拡張子を含める必要があります。ブラウザにはアセット名として公開されますが、元のファイル名と同じにする必要はありません。この名前は、サーバー上で名前が一意になるようにキャンペーン マネージャー 360 によって変更される場合があります。戻り値を調べて、名前が変更されていないかご確認ください。
    • type プロパティ。アセットのタイプを識別します。このプロパティによって、このアセットに関連付けることができるクリエイティブのタイプが決まります。
    $assetId = new Google_Service_Dfareporting_CreativeAssetId();
    $assetId->setName($asset['name']);
    $assetId->setType($type);
    
  2. creativeAssets.insert() を呼び出してファイルをアップロードします。マルチパート アップロードを実行し、同じリクエストの一部として assetIdentifier とファイル コンテンツの両方を渡します。正常に処理されると、CreativeAsset リソースと assetIdentifier が返されます。これを使用して、このアセットをクリエイティブに割り当てることができます。

    $metadata = new Google_Service_Dfareporting_CreativeAssetMetadata();
    $metadata->setAssetIdentifier($assetId);
    
    $result = $service->creativeAssets->insert(
        $userProfileId,
        $advertiserId,
        $metadata,
        ['data' => file_get_contents($asset['tmp_name']),
         'mimeType' => $asset['type'],
         'uploadType' => 'multipart']
    );
    

Python

  1. assetIdentifier オブジェクトを作成し、必須プロパティを設定します。アセットの種類や使用方法に関係なく、すべてのアセットで assetIdentifier を指定する必要があります。アセットをクリエイティブに割り当てると、このオブジェクトを使用してアセットを参照します。次のプロパティは必須です。

    • name プロパティ。サーバー上のアセットの名前になります。名前には、.png、.gif などのファイル形式を示す拡張子を含める必要があります。ブラウザにはアセット名として公開されますが、元のファイル名と同じにする必要はありません。この名前は、サーバー上で名前が一意になるようにキャンペーン マネージャー 360 によって変更される場合があります。戻り値を調べて、名前が変更されていないかご確認ください。
    • type プロパティ。アセットのタイプを識別します。このプロパティによって、このアセットに関連付けることができるクリエイティブのタイプが決まります。
    # Construct the creative asset metadata
    creative_asset = {'assetIdentifier': {'name': asset_name, 'type': asset_type}}
    
  2. creativeAssets.insert() を呼び出してファイルをアップロードします。マルチパート アップロードを実行し、同じリクエストの一部として assetIdentifier とファイル コンテンツの両方を渡します。正常に処理されると、CreativeAsset リソースと assetIdentifier が返されます。これを使用して、このアセットをクリエイティブに割り当てることができます。

    media = MediaFileUpload(path_to_asset_file)
    if not media.mimetype():
      media = MediaFileUpload(path_to_asset_file, 'application/octet-stream')
    
    response = service.creativeAssets().insert(
        advertiserId=advertiser_id,
        profileId=profile_id,
        media_body=media,
        body=creative_asset).execute()
    

Ruby

  1. assetIdentifier オブジェクトを作成し、必須プロパティを設定します。アセットの種類や使用方法に関係なく、すべてのアセットで assetIdentifier を指定する必要があります。アセットをクリエイティブに割り当てると、このオブジェクトを使用してアセットを参照します。次のプロパティは必須です。

    • name プロパティ。サーバー上のアセットの名前になります。名前には、.png、.gif などのファイル形式を示す拡張子を含める必要があります。ブラウザにはアセット名として公開されますが、元のファイル名と同じにする必要はありません。この名前は、サーバー上で名前が一意になるようにキャンペーン マネージャー 360 によって変更される場合があります。戻り値を調べて、名前が変更されていないかご確認ください。
    • type プロパティ。アセットのタイプを識別します。このプロパティによって、このアセットに関連付けることができるクリエイティブのタイプが決まります。
    # Construct the creative asset metadata
    creative_asset = DfareportingUtils::API_NAMESPACE::CreativeAsset.new(
      asset_identifier: DfareportingUtils::API_NAMESPACE::CreativeAssetId.new(
        name: asset_name,
        type: asset_type
      )
    )
    
  2. creativeAssets.insert() を呼び出してファイルをアップロードします。マルチパート アップロードを実行し、同じリクエストの一部として assetIdentifier とファイル コンテンツの両方を渡します。正常に処理されると、CreativeAsset リソースと assetIdentifier が返されます。これを使用して、このアセットをクリエイティブに割り当てることができます。

    # Upload the asset.
    mime_type = determine_mime_type(path_to_asset_file, asset_type)
    
    result = @service.insert_creative_asset(
      @profile_id,
      advertiser_id,
      creative_asset,
      content_type: mime_type,
      upload_source: path_to_asset_file
    )
    

クリエイティブを作成する

Creative オブジェクトは、既存のアセットをラップします。ホストページでのクリエイティブの使用方法に応じて、さまざまなクリエイティブ タイプの Creative オブジェクトを作成できます。どちらのタイプが適切かについては、リファレンス ドキュメントをご覧ください。

次の例は、新しい HTML5 ディスプレイ クリエイティブを作成する方法を示しています。

C#

  1. アセットをアップロードします。クリエイティブによって必要なアセットの種類と数量が異なります。詳しくは、アセットをアップロードするをご覧ください。アセットが正常にアップロードされるたびに、レスポンスで assetIdenfitier が返されます。クリエイティブ内でこれらのアセットを参照するには、従来の ID ではなく、保存されているファイル名とタイプを使用します。
  2. クリエイティブを作成し、適切な値を割り当てます。Creative をインスタンス化し、適切な type を設定します。Creative オブジェクトを保存した後でその型を変更することはできません。AssetIdentifierrole でアセットを指定します。
    // Locate an advertiser landing page to use as a default.
    LandingPage defaultLandingPage = getAdvertiserLandingPage(service, profileId, advertiserId);
    
    // Create the creative structure.
    Creative creative = new Creative();
    creative.AdvertiserId = advertiserId;
    creative.Name = "Test HTML5 display creative";
    creative.Size = new Size() { Id = sizeId };
    creative.Type = "DISPLAY";
    
    // Upload the HTML5 asset.
    CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
    CreativeAssetId html5AssetId =
        assetUtils.uploadAsset(pathToHtml5AssetFile, "HTML").AssetIdentifier;
    
    CreativeAsset html5Asset = new CreativeAsset();
    html5Asset.AssetIdentifier = html5AssetId;
    html5Asset.Role = "PRIMARY";
    
    // Upload the backup image asset.
    CreativeAssetId imageAssetId =
        assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier;
    
    CreativeAsset imageAsset = new CreativeAsset();
    imageAsset.AssetIdentifier = imageAssetId;
    imageAsset.Role = "BACKUP_IMAGE";
    
    // Add the creative assets.
    creative.CreativeAssets = new List<CreativeAsset>() { html5Asset, imageAsset };
    
    // Configure the bacup image.
    creative.BackupImageClickThroughUrl = new CreativeClickThroughUrl() {
      LandingPageId = defaultLandingPage.Id
    };
    creative.BackupImageReportingLabel = "backup";
    creative.BackupImageTargetWindow = new TargetWindow() { TargetWindowOption = "NEW_WINDOW" };
    
    // Add a click tag.
    ClickTag clickTag = new ClickTag();
    clickTag.Name = "clickTag";
    clickTag.EventName = "exit";
    clickTag.ClickThroughUrl = new CreativeClickThroughUrl() {
      LandingPageId = defaultLandingPage.Id
    };
    creative.ClickTags = new List<ClickTag>() { clickTag };
    
  3. クリエイティブを保存します。これを行うには、creatives.insert() を呼び出します。このクリエイティブを関連付ける広告主 ID を指定する必要があります。
    Creative result = service.Creatives.Insert(creative, profileId).Execute();
    
  4. (省略可)クリエイティブをキャンペーンに関連付けます。そのためには、campaignCreativeAssociations.insert() を呼び出してキャンペーン ID とクリエイティブ ID を渡します。
    // Create the campaign creative association structure.
    CampaignCreativeAssociation association = new CampaignCreativeAssociation();
    association.CreativeId = creativeId;
    
    // Insert the association.
    CampaignCreativeAssociation result =
        service.CampaignCreativeAssociations.Insert(association, profileId, campaignId).Execute();
    

Java

  1. アセットをアップロードします。クリエイティブによって必要なアセットの種類と数量が異なります。詳しくは、アセットをアップロードするをご覧ください。アセットが正常にアップロードされるたびに、レスポンスで assetIdenfitier が返されます。クリエイティブ内でこれらのアセットを参照するには、従来の ID ではなく、保存されているファイル名とタイプを使用します。
  2. クリエイティブを作成し、適切な値を割り当てます。Creative をインスタンス化し、適切な type を設定します。Creative オブジェクトを保存した後でその型を変更することはできません。AssetIdentifierrole でアセットを指定します。
    // Locate an advertiser landing page to use as a default.
    LandingPage defaultLandingPage = getAdvertiserLandingPage(reporting, profileId, advertiserId);
    
    // Create the creative structure.
    Creative creative = new Creative();
    creative.setAdvertiserId(advertiserId);
    creative.setName("Test HTML5 display creative");
    creative.setSize(new Size().setId(sizeId));
    creative.setType("DISPLAY");
    
    // Upload the HTML5 asset.
    CreativeAssetId html5AssetId = CreativeAssetUtils.uploadAsset(reporting, profileId,
        advertiserId, HTML5_ASSET_NAME, PATH_TO_HTML5_ASSET_FILE, "HTML").getAssetIdentifier();
    
    CreativeAsset html5Asset =
        new CreativeAsset().setAssetIdentifier(html5AssetId).setRole("PRIMARY");
    
    // Upload the backup image asset (note: asset type must be set to HTML_IMAGE).
    CreativeAssetId imageAssetId = CreativeAssetUtils.uploadAsset(reporting, profileId,
        advertiserId, IMAGE_ASSET_NAME, PATH_TO_IMAGE_ASSET_FILE, "HTML_IMAGE")
        .getAssetIdentifier();
    
    CreativeAsset backupImageAsset =
        new CreativeAsset().setAssetIdentifier(imageAssetId).setRole("BACKUP_IMAGE");
    
    // Add the creative assets.
    creative.setCreativeAssets(ImmutableList.of(html5Asset, backupImageAsset));
    
    // Configure the backup image.
    creative.setBackupImageClickThroughUrl(
        new CreativeClickThroughUrl().setLandingPageId(defaultLandingPage.getId()));
    creative.setBackupImageReportingLabel("backup");
    creative.setBackupImageTargetWindow(new TargetWindow().setTargetWindowOption("NEW_WINDOW"));
    
    // Add a click tag.
    ClickTag clickTag =
        new ClickTag().setName("clickTag").setEventName("exit").setClickThroughUrl(
            new CreativeClickThroughUrl().setLandingPageId(defaultLandingPage.getId()));
    creative.setClickTags(ImmutableList.of(clickTag));
    
  3. クリエイティブを保存します。これを行うには、creatives.insert() を呼び出します。このクリエイティブを関連付ける広告主 ID を指定する必要があります。
    Creative result = reporting.creatives().insert(profileId, creative).execute();
    
  4. (省略可)クリエイティブをキャンペーンに関連付けます。そのためには、campaignCreativeAssociations.insert() を呼び出してキャンペーン ID とクリエイティブ ID を渡します。
    // Create the campaign creative association structure.
    CampaignCreativeAssociation association = new CampaignCreativeAssociation();
    association.setCreativeId(creativeId);
    
    // Insert the association.
    CampaignCreativeAssociation result = reporting
        .campaignCreativeAssociations().insert(profileId, campaignId, association)
        .execute();
    

PHP

  1. アセットをアップロードします。クリエイティブによって必要なアセットの種類と数量が異なります。詳しくは、アセットをアップロードするをご覧ください。アセットが正常にアップロードされるたびに、レスポンスで assetIdenfitier が返されます。クリエイティブ内でこれらのアセットを参照するには、従来の ID ではなく、保存されているファイル名とタイプを使用します。
  2. クリエイティブを作成し、適切な値を割り当てます。Creative をインスタンス化し、適切な type を設定します。Creative オブジェクトを保存した後でその型を変更することはできません。AssetIdentifierrole でアセットを指定します。
    $creative = new Google_Service_Dfareporting_Creative();
    $creative->setAdvertiserId($values['advertiser_id']);
    $creative->setAutoAdvanceImages(true);
    $creative->setName('Test HTML5 display creative');
    $creative->setType('DISPLAY');
    
    $size = new Google_Service_Dfareporting_Size();
    $size->setId($values['size_id']);
    $creative->setSize($size);
    
    // Upload the HTML5 asset.
    $html = uploadAsset(
        $this->service,
        $values['user_profile_id'],
        $values['advertiser_id'],
        $values['html_asset_file'],
        'HTML'
    );
    
    $htmlAsset = new Google_Service_Dfareporting_CreativeAsset();
    $htmlAsset->setAssetIdentifier($html->getAssetIdentifier());
    $htmlAsset->setRole('PRIMARY');
    
    // Upload the backup image asset.
    $image = uploadAsset(
        $this->service,
        $values['user_profile_id'],
        $values['advertiser_id'],
        $values['image_asset_file'],
        'HTML_IMAGE'
    );
    
    $imageAsset = new Google_Service_Dfareporting_CreativeAsset();
    $imageAsset->setAssetIdentifier($image->getAssetIdentifier());
    $imageAsset->setRole('BACKUP_IMAGE');
    
    // Add the creative assets.
    $creative->setCreativeAssets([$htmlAsset, $imageAsset]);
    
    // Configure the default click-through URL.
    $clickThroughUrl =
        new Google_Service_Dfareporting_CreativeClickThroughUrl();
    $clickThroughUrl->setLandingPageId($values['landing_page_id']);
    
    // Configure the backup image.
    $creative->setBackupImageClickThroughUrl($clickThroughUrl);
    $creative->setBackupImageReportingLabel('backup');
    
    $targetWindow = new Google_Service_Dfareporting_TargetWindow();
    $targetWindow->setTargetWindowOption('NEW_WINDOW');
    $creative->setBackupImageTargetWindow($targetWindow);
    
    // Add a click tag.
    $clickTag = new Google_Service_Dfareporting_ClickTag();
    $clickTag->setName('clickTag');
    $clickTag->setEventName('exit');
    $clickTag->setClickThroughUrl($clickThroughUrl);
    $creative->setClickTags([$clickTag]);
    
  3. クリエイティブを保存します。これを行うには、creatives.insert() を呼び出します。このクリエイティブを関連付ける広告主 ID を指定する必要があります。
    $result = $this->service->creatives->insert(
        $values['user_profile_id'],
        $creative
    );
    
  4. (省略可)クリエイティブをキャンペーンに関連付けます。そのためには、campaignCreativeAssociations.insert() を呼び出してキャンペーン ID とクリエイティブ ID を渡します。
    $association =
        new Google_Service_Dfareporting_CampaignCreativeAssociation();
    $association->setCreativeId($values['creative_id']);
    
    $result = $this->service->campaignCreativeAssociations->insert(
        $values['user_profile_id'],
        $values['campaign_id'],
        $association
    );
    

Python

  1. アセットをアップロードします。クリエイティブによって必要なアセットの種類と数量が異なります。詳しくは、アセットをアップロードするをご覧ください。アセットが正常にアップロードされるたびに、レスポンスで assetIdenfitier が返されます。クリエイティブ内でこれらのアセットを参照するには、従来の ID ではなく、保存されているファイル名とタイプを使用します。
  2. クリエイティブを作成し、適切な値を割り当てます。Creative をインスタンス化し、適切な type を設定します。Creative オブジェクトを保存した後でその型を変更することはできません。AssetIdentifierrole でアセットを指定します。
    # Locate an advertiser landing page to use as a default.
    default_landing_page = get_advertiser_landing_page(service, profile_id,
                                                       advertiser_id)
    
    # Upload the HTML5 asset
    html5_asset_id = upload_creative_asset(service, profile_id, advertiser_id,
                                           html5_asset_name,
                                           path_to_html5_asset_file, 'HTML')
    
    # Upload the backup image asset
    backup_image_asset_id = upload_creative_asset(
        service, profile_id, advertiser_id, backup_image_name,
        path_to_backup_image_file, 'HTML_IMAGE')
    
    # Construct the creative structure.
    creative = {
        'advertiserId': advertiser_id,
        'backupImageClickThroughUrl': {
            'landingPageId': default_landing_page['id']
        },
        'backupImageReportingLabel': 'backup_image_exit',
        'backupImageTargetWindow': {'targetWindowOption': 'NEW_WINDOW'},
        'clickTags': [{
            'eventName': 'exit',
            'name': 'click_tag',
            'clickThroughUrl': {'landingPageId': default_landing_page['id']}
        }],
        'creativeAssets': [
            {'assetIdentifier': html5_asset_id, 'role': 'PRIMARY'},
            {'assetIdentifier': backup_image_asset_id, 'role': 'BACKUP_IMAGE'}
        ],
        'name': 'Test HTML5 display creative',
        'size': {'id': size_id},
        'type': 'DISPLAY'
    }
    
  3. クリエイティブを保存します。これを行うには、creatives.insert() を呼び出します。このクリエイティブを関連付ける広告主 ID を指定する必要があります。
    request = service.creatives().insert(profileId=profile_id, body=creative)
    
    # Execute request and print response.
    response = request.execute()
    
  4. (省略可)クリエイティブをキャンペーンに関連付けます。そのためには、campaignCreativeAssociations.insert() を呼び出してキャンペーン ID とクリエイティブ ID を渡します。
    # Construct the request.
    association = {
        'creativeId': creative_id
    }
    
    request = service.campaignCreativeAssociations().insert(
        profileId=profile_id, campaignId=campaign_id, body=association)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. アセットをアップロードします。クリエイティブによって必要なアセットの種類と数量が異なります。詳しくは、アセットをアップロードするをご覧ください。アセットが正常にアップロードされるたびに、レスポンスで assetIdenfitier が返されます。クリエイティブ内でこれらのアセットを参照するには、従来の ID ではなく、保存されているファイル名とタイプを使用します。
  2. クリエイティブを作成し、適切な値を割り当てます。Creative をインスタンス化し、適切な type を設定します。Creative オブジェクトを保存した後でその型を変更することはできません。AssetIdentifierrole でアセットを指定します。
    # Locate an advertiser landing page to use as a default.
    default_landing_page = get_advertiser_landing_page(service, profile_id,
      advertiser_id)
    
    # Upload the HTML5 asset.
    html5_asset_id = util.upload_asset(advertiser_id, path_to_html5_asset_file,
      'HTML').asset_identifier
    
    # Upload the backup image asset.
    backup_image_asset_id = util.upload_asset(advertiser_id,
      path_to_backup_image_file, 'HTML_IMAGE').asset_identifier
    
    # Construct the creative structure.
    creative = DfareportingUtils::API_NAMESPACE::Creative.new(
      advertiser_id: advertiser_id,
      backup_image_click_through_url:
        DfareportingUtils::API_NAMESPACE::CreativeClickThroughUrl.new(
          landing_page_id: default_landing_page.id
        ),
      backup_image_reporting_label: 'backup',
      backup_image_target_window:
        DfareportingUtils::API_NAMESPACE::TargetWindow.new(
          target_window_option: 'NEW_WINDOW'
        ),
      click_tags: [
        DfareportingUtils::API_NAMESPACE::ClickTag.new(
          event_name: 'exit',
          name: 'click_tag',
          click_through_url:
            DfareportingUtils::API_NAMESPACE::CreativeClickThroughUrl.new(
              landing_page_id: default_landing_page.id
            )
        )
      ],
      creative_assets: [
        DfareportingUtils::API_NAMESPACE::CreativeAsset.new(
          asset_identifier: html5_asset_id,
          role: 'PRIMARY'
        ),
        DfareportingUtils::API_NAMESPACE::CreativeAsset.new(
          asset_identifier: backup_image_asset_id,
          role: 'BACKUP_IMAGE'
        )
      ],
      name: 'Example HTML5 display creative',
      size: DfareportingUtils::API_NAMESPACE::Size.new(id: size_id),
      type: 'DISPLAY'
    )
    
  3. クリエイティブを保存します。これを行うには、creatives.insert() を呼び出します。このクリエイティブを関連付ける広告主 ID を指定する必要があります。
    # Insert the creative.
    result = service.insert_creative(profile_id, creative)
    
  4. (省略可)クリエイティブをキャンペーンに関連付けます。そのためには、campaignCreativeAssociations.insert() を呼び出してキャンペーン ID とクリエイティブ ID を渡します。
    # Create a new creative-campaign association to insert
    association =
      DfareportingUtils::API_NAMESPACE::CampaignCreativeAssociation.new(
        creative_id: creative_id
      )
    
    # Insert the advertiser group.
    result = service.insert_campaign_creative_association(profile_id, campaign_id,
      association)
    

広告の作成

Ad は、CreativePlacement の間のリンクです。Ad は 1 つ以上のプレースメントにリンクでき、1 つ以上のクリエイティブを保持します。

Ad は、明示的または暗黙的に作成できます。

明示的

C#

  1. この広告を関連付けるクリエイティブごとに CreativeAssignment オブジェクトを作成します。CreativeAssignment.active フィールドは必ず true に設定してください。
    // Create a click-through URL.
    ClickThroughUrl clickThroughUrl = new ClickThroughUrl();
    clickThroughUrl.DefaultLandingPage = true;
    
    // Create a creative assignment.
    CreativeAssignment creativeAssignment = new CreativeAssignment();
    creativeAssignment.Active = true;
    creativeAssignment.CreativeId = creativeId;
    creativeAssignment.ClickThroughUrl = clickThroughUrl;
    
  2. CreativeAssignment を格納する CreativeRotation オブジェクトを作成します。ローテーション グループを作成する場合は、他の必須のクリエイティブ ローテーション フィールドを必ず設定します。
    // Create a creative rotation.
    CreativeRotation creativeRotation = new CreativeRotation();
    creativeRotation.CreativeAssignments = new List<CreativeAssignment>() {
        creativeAssignment
    };
    
  3. この広告を関連付けるプレースメントごとに PlacementAssignment オブジェクトを作成します。PlacementAssignment.active フィールドは必ず true に設定してください。
    // Create a placement assignment.
    PlacementAssignment placementAssignment = new PlacementAssignment();
    placementAssignment.Active = true;
    placementAssignment.PlacementId = placementId;
    
  4. Ad オブジェクトを作成します。creativeRotation を Ad オブジェクトの creativeRotation フィールドに設定し、placementAssignments を Ad オブジェクトの placementAssignments 配列に設定します。
    // Create a delivery schedule.
    DeliverySchedule deliverySchedule = new DeliverySchedule();
    deliverySchedule.ImpressionRatio = 1;
    deliverySchedule.Priority = "AD_PRIORITY_01";
    
    DateTime startDate = DateTime.Now;
    DateTime endDate = Convert.ToDateTime(campaign.EndDate);
    
    // Create a rotation group.
    Ad rotationGroup = new Ad();
    rotationGroup.Active = true;
    rotationGroup.CampaignId = campaignId;
    rotationGroup.CreativeRotation = creativeRotation;
    rotationGroup.DeliverySchedule = deliverySchedule;
    rotationGroup.StartTime = startDate;
    rotationGroup.EndTime = endDate;
    rotationGroup.Name = adName;
    rotationGroup.PlacementAssignments = new List<PlacementAssignment>() {
        placementAssignment
    };
    rotationGroup.Type = "AD_SERVING_STANDARD_AD";
    
  5. ads.insert() を呼び出して広告を保存します。
    // Insert the rotation group.
    Ad result = service.Ads.Insert(rotationGroup, profileId).Execute();
    

Java

  1. この広告を関連付けるクリエイティブごとに CreativeAssignment オブジェクトを作成します。CreativeAssignment.active フィールドは必ず true に設定してください。
    // Create a click-through URL.
    ClickThroughUrl clickThroughUrl = new ClickThroughUrl();
    clickThroughUrl.setDefaultLandingPage(true);
    
    // Create a creative assignment.
    CreativeAssignment creativeAssignment = new CreativeAssignment();
    creativeAssignment.setActive(true);
    creativeAssignment.setCreativeId(creativeId);
    creativeAssignment.setClickThroughUrl(clickThroughUrl);
    
  2. CreativeAssignment を格納する CreativeRotation オブジェクトを作成します。ローテーション グループを作成する場合は、他の必須のクリエイティブ ローテーション フィールドを必ず設定します。
    // Create a creative rotation.
    CreativeRotation creativeRotation = new CreativeRotation();
    creativeRotation.setCreativeAssignments(ImmutableList.of(creativeAssignment));
    
  3. この広告を関連付けるプレースメントごとに PlacementAssignment オブジェクトを作成します。PlacementAssignment.active フィールドは必ず true に設定してください。
    // Create a placement assignment.
    PlacementAssignment placementAssignment = new PlacementAssignment();
    placementAssignment.setActive(true);
    placementAssignment.setPlacementId(placementId);
    
  4. Ad オブジェクトを作成します。creativeRotation を Ad オブジェクトの creativeRotation フィールドに設定し、placementAssignments を Ad オブジェクトの placementAssignments 配列に設定します。
    // Create a delivery schedule.
    DeliverySchedule deliverySchedule = new DeliverySchedule();
    deliverySchedule.setImpressionRatio(1L);
    deliverySchedule.setPriority("AD_PRIORITY_01");
    
    DateTime startDate = new DateTime(new Date());
    DateTime endDate = new DateTime(campaign.getEndDate().getValue());
    
    // Create a rotation group.
    Ad rotationGroup = new Ad();
    rotationGroup.setActive(true);
    rotationGroup.setCampaignId(campaignId);
    rotationGroup.setCreativeRotation(creativeRotation);
    rotationGroup.setDeliverySchedule(deliverySchedule);
    rotationGroup.setStartTime(startDate);
    rotationGroup.setEndTime(endDate);
    rotationGroup.setName(adName);
    rotationGroup.setPlacementAssignments(ImmutableList.of(placementAssignment));
    rotationGroup.setType("AD_SERVING_STANDARD_AD");
    
  5. ads.insert() を呼び出して広告を保存します。
    // Insert the rotation group.
    Ad result = reporting.ads().insert(profileId, rotationGroup).execute();
    

PHP

  1. この広告を関連付けるクリエイティブごとに CreativeAssignment オブジェクトを作成します。CreativeAssignment.active フィールドは必ず true に設定してください。
    // Create a click-through URL.
    $url = new Google_Service_Dfareporting_ClickThroughUrl();
    $url->setDefaultLandingPage(true);
    
    // Create a creative assignment.
    $creativeAssignment =
        new Google_Service_Dfareporting_CreativeAssignment();
    $creativeAssignment->setActive(true);
    $creativeAssignment->setCreativeId($values['creative_id']);
    $creativeAssignment->setClickThroughUrl($url);
    
  2. CreativeAssignment を格納する CreativeRotation オブジェクトを作成します。ローテーション グループを作成する場合は、他の必須のクリエイティブ ローテーション フィールドを必ず設定します。
    // Create a creative rotation.
    $creativeRotation = new Google_Service_Dfareporting_CreativeRotation();
    $creativeRotation->setCreativeAssignments([$creativeAssignment]);
    
  3. この広告を関連付けるプレースメントごとに PlacementAssignment オブジェクトを作成します。PlacementAssignment.active フィールドは必ず true に設定してください。
    // Create a placement assignment.
    $placementAssignment =
        new Google_Service_Dfareporting_PlacementAssignment();
    $placementAssignment->setActive(true);
    $placementAssignment->setPlacementId($values['placement_id']);
    
  4. Ad オブジェクトを作成します。creativeRotation を Ad オブジェクトの creativeRotation フィールドに設定し、placementAssignments を Ad オブジェクトの placementAssignments 配列に設定します。
    // Create a delivery schedule.
    $deliverySchedule = new Google_Service_Dfareporting_DeliverySchedule();
    $deliverySchedule->setImpressionRatio(1);
    $deliverySchedule->SetPriority('AD_PRIORITY_01');
    
    $startDate = new DateTime('today');
    $endDate = new DateTime($campaign->getEndDate());
    
    // Create a rotation group.
    $ad = new Google_Service_Dfareporting_Ad();
    $ad->setActive(true);
    $ad->setCampaignId($values['campaign_id']);
    $ad->setCreativeRotation($creativeRotation);
    $ad->setDeliverySchedule($deliverySchedule);
    $ad->setStartTime($startDate->format('Y-m-d') . 'T23:59:59Z');
    $ad->setEndTime($endDate->format('Y-m-d') . 'T00:00:00Z');
    $ad->setName($values['ad_name']);
    $ad->setPlacementAssignments([$placementAssignment]);
    $ad->setType('AD_SERVING_STANDARD_AD');
    
  5. ads.insert() を呼び出して広告を保存します。
    $result = $this->service->ads->insert($values['user_profile_id'], $ad);
    

Python

  1. この広告を関連付けるクリエイティブごとに CreativeAssignment オブジェクトを作成します。CreativeAssignment.active フィールドは必ず true に設定してください。
    # Construct creative assignment.
    creative_assignment = {
        'active': 'true',
        'creativeId': creative_id,
        'clickThroughUrl': {
            'defaultLandingPage': 'true'
        }
    }
    
  2. CreativeAssignment を格納する CreativeRotation オブジェクトを作成します。ローテーション グループを作成する場合は、他の必須のクリエイティブ ローテーション フィールドを必ず設定します。
    # Construct creative rotation.
    creative_rotation = {
        'creativeAssignments': [creative_assignment],
        'type': 'CREATIVE_ROTATION_TYPE_RANDOM',
        'weightCalculationStrategy': 'WEIGHT_STRATEGY_OPTIMIZED'
    }
    
  3. この広告を関連付けるプレースメントごとに PlacementAssignment オブジェクトを作成します。PlacementAssignment.active フィールドは必ず true に設定してください。
    # Construct placement assignment.
    placement_assignment = {
        'active': 'true',
        'placementId': placement_id,
    }
    
  4. Ad オブジェクトを作成します。creativeRotation を Ad オブジェクトの creativeRotation フィールドに設定し、placementAssignments を Ad オブジェクトの placementAssignments 配列に設定します。
    # Construct delivery schedule.
    delivery_schedule = {
        'impressionRatio': '1',
        'priority': 'AD_PRIORITY_01'
    }
    
    # Construct and save ad.
    ad = {
        'active': 'true',
        'campaignId': campaign_id,
        'creativeRotation': creative_rotation,
        'deliverySchedule': delivery_schedule,
        'endTime': '%sT00:00:00Z' % campaign['endDate'],
        'name': 'Test Rotation Group',
        'placementAssignments': [placement_assignment],
        'startTime': '%sT23:59:59Z' % time.strftime('%Y-%m-%d'),
        'type': 'AD_SERVING_STANDARD_AD'
    }
    
  5. ads.insert() を呼び出して広告を保存します。
    request = service.ads().insert(profileId=profile_id, body=ad)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. この広告を関連付けるクリエイティブごとに CreativeAssignment オブジェクトを作成します。CreativeAssignment.active フィールドは必ず true に設定してください。
    # Construct creative assignment.
    creative_assignment =
      DfareportingUtils::API_NAMESPACE::CreativeAssignment.new(
        active: true,
        creative_id: creative_id,
        click_through_url: DfareportingUtils::API_NAMESPACE::ClickThroughUrl.new(
          default_landing_page: true
        )
      )
    
  2. CreativeAssignment を格納する CreativeRotation オブジェクトを作成します。ローテーション グループを作成する場合は、他の必須のクリエイティブ ローテーション フィールドを必ず設定します。
    # Construct creative rotation.
    creative_rotation = DfareportingUtils::API_NAMESPACE::CreativeRotation.new(
      creative_assignments: [creative_assignment],
      type: 'CREATIVE_ROTATION_TYPE_RANDOM',
      weight_calculation_strategy: 'WEIGHT_STRATEGY_OPTIMIZED'
    )
    
  3. この広告を関連付けるプレースメントごとに PlacementAssignment オブジェクトを作成します。PlacementAssignment.active フィールドは必ず true に設定してください。
    # Construct placement assignment.
    placement_assignment =
      DfareportingUtils::API_NAMESPACE::PlacementAssignment.new(
        active: true,
        placement_id: placement_id
      )
    
  4. Ad オブジェクトを作成します。creativeRotation を Ad オブジェクトの creativeRotation フィールドに設定し、placementAssignments を Ad オブジェクトの placementAssignments 配列に設定します。
    # Construct delivery schedule.
    delivery_schedule = DfareportingUtils::API_NAMESPACE::DeliverySchedule.new(
      impression_ratio: 1,
      priority: 'AD_PRIORITY_01'
    )
    
    # Construct and save ad.
    ad = DfareportingUtils::API_NAMESPACE::Ad.new(
      active: true,
      campaign_id: campaign_id,
      creative_rotation: creative_rotation,
      delivery_schedule: delivery_schedule,
      end_time: format('%sT00:00:00Z', campaign.end_date),
      name: 'Example Rotation Group',
      placement_assignments: [placement_assignment],
      start_time: format('%sT23:59:59Z', Time.now.strftime('%Y-%m-%d')),
      type: 'AD_SERVING_STANDARD_AD'
    )
    
  5. ads.insert() を呼び出して広告を保存します。
    result = service.insert_ad(profile_id, ad)
    

暗黙的に

C#

  1. Placement を作成して保存します。
  2. Creative を作成して保存します。
  3. campaignCreativeAssociations.insert() を呼び出して、CreativePlacement に使用するのと同じ Campaign に関連付けます(クリエイティブを作成するセクションの手順 4 をご覧ください)。これにより、クリエイティブとプレースメントの両方に関連付けられたデフォルト広告が作成されます。
    // Create the campaign creative association structure.
    CampaignCreativeAssociation association = new CampaignCreativeAssociation();
    association.CreativeId = creativeId;
    
    // Insert the association.
    CampaignCreativeAssociation result =
        service.CampaignCreativeAssociations.Insert(association, profileId, campaignId).Execute();
    

Java

  1. Placement を作成して保存します。
  2. Creative を作成して保存します。
  3. campaignCreativeAssociations.insert() を呼び出して、CreativePlacement に使用するのと同じ Campaign に関連付けます(クリエイティブを作成するセクションの手順 4 をご覧ください)。これにより、クリエイティブとプレースメントの両方に関連付けられたデフォルト広告が作成されます。
    // Create the campaign creative association structure.
    CampaignCreativeAssociation association = new CampaignCreativeAssociation();
    association.setCreativeId(creativeId);
    
    // Insert the association.
    CampaignCreativeAssociation result = reporting
        .campaignCreativeAssociations().insert(profileId, campaignId, association)
        .execute();
    

PHP

  1. Placement を作成して保存します。
  2. Creative を作成して保存します。
  3. campaignCreativeAssociations.insert() を呼び出して、CreativePlacement に使用するのと同じ Campaign に関連付けます(クリエイティブを作成するセクションの手順 4 をご覧ください)。これにより、クリエイティブとプレースメントの両方に関連付けられたデフォルト広告が作成されます。
    $association =
        new Google_Service_Dfareporting_CampaignCreativeAssociation();
    $association->setCreativeId($values['creative_id']);
    
    $result = $this->service->campaignCreativeAssociations->insert(
        $values['user_profile_id'],
        $values['campaign_id'],
        $association
    );
    

Python

  1. Placement を作成して保存します。
  2. Creative を作成して保存します。
  3. campaignCreativeAssociations.insert() を呼び出して、CreativePlacement に使用するのと同じ Campaign に関連付けます(クリエイティブを作成するセクションの手順 4 をご覧ください)。これにより、クリエイティブとプレースメントの両方に関連付けられたデフォルト広告が作成されます。
    # Construct the request.
    association = {
        'creativeId': creative_id
    }
    
    request = service.campaignCreativeAssociations().insert(
        profileId=profile_id, campaignId=campaign_id, body=association)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. Placement を作成して保存します。
  2. Creative を作成して保存します。
  3. campaignCreativeAssociations.insert() を呼び出して、CreativePlacement に使用するのと同じ Campaign に関連付けます(クリエイティブを作成するセクションの手順 4 をご覧ください)。これにより、クリエイティブとプレースメントの両方に関連付けられたデフォルト広告が作成されます。
    # Create a new creative-campaign association to insert
    association =
      DfareportingUtils::API_NAMESPACE::CampaignCreativeAssociation.new(
        creative_id: creative_id
      )
    
    # Insert the advertiser group.
    result = service.insert_campaign_creative_association(profile_id, campaign_id,
      association)
    

広告を暗黙的に作成することで、Ad を作成する手間を省くことができます。これを行うには、指定したサイズのデフォルト広告がキャンペーンにまだ存在しない必要があります。

オブジェクトを検索する

オブジェクトを検索するには、検索対象のオブジェクトを定義するサービスによって公開される list() オペレーションを呼び出し、そのオブジェクト タイプに適したオプションの条件を指定します。たとえば、Ad オブジェクトを検索するには、ads.list() を呼び出します。オプションの条件を使用すると、そのオブジェクトに適した一連のプロパティが公開されます。検索するプロパティはいくつでも指定できます。検索条件のすべてを満たすオブジェクトのみが返されます。任意の条件に一致する検索は実行できません。文字列はワイルドカード(*)をサポートしており、大文字と小文字は区別されません。また、より大きい文字列と一致します。

パフォーマンスを向上させるために、fields パラメータを使用して部分的なレスポンスをリクエストできます。これは、完全なリソース表現ではなく、指定したフィールドのみを返すようにサーバーに指示します。このトピックについて詳しくは、パフォーマンス向上のヒントをご覧ください。

Paging

list() リクエストのすべての結果を取得することは望ましくない場合があります。たとえば、数千ものプールの中から最新の 10 件の広告のみに関心があるような場合です。これを実現するため、多くの list() メソッドでは、ページングと呼ばれるプロセスを使用して、リクエストする結果の数を減らすことができます。

ページングをサポートするメソッドは、結果のサブセットを「ページ」と呼ばれるグループで返します。ページあたりの結果の最大数は 1,000 です(デフォルト)。maxResults を設定すると、1 ページあたりの結果数を変更できます。レスポンスで返される nextPageToken を使用して、ページを反復処理できます。

C#

// Limit the fields returned.
String fields = "nextPageToken,ads(advertiserId,id,name)";

AdsListResponse result;
String nextPageToken = null;

do {
  // Create and execute the ad list request.
  AdsResource.ListRequest request = service.Ads.List(profileId);
  request.Active = true;
  request.Fields = fields;
  request.PageToken = nextPageToken;
  result = request.Execute();

  foreach (Ad ad in result.Ads) {
    Console.WriteLine(
        "Ad with ID {0} and name \"{1}\" is associated with advertiser" +
        " ID {2}.", ad.Id, ad.Name, ad.AdvertiserId);
  }

  // Update the next page token.
  nextPageToken = result.NextPageToken;
} while (result.Ads.Any() && !String.IsNullOrEmpty(nextPageToken));

Java

// Limit the fields returned.
String fields = "nextPageToken,ads(advertiserId,id,name)";

AdsListResponse result;
String nextPageToken = null;

do {
  // Create and execute the ad list request.
  result = reporting.ads().list(profileId).setActive(true).setFields(fields)
      .setPageToken(nextPageToken).execute();

  for (Ad ad : result.getAds()) {
    System.out.printf(
        "Ad with ID %d and name \"%s\" is associated with advertiser ID %d.%n", ad.getId(),
        ad.getName(), ad.getAdvertiserId());
  }

  // Update the next page token.
  nextPageToken = result.getNextPageToken();
} while (!result.getAds().isEmpty() && !Strings.isNullOrEmpty(nextPageToken));

PHP

$response = null;
$pageToken = null;

do {
    // Create and execute the ads list request.
    $response = $this->service->ads->listAds(
        $values['user_profile_id'],
        ['active' => true, 'pageToken' => $pageToken]
    );

    foreach ($response->getAds() as $ads) {
        $this->printResultsTableRow($ads);
    }

    // Update the next page token.
    $pageToken = $response->getNextPageToken();
} while (!empty($response->getAds()) && !empty($pageToken));

Python

# Construct the request.
request = service.ads().list(profileId=profile_id, active=True)

while True:
  # Execute request and print response.
  response = request.execute()

  for ad in response['ads']:
    print 'Found ad with ID %s and name "%s".' % (ad['id'], ad['name'])

  if response['ads'] and response['nextPageToken']:
    request = service.ads().list_next(request, response)
  else:
    break

Ruby

token = nil
loop do
  result = service.list_ads(profile_id,
    page_token: token,
    fields: 'nextPageToken,ads(id,name)')

  # Display results.
  if result.ads.any?
    result.ads.each do |ad|
      puts format('Found ad with ID %d and name "%s".', ad.id, ad.name)
    end

    token = result.next_page_token
  else
    # Stop paging if there are no more results.
    token = nil
  end

  break if token.to_s.empty?
end

Floodlight タグを生成する

Floodlight タグは、ページに埋め込まれる HTML タグで、サイトでのユーザー アクション(購入など)のトラッキングに使用されます。Floodlight タグを生成するには、FloodlightActivityGroup に属する FloodlightActivity が必要です。

C#

  1. 新しい Floodlight アクティビティ グループを作成し、nametypefloodlightConfigurationId の値を渡します。
    // Create the floodlight activity group.
    FloodlightActivityGroup floodlightActivityGroup = new FloodlightActivityGroup();
    floodlightActivityGroup.Name = groupName;
    floodlightActivityGroup.FloodlightConfigurationId = floodlightConfigurationId;
    floodlightActivityGroup.Type = "COUNTER";
    
  2. floodlightActivityGroups.insert() を呼び出して Floodlight アクティビティ グループを保存します。これにより、新しいグループの ID が返されます。
    // Insert the activity group.
    FloodlightActivityGroup result =
        service.FloodlightActivityGroups.Insert(floodlightActivityGroup, profileId).Execute();
    
  3. 新しい Floodlight アクティビティを作成し、先ほど作成した Floodlight アクティビティ グループの ID を割り当て、その他の必須フィールドを割り当てます。
    // Set floodlight activity structure.
    FloodlightActivity activity = new FloodlightActivity();
    activity.CountingMethod = "STANDARD_COUNTING";
    activity.Name = activityName;
    activity.FloodlightActivityGroupId = activityGroupId;
    activity.FloodlightTagType = "GLOBAL_SITE_TAG";
    activity.ExpectedUrl = url;
    
  4. floodlightActivities.insert() を呼び出して新しいアクティビティを保存します。これにより、新しいアクティビティの ID が返されます。
    // Create the floodlight tag activity.
    FloodlightActivity result =
        service.FloodlightActivities.Insert(activity, profileId).Execute();
    
  5. 新しいアクティビティの floodlightActivityId を指定して floodlightActivities.generatetag() を呼び出し、タグを生成します。広告主のウェブサイトのウェブマスターにタグを送信します。
    // Generate the floodlight activity tag.
    FloodlightActivitiesResource.GeneratetagRequest request =
        service.FloodlightActivities.Generatetag(profileId);
    request.FloodlightActivityId = activityId;
    
    FloodlightActivitiesGenerateTagResponse response = request.Execute();
    

Java

  1. 新しい Floodlight アクティビティ グループを作成し、nametypefloodlightConfigurationId の値を渡します。
    // Create the floodlight activity group.
    FloodlightActivityGroup floodlightActivityGroup = new FloodlightActivityGroup();
    floodlightActivityGroup.setName(groupName);
    floodlightActivityGroup.setFloodlightConfigurationId(floodlightConfigurationId);
    floodlightActivityGroup.setType("COUNTER");
    
  2. floodlightActivityGroups.insert() を呼び出して Floodlight アクティビティ グループを保存します。これにより、新しいグループの ID が返されます。
    // Insert the activity group.
    FloodlightActivityGroup result =
        reporting.floodlightActivityGroups().insert(profileId, floodlightActivityGroup).execute();
    
  3. 新しい Floodlight アクティビティを作成し、先ほど作成した Floodlight アクティビティ グループの ID を割り当て、その他の必須フィールドを割り当てます。
    // Set floodlight activity structure.
    FloodlightActivity activity = new FloodlightActivity();
    activity.setName(activityName);
    activity.setCountingMethod("STANDARD_COUNTING");
    activity.setExpectedUrl(url);
    activity.setFloodlightActivityGroupId(activityGroupId);
    activity.setFloodlightTagType("GLOBAL_SITE_TAG");
    
  4. floodlightActivities.insert() を呼び出して新しいアクティビティを保存します。これにより、新しいアクティビティの ID が返されます。
    // Create the floodlight tag activity.
    FloodlightActivity result =
        reporting.floodlightActivities().insert(profileId, activity).execute();
    
  5. 新しいアクティビティの floodlightActivityId を指定して floodlightActivities.generatetag() を呼び出し、タグを生成します。広告主のウェブサイトのウェブマスターにタグを送信します。
    // Generate the floodlight activity tag.
    Generatetag request = reporting.floodlightActivities().generatetag(profileId);
    request.setFloodlightActivityId(activityId);
    
    FloodlightActivitiesGenerateTagResponse response = request.execute();
    

PHP

  1. 新しい Floodlight アクティビティ グループを作成し、nametypefloodlightConfigurationId の値を渡します。
    $group = new Google_Service_Dfareporting_FloodlightActivityGroup();
    $group->setFloodlightConfigurationId($values['configuration_id']);
    $group->setName($values['group_name']);
    $group->setType('COUNTER');
    
  2. floodlightActivityGroups.insert() を呼び出して Floodlight アクティビティ グループを保存します。これにより、新しいグループの ID が返されます。
    $result = $this->service->floodlightActivityGroups->insert(
        $values['user_profile_id'],
        $group
    );
    
  3. 新しい Floodlight アクティビティを作成し、先ほど作成した Floodlight アクティビティ グループの ID を割り当て、その他の必須フィールドを割り当てます。
    $activity = new Google_Service_Dfareporting_FloodlightActivity();
    $activity->setCountingMethod('STANDARD_COUNTING');
    $activity->setExpectedUrl($values['url']);
    $activity->setFloodlightActivityGroupId($values['activity_group_id']);
    $activity->setFloodlightTagType('GLOBAL_SITE_TAG');
    $activity->setName($values['activity_name']);
    
  4. floodlightActivities.insert() を呼び出して新しいアクティビティを保存します。これにより、新しいアクティビティの ID が返されます。
    $result = $this->service->floodlightActivities->insert(
        $values['user_profile_id'],
        $activity
    );
    
  5. 新しいアクティビティの floodlightActivityId を指定して floodlightActivities.generatetag() を呼び出し、タグを生成します。広告主のウェブサイトのウェブマスターにタグを送信します。
    $result = $this->service->floodlightActivities->generatetag(
        $values['user_profile_id'],
        ['floodlightActivityId' => $values['activity_id']]
    );
    

Python

  1. 新しい Floodlight アクティビティ グループを作成し、nametypefloodlightConfigurationId の値を渡します。
    # Construct and save floodlight activity group.
    activity_group = {
        'name': 'Test Floodlight Activity Group',
        'floodlightConfigurationId': floodlight_config_id,
        'type': 'COUNTER'
    }
    
  2. floodlightActivityGroups.insert() を呼び出して Floodlight アクティビティ グループを保存します。これにより、新しいグループの ID が返されます。
    request = service.floodlightActivityGroups().insert(
        profileId=profile_id, body=activity_group)
    
  3. 新しい Floodlight アクティビティを作成し、先ほど作成した Floodlight アクティビティ グループの ID を割り当て、その他の必須フィールドを割り当てます。
    # Construct and save floodlight activity.
    floodlight_activity = {
        'countingMethod': 'STANDARD_COUNTING',
        'expectedUrl': 'http://www.google.com',
        'floodlightActivityGroupId': activity_group_id,
        'floodlightTagType': 'GLOBAL_SITE_TAG',
        'name': 'Test Floodlight Activity'
    }
    
  4. floodlightActivities.insert() を呼び出して新しいアクティビティを保存します。これにより、新しいアクティビティの ID が返されます。
    request = service.floodlightActivities().insert(
        profileId=profile_id, body=floodlight_activity)
    
  5. 新しいアクティビティの floodlightActivityId を指定して floodlightActivities.generatetag() を呼び出し、タグを生成します。広告主のウェブサイトのウェブマスターにタグを送信します。
    # Construct the request.
    request = service.floodlightActivities().generatetag(
        profileId=profile_id, floodlightActivityId=activity_id)
    
    # Execute request and print response.
    response = request.execute()
    

Ruby

  1. 新しい Floodlight アクティビティ グループを作成し、nametypefloodlightConfigurationId の値を渡します。
    # Create a new floodlight activity group resource to insert.
    activity_group =
      DfareportingUtils::API_NAMESPACE::FloodlightActivityGroup.new(
        floodlight_configuration_id: floodlight_config_id,
        name:
          format('Example Floodlight Activity Group #%s', SecureRandom.hex(3)),
        type: 'COUNTER'
      )
    
  2. floodlightActivityGroups.insert() を呼び出して Floodlight アクティビティ グループを保存します。これにより、新しいグループの ID が返されます。
    # Insert the floodlight activity group.
    result = service.insert_floodlight_activity_group(profile_id, activity_group)
    
  3. 新しい Floodlight アクティビティを作成し、先ほど作成した Floodlight アクティビティ グループの ID を割り当て、その他の必須フィールドを割り当てます。
    # Create a new floodlight activity resource to insert.
    activity = DfareportingUtils::API_NAMESPACE::FloodlightActivity.new(
      counting_method: 'STANDARD_COUNTING',
      expected_url: 'http://www.google.com',
      floodlight_activity_group_id: activity_group_id,
      floodlight_tag_type: 'GLOBAL_SITE_TAG',
      name: format('Example Floodlight Activity #%s', SecureRandom.hex(3))
    )
    
  4. floodlightActivities.insert() を呼び出して新しいアクティビティを保存します。これにより、新しいアクティビティの ID が返されます。
    # Insert the floodlight activity.
    result = service.insert_floodlight_activity(profile_id, activity)
    
  5. 新しいアクティビティの floodlightActivityId を指定して floodlightActivities.generatetag() を呼び出し、タグを生成します。広告主のウェブサイトのウェブマスターにタグを送信します。
    # Construct the request.
    result = service.generatetag_floodlight_activity(profile_id,
      floodlight_activity_id: activity_id)
    

プレースメント タグを生成する

最後のステップでは、広告を表示するためにパブリッシャーに送信する HTML タグを生成します。API を使用してタグを生成するには、placementIdstagFormats のセットを指定して placements.generatetags() にリクエストを送信します。

C#

// Generate the placement activity tags.
PlacementsResource.GeneratetagsRequest request =
    service.Placements.Generatetags(profileId);
request.CampaignId = campaignId;
request.TagFormats =
    PlacementsResource.GeneratetagsRequest.TagFormatsEnum.PLACEMENTTAGIFRAMEJAVASCRIPT;
request.PlacementIds = placementId.ToString();

PlacementsGenerateTagsResponse response = request.Execute();

Java

// Generate the placement activity tags.
Generatetags request = reporting.placements().generatetags(profileId);
request.setCampaignId(campaignId);
request.setTagFormats(tagFormats);
request.setPlacementIds(ImmutableList.of(placementId));

PlacementsGenerateTagsResponse response = request.execute();

PHP

$placementTags = $this->service->placements->generatetags(
    $values['user_profile_id'],
    ['campaignId' => $values['campaign_id'],
     'placementIds' => [$values['placement_id']],
     'tagFormats' => ['PLACEMENT_TAG_STANDARD',
                      'PLACEMENT_TAG_IFRAME_JAVASCRIPT',
                      'PLACEMENT_TAG_INTERNAL_REDIRECT']
    ]
);

Python

# Construct the request.
request = service.placements().generatetags(
    profileId=profile_id, campaignId=campaign_id,
    placementIds=[placement_id])

# Execute request and print response.
response = request.execute()

Ruby

# Construct the request.
result = service.generate_placement_tags(profile_id,
  campaign_id: campaign_id,
  placement_ids: [placement_id])