examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php
private static function createAd(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        AdGroup $adGroup
    ) {
        $adGroupAdService =
            $adWordsServices->get($session, AdGroupAdService::class);

        $responsiveDisplayAd = new ResponsiveDisplayAd();

        // This ad format does not allow the creation of an image using the
        // Image.data field. An image must first be created using the
        // MediaService and Image.mediaId must be populated when creating the
        // ad.
        $marketingImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/3b9Wfh'
        );
        $responsiveDisplayAd->setMarketingImage($marketingImage);

        $responsiveDisplayAd->setShortHeadline('Travel');
        $responsiveDisplayAd->setLongHeadline('Travel the World.');
        $responsiveDisplayAd->setDescription('Take to the air!');
        $responsiveDisplayAd->setBusinessName('Interplanetary Cruises');
        $responsiveDisplayAd->setFinalUrls(['http://www.example.com']);

        // Optional: Set the call-to-action text.
        // Valid texts: https://support.google.com/adwords/answer/7005917.
        $responsiveDisplayAd->setCallToActionText('Apply Now');

        // Optional: Set dynamic display ad settings, composed of landscape logo
        // image, promotion text, and price prefix.
        $dynamicDisplayAdSettings =
            self::createDynamicDisplayAdSettings($adWordsServices, $session);
        $responsiveDisplayAd->setDynamicDisplayAdSettings(
            $dynamicDisplayAdSettings
        );

        // Optional: Creates a square marketing image using MediaService, and
        // set it to the ad.
        $squareMarketingImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/mtt54n'
        );
        $responsiveDisplayAd->setSquareMarketingImage($squareMarketingImage);

        // Optional: Set the logo image.
        $logoImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/mtt54n'
        );
        $responsiveDisplayAd->setLogoImage($logoImage);

        // Whitelisted accounts only: Set color settings using hexadecimal
        // values. Set allowFlexibleColor to false if you want your ads to
        // render by always using your colors strictly.
        /*
        $responsiveDisplayAd->setMainColor('#0000ff');
        $responsiveDisplayAd->setAccentColor('#ffff00');
        $responsiveDisplayAd->setFlexibleColor(false);
        */

        // Whitelisted accounts only: Set the format setting that the ad will be
        // served in.
        /*
        $responsiveDisplayAd->setFormatSetting(
            \Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting::NON_NATIVE
        );
        */

        // Creates ad group ad.
        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroup->getId());
        $adGroupAd->setAd($responsiveDisplayAd);

        // Create an ad group ad operation.
        $adGroupAdOperation = new AdGroupAdOperation();
        $adGroupAdOperation->setOperand($adGroupAd);
        $adGroupAdOperation->setOperator(Operator::ADD);

        // Creates an ad group ad on the server.
        $adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
        $adGroupAd = $adGroupAdAddResult->getValue()[0];

        return $adGroupAd;
    }
private static function createAd(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        AdGroup $adGroup
    ) {
        $adGroupAdService =
            $adWordsServices->get($session, AdGroupAdService::class);

        $responsiveDisplayAd = new ResponsiveDisplayAd();

        // This ad format does not allow the creation of an image using the
        // Image.data field. An image must first be created using the
        // MediaService and Image.mediaId must be populated when creating the
        // ad.
        $marketingImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/3b9Wfh'
        );
        $responsiveDisplayAd->setMarketingImage($marketingImage);

        $responsiveDisplayAd->setShortHeadline('Travel');
        $responsiveDisplayAd->setLongHeadline('Travel the World.');
        $responsiveDisplayAd->setDescription('Take to the air!');
        $responsiveDisplayAd->setBusinessName('Interplanetary Cruises');
        $responsiveDisplayAd->setFinalUrls(['http://www.example.com']);

        // Optional: Set the call-to-action text.
        // Valid texts: https://support.google.com/adwords/answer/7005917.
        $responsiveDisplayAd->setCallToActionText('Apply Now');

        // Optional: Set dynamic display ad settings, composed of landscape logo
        // image, promotion text, and price prefix.
        $dynamicDisplayAdSettings =
            self::createDynamicDisplayAdSettings($adWordsServices, $session);
        $responsiveDisplayAd->setDynamicDisplayAdSettings(
            $dynamicDisplayAdSettings
        );

        // Optional: Creates a square marketing image using MediaService, and
        // set it to the ad.
        $squareMarketingImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/mtt54n'
        );
        $responsiveDisplayAd->setSquareMarketingImage($squareMarketingImage);

        // Optional: Set the logo image.
        $logoImage = self::uploadImage(
            $adWordsServices,
            $session,
            'https://goo.gl/mtt54n'
        );
        $responsiveDisplayAd->setLogoImage($logoImage);

        // Whitelisted accounts only: Set color settings using hexadecimal
        // values. Set allowFlexibleColor to false if you want your ads to
        // render by always using your colors strictly.
        /*
        $responsiveDisplayAd->setMainColor('#0000ff');
        $responsiveDisplayAd->setAccentColor('#ffff00');
        $responsiveDisplayAd->setFlexibleColor(false);
        */

        // Whitelisted accounts only: Set the format setting that the ad will be
        // served in.
        /*
        $responsiveDisplayAd->setFormatSetting(
            \Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting::NON_NATIVE
        );
        */

        // Creates ad group ad.
        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroup->getId());
        $adGroupAd->setAd($responsiveDisplayAd);

        // Create an ad group ad operation.
        $adGroupAdOperation = new AdGroupAdOperation();
        $adGroupAdOperation->setOperand($adGroupAd);
        $adGroupAdOperation->setOperator(Operator::ADD);

        // Creates an ad group ad on the server.
        $adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
        $adGroupAd = $adGroupAdAddResult->getValue()[0];

        return $adGroupAd;
    }
