examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php
private static function createAdsWithCustomizations(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $adGroupIds,
        $feedName
    ) {
        $adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
        $operations = [];

        // Create an expanded text ad that uses ad customization.
        $expandedTextAd = new ExpandedTextAd();
        $expandedTextAd->setHeadlinePart1(
            sprintf('Luxury Cruise to {=%s.Name}', $feedName)
        );
        $expandedTextAd->setHeadlinePart2(
            sprintf('Only {=%s.Price}', $feedName)
        );
        $expandedTextAd->setDescription(
            sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
        );
        $expandedTextAd->setFinalUrls(['http://www.example.com']);

        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroupIds[0]);
        $adGroupAd->setAd($expandedTextAd);

        $operation = new AdGroupAdOperation();
        $operation->setOperand($adGroupAd);
        $operation->setOperator(Operator::ADD);
        $operations[] = $operation;

        // Create another expanded text ad with the same properties as the first
        // one for another ad group.
        // This is done to prevent PHP SoapClient from making a reference
        // to this object in the generated XML payload, which is not recognized by
        // AdWords API.
        $expandedTextAd2 = new ExpandedTextAd();
        $expandedTextAd2->setHeadlinePart1(
            sprintf('Luxury Cruise to {=%s.Name}', $feedName)
        );
        $expandedTextAd2->setHeadlinePart2(
            sprintf('Only {=%s.Price}', $feedName)
        );
        $expandedTextAd2->setDescription(
            sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
        );
        $expandedTextAd2->setFinalUrls(['http://www.example.com']);

        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroupIds[1]);
        $adGroupAd->setAd($expandedTextAd2);

        $operation = new AdGroupAdOperation();
        $operation->setOperand($adGroupAd);
        $operation->setOperator(Operator::ADD);
        $operations[] = $operation;

        $result = $adGroupAdService->mutate($operations);

        foreach ($result->getValue() as $adGroupAd) {
            printf(
                "Expanded text ad with ID %d and status '%s' was added.\n",
                $adGroupAd->getAd()->getId(),
                $adGroupAd->getStatus()
            );
        }
    }
private static function createAdsWithCustomizations(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $adGroupIds,
        $feedName
    ) {
        $adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
        $operations = [];

        // Create an expanded text ad that uses ad customization.
        $expandedTextAd = new ExpandedTextAd();
        $expandedTextAd->setHeadlinePart1(
            sprintf('Luxury Cruise to {=%s.Name}', $feedName)
        );
        $expandedTextAd->setHeadlinePart2(
            sprintf('Only {=%s.Price}', $feedName)
        );
        $expandedTextAd->setDescription(
            sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
        );
        $expandedTextAd->setFinalUrls(['http://www.example.com']);

        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroupIds[0]);
        $adGroupAd->setAd($expandedTextAd);

        $operation = new AdGroupAdOperation();
        $operation->setOperand($adGroupAd);
        $operation->setOperator(Operator::ADD);
        $operations[] = $operation;

        // Create another expanded text ad with the same properties as the first
        // one for another ad group.
        // This is done to prevent PHP SoapClient from making a reference
        // to this object in the generated XML payload, which is not recognized by
        // AdWords API.
        $expandedTextAd2 = new ExpandedTextAd();
        $expandedTextAd2->setHeadlinePart1(
            sprintf('Luxury Cruise to {=%s.Name}', $feedName)
        );
        $expandedTextAd2->setHeadlinePart2(
            sprintf('Only {=%s.Price}', $feedName)
        );
        $expandedTextAd2->setDescription(
            sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
        );
        $expandedTextAd2->setFinalUrls(['http://www.example.com']);

        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroupIds[1]);
        $adGroupAd->setAd($expandedTextAd2);

        $operation = new AdGroupAdOperation();
        $operation->setOperand($adGroupAd);
        $operation->setOperator(Operator::ADD);
        $operations[] = $operation;

        $result = $adGroupAdService->mutate($operations);

        foreach ($result->getValue() as $adGroupAd) {
            printf(
                "Expanded text ad with ID %d and status '%s' was added.\n",
                $adGroupAd->getAd()->getId(),
                $adGroupAd->getStatus()
            );
        }
    }
private static function createAdsWithCustomizations ( AdWordsServices $ adWordsServices , AdWordsSession $ session , array $ adGroupIds , $ feedName ) { $ adGroupAdService = $ adWordsServices -> get ( $ session , AdGroupAdService :: class ) ; $ operations = [ ] ; // Create an expanded text ad that uses ad customization. $ expandedTextAd = new ExpandedTextAd ( ) ; $ expandedTextAd -> setHeadlinePart1 ( sprintf ( 'Luxury Cruise to {=%s.Name}' , $ feedName ) ) ; $ expandedTextAd -> setHeadlinePart2 ( sprintf ( 'Only {=%s.Price}' , $ feedName ) ) ; $ expandedTextAd -> setDescription ( sprintf ( 'Offer ends in {=countdown(%s.Date)}!' , $ feedName ) ) ; $ expandedTextAd -> setFinalUrls ( [ 'http://www.example.com' ] ) ; $ adGroupAd = new AdGroupAd ( ) ; $ adGroupAd -> setAdGroupId ( $ adGroupIds [ 0 ] ) ; $ adGroupAd -> setAd ( $ expandedTextAd ) ; $ operation = new AdGroupAdOperation ( ) ; $ operation -> setOperand ( $ adGroupAd ) ; $ operation -> setOperator ( Operator :: ADD ) ; $ operations [ ] = $ operation ; // Create another expanded text ad with the same properties as the first // one for another ad group. // This is done to prevent PHP SoapClient from making a reference // to this object in the generated XML payload, which is not recognized by // AdWords API. $ expandedTextAd2 = new ExpandedTextAd ( ) ; $ expandedTextAd2 -> setHeadlinePart1 ( sprintf ( 'Luxury Cruise to {=%s.Name}' , $ feedName ) ) ; $ expandedTextAd2 -> setHeadlinePart2 ( sprintf ( 'Only {=%s.Price}' , $ feedName ) ) ; $ expandedTextAd2 -> setDescription ( sprintf ( 'Offer ends in {=countdown(%s.Date)}!' , $ feedName ) ) ; $ expandedTextAd2 -> setFinalUrls ( [ 'http://www.example.com' ] ) ; $ adGroupAd = new AdGroupAd ( ) ; $ adGroupAd -> setAdGroupId ( $ adGroupIds [ 1 ] ) ; $ adGroupAd -> setAd ( $ expandedTextAd2 ) ; $ operation = new AdGroupAdOperation ( ) ; $ operation -> setOperand ( $ adGroupAd ) ; $ operation -> setOperator ( Operator :: ADD ) ; $ operations [ ] = $ operation ; $ result = $ adGroupAdService -> mutate ( $ operations ) ; foreach ( $ result -> getValue ( ) as $ adGroupAd ) { printf ( "Expanded text ad with ID %d and status '%s' was added.\n" , $ adGroupAd -> getAd ( ) -> getId ( ) , $ adGroupAd -> getStatus ( ) ) ; } }
Creates expanded text ads that use ad customizations for the specified
ad group IDs.

@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param int[] $adGroupIds the ad group IDs to add the ad customizer
@param string $feedName the name of feed to be created
Creates expanded text ads that use ad customizations for the specified ad group IDs .