examples/AdWords/v201809/AdvancedOperations/AddDynamicSearchAdsCampaign.php
private static function createCampaign(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        Budget $budget
    ) {
        $campaignService = $adWordsServices->get($session, CampaignService::class);

        // Create campaign with some properties set.
        $campaign = new Campaign();
        $campaign->setName('Interplanetary Cruise #' . uniqid());
        $campaign->setAdvertisingChannelType(AdvertisingChannelType::SEARCH);

        // Recommendation: Set the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        $campaign->setStatus(CampaignStatus::PAUSED);

        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $biddingStrategyConfiguration->setBiddingStrategyType(
            BiddingStrategyType::MANUAL_CPC
        );
        $campaign->setBiddingStrategyConfiguration($biddingStrategyConfiguration);

        // Only the budgetId should be sent, all other fields will be ignored by
        // CampaignService.
        $campaignBudget = new Budget();
        $campaignBudget->setBudgetId($budget->getBudgetId());
        $campaign->setBudget($campaignBudget);

        // Required: Set the campaign's Dynamic Search Ads settings.
        $dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
        // Required: Set the domain name and language.
        $dynamicSearchAdsSetting->setDomainName('example.com');
        $dynamicSearchAdsSetting->setLanguageCode('en');

        // Set the campaign settings.
        $campaign->setSettings([$dynamicSearchAdsSetting]);

        // Optional: Set the start date.
        $campaign->setStartDate(date('Ymd', strtotime('+1 day')));
        // Optional: Set the end date.
        $campaign->setEndDate(date('Ymd', strtotime('+1 year')));

        // Create a campaign operation.
        $operation = new CampaignOperation();
        $operation->setOperand($campaign);
        $operation->setOperator(Operator::ADD);

        // Create the campaign on the server and print out some information.
        $result = $campaignService->mutate([$operation]);
        $campaign = $result->getValue()[0];
        printf(
            "Campaign with name '%s' and ID %d was added.\n",
            $campaign->getName(),
            $campaign->getId()
        );

        return $campaign;
    }
private static function createCampaign(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        Budget $budget
    ) {
        $campaignService = $adWordsServices->get($session, CampaignService::class);

        // Create campaign with some properties set.
        $campaign = new Campaign();
        $campaign->setName('Interplanetary Cruise #' . uniqid());
        $campaign->setAdvertisingChannelType(AdvertisingChannelType::SEARCH);

        // Recommendation: Set the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        $campaign->setStatus(CampaignStatus::PAUSED);

        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $biddingStrategyConfiguration->setBiddingStrategyType(
            BiddingStrategyType::MANUAL_CPC
        );
        $campaign->setBiddingStrategyConfiguration($biddingStrategyConfiguration);

        // Only the budgetId should be sent, all other fields will be ignored by
        // CampaignService.
        $campaignBudget = new Budget();
        $campaignBudget->setBudgetId($budget->getBudgetId());
        $campaign->setBudget($campaignBudget);

        // Required: Set the campaign's Dynamic Search Ads settings.
        $dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
        // Required: Set the domain name and language.
        $dynamicSearchAdsSetting->setDomainName('example.com');
        $dynamicSearchAdsSetting->setLanguageCode('en');

        // Set the campaign settings.
        $campaign->setSettings([$dynamicSearchAdsSetting]);

        // Optional: Set the start date.
        $campaign->setStartDate(date('Ymd', strtotime('+1 day')));
        // Optional: Set the end date.
        $campaign->setEndDate(date('Ymd', strtotime('+1 year')));

        // Create a campaign operation.
        $operation = new CampaignOperation();
        $operation->setOperand($campaign);
        $operation->setOperator(Operator::ADD);

        // Create the campaign on the server and print out some information.
        $result = $campaignService->mutate([$operation]);
        $campaign = $result->getValue()[0];
        printf(
            "Campaign with name '%s' and ID %d was added.\n",
            $campaign->getName(),
            $campaign->getId()
        );

        return $campaign;
    }
private static function createCampaign ( AdWordsServices $ adWordsServices , AdWordsSession $ session , Budget $ budget ) { $ campaignService = $ adWordsServices -> get ( $ session , CampaignService :: class ) ; // Create campaign with some properties set. $ campaign = new Campaign ( ) ; $ campaign -> setName ( 'Interplanetary Cruise #' . uniqid ( ) ) ; $ campaign -> setAdvertisingChannelType ( AdvertisingChannelType :: SEARCH ) ; // Recommendation: Set the campaign to PAUSED when creating it to prevent // the ads from immediately serving. Set to ENABLED once you've added // targeting and the ads are ready to serve. $ campaign -> setStatus ( CampaignStatus :: PAUSED ) ; $ biddingStrategyConfiguration = new BiddingStrategyConfiguration ( ) ; $ biddingStrategyConfiguration -> setBiddingStrategyType ( BiddingStrategyType :: MANUAL_CPC ) ; $ campaign -> setBiddingStrategyConfiguration ( $ biddingStrategyConfiguration ) ; // Only the budgetId should be sent, all other fields will be ignored by // CampaignService. $ campaignBudget = new Budget ( ) ; $ campaignBudget -> setBudgetId ( $ budget -> getBudgetId ( ) ) ; $ campaign -> setBudget ( $ campaignBudget ) ; // Required: Set the campaign's Dynamic Search Ads settings. $ dynamicSearchAdsSetting = new DynamicSearchAdsSetting ( ) ; // Required: Set the domain name and language. $ dynamicSearchAdsSetting -> setDomainName ( 'example.com' ) ; $ dynamicSearchAdsSetting -> setLanguageCode ( 'en' ) ; // Set the campaign settings. $ campaign -> setSettings ( [ $ dynamicSearchAdsSetting ] ) ; // Optional: Set the start date. $ campaign -> setStartDate ( date ( 'Ymd' , strtotime ( '+1 day' ) ) ) ; // Optional: Set the end date. $ campaign -> setEndDate ( date ( 'Ymd' , strtotime ( '+1 year' ) ) ) ; // Create a campaign operation. $ operation = new CampaignOperation ( ) ; $ operation -> setOperand ( $ campaign ) ; $ operation -> setOperator ( Operator :: ADD ) ; // Create the campaign on the server and print out some information. $ result = $ campaignService -> mutate ( [ $ operation ] ) ; $ campaign = $ result -> getValue ( ) [ 0 ] ; printf ( "Campaign with name '%s' and ID %d was added.\n" , $ campaign -> getName ( ) , $ campaign -> getId ( ) ) ; return $ campaign ; }
Creates the campaign.
Creates the campaign .