private static function createAd ( AdWordsServices $ adWordsServices , AdWordsSession $ session , AdGroup $ adGroup ) { $ adGroupAdService = $ adWordsServices -> get ( $ session , AdGroupAdService :: class ) ; $ responsiveDisplayAd = new ResponsiveDisplayAd ( ) ; // This ad format does not allow the creation of an image using the // Image.data field. An image must first be created using the // MediaService and Image.mediaId must be populated when creating the // ad. $ marketingImage = self :: uploadImage ( $ adWordsServices , $ session , 'https://goo.gl/3b9Wfh' ) ; $ responsiveDisplayAd -> setMarketingImage ( $ marketingImage ) ; $ responsiveDisplayAd -> setShortHeadline ( 'Travel' ) ; $ responsiveDisplayAd -> setLongHeadline ( 'Travel the World.' ) ; $ responsiveDisplayAd -> setDescription ( 'Take to the air!' ) ; $ responsiveDisplayAd -> setBusinessName ( 'Interplanetary Cruises' ) ; $ responsiveDisplayAd -> setFinalUrls ( [ 'http://www.example.com' ] ) ; // Optional: Set the call-to-action text. // Valid texts: https://support.google.com/adwords/answer/7005917. $ responsiveDisplayAd -> setCallToActionText ( 'Apply Now' ) ; // Optional: Set dynamic display ad settings, composed of landscape logo // image, promotion text, and price prefix. $ dynamicDisplayAdSettings = self :: createDynamicDisplayAdSettings ( $ adWordsServices , $ session ) ; $ responsiveDisplayAd -> setDynamicDisplayAdSettings ( $ dynamicDisplayAdSettings ) ; // Optional: Creates a square marketing image using MediaService, and // set it to the ad. $ squareMarketingImage = self :: uploadImage ( $ adWordsServices , $ session , 'https://goo.gl/mtt54n' ) ; $ responsiveDisplayAd -> setSquareMarketingImage ( $ squareMarketingImage ) ; // Optional: Set the logo image. $ logoImage = self :: uploadImage ( $ adWordsServices , $ session , 'https://goo.gl/mtt54n' ) ; $ responsiveDisplayAd -> setLogoImage ( $ logoImage ) ; // Whitelisted accounts only: Set color settings using hexadecimal // values. Set allowFlexibleColor to false if you want your ads to // render by always using your colors strictly. /*
        $responsiveDisplayAd->setMainColor('#0000ff');
        $responsiveDisplayAd->setAccentColor('#ffff00');
        $responsiveDisplayAd->setFlexibleColor(false);
        */ // Whitelisted accounts only: Set the format setting that the ad will be // served in. /*
        $responsiveDisplayAd->setFormatSetting(
            \Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting::NON_NATIVE
        );
        */ // Creates ad group ad. $ adGroupAd = new AdGroupAd ( ) ; $ adGroupAd -> setAdGroupId ( $ adGroup -> getId ( ) ) ; $ adGroupAd -> setAd ( $ responsiveDisplayAd ) ; // Create an ad group ad operation. $ adGroupAdOperation = new AdGroupAdOperation ( ) ; $ adGroupAdOperation -> setOperand ( $ adGroupAd ) ; $ adGroupAdOperation -> setOperator ( Operator :: ADD ) ; // Creates an ad group ad on the server. $ adGroupAdAddResult = $ adGroupAdService -> mutate ( [ $ adGroupAdOperation ] ) ; $ adGroupAd = $ adGroupAdAddResult -> getValue ( ) [ 0 ] ; return $ adGroupAd ; }
Creates an ad for serving dynamic content in a remarketing campaign.

@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param AdGroup $adGroup the ad group under wich to create the ad
@return AdGroupAd the created ad group ad
Creates an ad for serving dynamic content in a remarketing campaign .