Beispiel #1
0
        /// <summary>
        /// Creates the responsive display ad.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupResourceName">The ad group resource name to receive the ad.</param>
        private void CreateAd(GoogleAdsClient client, long customerId, string adGroupResourceName)
        {
            // Creates the ad group ad service client.
            AdGroupAdServiceClient adGroupAdServiceClient =
                client.GetService(Services.V6.AdGroupAdService);

            string marketingImageUrl          = "https://goo.gl/3b9Wfh";
            string marketingImageName         = "Marketing Image";
            string marketingImageResourceName =
                uploadAsset(client, customerId, marketingImageUrl, marketingImageName);
            string squareMarketingImageName         = "Square Marketing Image";
            string squareMarketingImageUrl          = "https://goo.gl/mtt54n";
            string squareMarketingImageResourceName =
                uploadAsset(client, customerId, squareMarketingImageUrl, squareMarketingImageName);

            // Creates the responsive display ad info object.
            ResponsiveDisplayAdInfo responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo()
            {
                MarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = marketingImageResourceName
                    }
                },
                SquareMarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = squareMarketingImageResourceName
                    }
                },
                Headlines =
                {
                    new AdTextAsset()
                    {
                        Text = "Travel"
                    }
                },
                LongHeadline = new AdTextAsset()
                {
                    Text = "Travel the World"
                },
                Descriptions =
                {
                    new AdTextAsset()
                    {
                        Text = "Take to the air!"
                    }
                },
                BusinessName = "Interplanetary Cruises",
                // Optional: Call to action text.
                // Valid texts: https://support.google.com/adwords/answer/7005917
                CallToActionText = "Apply Now",
                // Optional: Sets the ad colors.
                MainColor   = "#0000ff",
                AccentColor = "#ffff00",
                // Optional: Sets to false to strictly render the ad using the colors.
                AllowFlexibleColor = false,
                // Optional: Sets the format setting that the ad will be served in.
                FormatSetting = DisplayAdFormatSetting.NonNative,
                // Optional: Creates a logo image and sets it to the ad.

                /*
                 *  LogoImages = { new AdImageAsset()
                 *  {
                 *      Asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
                 *  }}
                 */
                // Optional: Creates a square logo image and sets it to the ad.

                /*
                 *  SquareLogoImages = { new AdImageAsset()
                 *  {
                 *      Asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
                 *  }}
                 */
            };

            // Creates the ad.
            Ad ad = new Ad()
            {
                ResponsiveDisplayAd = responsiveDisplayAdInfo,
                FinalUrls           = { "http://www.example.com/" }
            };

            // Creates the ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                Ad      = ad
            };

            // Creates the ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Adds the ad group ad.
            MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds
                                                    (customerId.ToString(), new[] { operation });

            Console.WriteLine("Created ad group ad with resource name " +
                              $"'{response.Results.First().ResourceName}'.");
        }
Beispiel #2
0
        /// <summary>
        /// Creates the responsive display ad.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupResourceName">The ad group resource name.</param>
        /// <param name="marketingImageAssetResourceName">The marketing image asset resource
        /// name.</param>
        /// <param name="squareMarketingImageAssetResourceName">The square marketing image asset
        /// resource name.</param>
        /// <returns>Resource name of the newly created ad.</returns>
        private static string CreateResponsiveDisplayAd(GoogleAdsClient client, long customerId,
                                                        string adGroupResourceName, string marketingImageAssetResourceName,
                                                        string squareMarketingImageAssetResourceName)
        {
            // Get the AdGroupAdServiceClient.
            AdGroupAdServiceClient adGroupAdService =
                client.GetService(Services.V3.AdGroupAdService);

            // Creates a responsive display ad info.
            ResponsiveDisplayAdInfo responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo()
            {
                // Sets some basic required information for the responsive display ad.
                Headlines = { new AdTextAsset()
                              {
                                  Text = "Travel"
                              } },
                LongHeadline = new AdTextAsset()
                {
                    Text = "Travel the World"
                },
                Descriptions = { new AdTextAsset()
                                 {
                                     Text = "Take to the air!"
                                 } },
                BusinessName = "Google",

                // Sets the marketing image and square marketing image to the previously created
                // image assets.
                MarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = marketingImageAssetResourceName
                    }
                },
                SquareMarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = squareMarketingImageAssetResourceName
                    }
                },

                // Optional: Sets call to action text, price prefix and promotion text.
                CallToActionText = "Shop Now",
                PricePrefix      = "as low as",
                PromoText        = "Free shipping!"
            };

            // Creates an ad group ad with the created responsive display ad info.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Paused,
                Ad      = new Ad()
                {
                    FinalUrls           = { "https://www.example.com" },
                    ResponsiveDisplayAd = responsiveDisplayAdInfo
                }
            };

            // Creates an ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Issues a mutate request to add the ad.
            MutateAdGroupAdsResponse response =
                adGroupAdService.MutateAdGroupAds(customerId.ToString(), new[] { operation });

            string adGroupAdResourceName = response.Results.First().ResourceName;

            // Print out some information about the added ad group ad.
            Console.WriteLine($"Added ad group ad with resource name = '{adGroupAdResourceName}'.");

            return(adGroupAdResourceName);
        }