Google Ads API is returning to beta status. Please read our blog post for more details.

Create a Smart Display Campaign

Campaign budget

You can use an existing campaign budget or create a new one:

PHP

private static function createCampaignBudget(
    GoogleAdsClient $googleAdsClient,
    int $customerId
) {
    // Creates a campaign budget.
    $campaignBudget = new CampaignBudget([
        'name' => new StringValue(['value' => 'Interplanetary Cruise Budget #' . uniqid()]),
        'delivery_method' => BudgetDeliveryMethod::STANDARD,
        'amount_micros' => new Int64Value(['value' => 5000000])
    ]);

    // Creates a campaign budget operation.
    $campaignBudgetOperation = new CampaignBudgetOperation();
    $campaignBudgetOperation->setCreate($campaignBudget);

    // Issues a mutate request to add campaign budgets.
    $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient();
    /** @var MutateCampaignBudgetsResponse $campaignBudgetResponse */
    $campaignBudgetResponse = $campaignBudgetServiceClient->mutateCampaignBudgets(
        $customerId,
        [$campaignBudgetOperation]
    );

    // Prints out some information about the created campaign budget.
    $campaignBudgetResourceName = $campaignBudgetResponse->getResults()[0]->getResourceName();
    printf("Added budget named '%s'.%s", $campaignBudgetResourceName, PHP_EOL);

    return $campaignBudgetResourceName;
}

Smart Display Campaign

To create a Smart Display campaign, follow the steps in our code example with these specifics:

  1. Set the advertising_channel_type to DISPLAY.

  2. Set the advertising_channel_sub_type to DISPLAY_SMART_CAMPAIGN.

  3. Set the target_cpa field to a newly created TargetCpa object. Target CPA is the only allowed bidding strategy for this campaign type.

You can also set targeting options for smart display campaign, by following the Add Campaign Targeting Criteria code example. The only campaign-level targeting options allowed are:

PHP

private static function createSmartDisplayCampaign(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $campaignBudgetResourceName
) {
    $campaign = new Campaign([
        'name' => new StringValue(['value' => 'Smart Display Campaign #' . uniqid()]),
        // Smart Display campaign requires the advertising_channel_type as 'DISPLAY'.
        'advertising_channel_type' => AdvertisingChannelType::DISPLAY,
        // Smart Display campaign requires the advertising_channel_sub_type as
        // 'DISPLAY_SMART_CAMPAIGN'.
        'advertising_channel_sub_type' => AdvertisingChannelSubType::DISPLAY_SMART_CAMPAIGN,
        // Smart Display campaign requires the TargetCpa bidding strategy.
        'target_cpa' => new TargetCpa([
            'target_cpa_micros' => new Int64Value(['value' => 5000000])
        ]),
        'campaign_budget' => $campaignBudgetResourceName,
        // Optional: Sets the start and end dates for the campaign, beginning one day from
        // now and ending a month from now.
        'start_date' => new StringValue(['value' => date('Ymd', strtotime('+1 day'))]),
        'end_date' => new StringValue(['value' => date('Ymd', strtotime('+1 month'))])
    ]);

    // Creates a campaign operation.
    $campaignOperation = new CampaignOperation();
    $campaignOperation->setCreate($campaign);

    // Issues a mutate request to add the campaign.
    $campaignServiceClient = $googleAdsClient->getCampaignServiceClient();
    /** @var MutateCampaignsResponse $campaignResponse */
    $campaignResponse = $campaignServiceClient->mutateCampaigns(
        $customerId,
        [$campaignOperation]
    );

    $campaignResourceName = $campaignResponse->getResults()[0]->getResourceName();
    printf("Added a Smart Display campaign named '%s'.%s", $campaignResourceName, PHP_EOL);

    return $campaignResourceName;
}