/// <summary>Snippet for GetCampaignExtensionSettingAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignExtensionSettingRequestObjectAsync()
        {
            // Create client
            CampaignExtensionSettingServiceClient campaignExtensionSettingServiceClient = await CampaignExtensionSettingServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignExtensionSettingRequest request = new GetCampaignExtensionSettingRequest
            {
                ResourceNameAsCampaignExtensionSettingName = CampaignExtensionSettingName.FromCustomerCampaignExtensionType("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[EXTENSION_TYPE]"),
            };
            // Make the request
            CampaignExtensionSetting response = await campaignExtensionSettingServiceClient.GetCampaignExtensionSettingAsync(request);
        }
        /// <summary>
        /// Runs the code example.
        /// </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="campaignId">The campaign ID.</param>
        /// <param name="feedItemIds">The extension feed item IDs to replace.</param>
        // [START update_sitelink_campaign_extension_setting]
        public void Run(GoogleAdsClient client, long customerId, long campaignId,
                        long[] feedItemIds)
        {
            // Get the CampaignExtensionSettingService.
            CampaignExtensionSettingServiceClient campaignExtensionSettingService =
                client.GetService(Services.V10.CampaignExtensionSettingService);

            // Transform the specified extension feed item IDs to an array of resource names.
            IEnumerable <string> extensionFeedItems = feedItemIds.Select(feedItemId =>
                                                                         ResourceNames.ExtensionFeedItem(customerId, feedItemId));

            // Create a campaign extension setting using the specified campaign ID and extension
            // feed item resource names.
            CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting
            {
                ResourceName = ResourceNames.CampaignExtensionSetting(customerId, campaignId,
                                                                      ExtensionType.Sitelink)
            };

            campaignExtensionSetting.ExtensionFeedItems.Add(extensionFeedItems);

            // Construct an operation that will update the extension feed item using the FieldMasks
            // utilities to derive the update mask. This mask tells the Google Ads API which
            // attributes of the extension feed item you want to change.
            CampaignExtensionSettingOperation campaignExtensionSettingOperation =
                new CampaignExtensionSettingOperation
            {
                Update     = campaignExtensionSetting,
                UpdateMask = FieldMasks.AllSetFieldsOf(campaignExtensionSetting)
            };

            try
            {
                // Issue a mutate request to update the campaign extension setting.
                MutateCampaignExtensionSettingsResponse response =
                    campaignExtensionSettingService.MutateCampaignExtensionSettings
                        (customerId.ToString(), new[] { campaignExtensionSettingOperation });

                // Print the resource name of the updated campaign extension setting.
                Console.WriteLine("Updated a campaign extension setting with resource name " +
                                  $"'{response.Results.First().ResourceName}'.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Example #3
0
        /// <summary>Snippet for GetCampaignExtensionSettingAsync</summary>
        public async Task GetCampaignExtensionSettingAsync()
        {
            // Snippet: GetCampaignExtensionSettingAsync(string, CallSettings)
            // Additional: GetCampaignExtensionSettingAsync(string, CancellationToken)
            // Create client
            CampaignExtensionSettingServiceClient campaignExtensionSettingServiceClient = await CampaignExtensionSettingServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignExtensionSettings/[CAMPAIGN_EXTENSION_SETTING]";
            // Make the request
            CampaignExtensionSetting response = await campaignExtensionSettingServiceClient.GetCampaignExtensionSettingAsync(resourceName);

            // End snippet
        }
Example #4
0
 /// <summary>Snippet for GetCampaignExtensionSetting</summary>
 public void GetCampaignExtensionSettingRequestObject()
 {
     // Snippet: GetCampaignExtensionSetting(GetCampaignExtensionSettingRequest, CallSettings)
     // Create client
     CampaignExtensionSettingServiceClient campaignExtensionSettingServiceClient = CampaignExtensionSettingServiceClient.Create();
     // Initialize request argument(s)
     GetCampaignExtensionSettingRequest request = new GetCampaignExtensionSettingRequest
     {
         ResourceNameAsCampaignExtensionSettingName = CampaignExtensionSettingName.FromCustomerCampaignExtensionSetting("[CUSTOMER]", "[CAMPAIGN_EXTENSION_SETTING]"),
     };
     // Make the request
     CampaignExtensionSetting response = campaignExtensionSettingServiceClient.GetCampaignExtensionSetting(request);
     // End snippet
 }
        /// <summary>Snippet for GetCampaignExtensionSettingAsync</summary>
        public async Task GetCampaignExtensionSettingResourceNamesAsync()
        {
            // Snippet: GetCampaignExtensionSettingAsync(CampaignExtensionSettingName, CallSettings)
            // Additional: GetCampaignExtensionSettingAsync(CampaignExtensionSettingName, CancellationToken)
            // Create client
            CampaignExtensionSettingServiceClient campaignExtensionSettingServiceClient = await CampaignExtensionSettingServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignExtensionSettingName resourceName = CampaignExtensionSettingName.FromCustomerCampaignExtensionType("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[EXTENSION_TYPE]");
            // Make the request
            CampaignExtensionSetting response = await campaignExtensionSettingServiceClient.GetCampaignExtensionSettingAsync(resourceName);

            // End snippet
        }
Example #6
0
        /// <summary>
        /// Creates the extension setting fo a list of feed items.
        /// </summary>
        /// <param name="user">The user for which extension settings are created.
        /// </param>
        /// <param name="feedItems">The list of all feed items.</param>
        /// <param name="campaignId">ID of the campaign to which extension settings
        /// are added.</param>
        /// <param name="feedItemIds">IDs of the feed items for which extension
        /// settings should be created.</param>
        /// <param name="platformRestrictions">The platform restrictions for the
        /// extension setting.</param>
        private static void CreateExtensionSetting(AdWordsUser user, Dictionary <long,
                                                                                 SiteLinkFromFeed> feedItems, long campaignId, List <long> feedItemIds,
                                                   ExtensionSettingPlatform platformRestrictions)
        {
            CampaignExtensionSetting extensionSetting = new CampaignExtensionSetting()
            {
                campaignId       = campaignId,
                extensionType    = FeedType.SITELINK,
                extensionSetting = new ExtensionSetting()
                {
                }
            };

            List <ExtensionFeedItem> extensionFeedItems = new List <ExtensionFeedItem>();

            foreach (long feedItemId in feedItemIds)
            {
                SiteLinkFromFeed feedItem    = feedItems[feedItemId];
                SitelinkFeedItem newFeedItem = new SitelinkFeedItem()
                {
                    sitelinkText                = feedItem.Text,
                    sitelinkUrl                 = feedItem.Url,
                    sitelinkFinalUrls           = feedItem.FinalUrls,
                    sitelinkFinalMobileUrls     = feedItem.FinalMobileUrls,
                    sitelinkTrackingUrlTemplate = feedItem.TrackingUrlTemplate,
                    sitelinkLine2               = feedItem.Line2,
                    sitelinkLine3               = feedItem.Line3,
                    scheduling = feedItem.Scheduling
                };

                extensionFeedItems.Add(newFeedItem);
            }
            extensionSetting.extensionSetting.extensions           = extensionFeedItems.ToArray();
            extensionSetting.extensionSetting.platformRestrictions = platformRestrictions;
            extensionSetting.extensionType = FeedType.SITELINK;

            CampaignExtensionSettingService campaignExtensionSettingService =
                (CampaignExtensionSettingService)user.GetService(
                    AdWordsService.v201409.CampaignExtensionSettingService);
            CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation()
            {
                operand   = extensionSetting,
                @operator = Operator.ADD
            };

            campaignExtensionSettingService.mutate(new CampaignExtensionSettingOperation[] { operation });
            return;
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">ID of the campaign to which sitelinks are added.</param>
        /// <param name="imageAssetId">ID of the image asset to be used for creating the extension.
        /// </param>
        public void Run(GoogleAdsClient client, long customerId, long campaignId,
                        long imageAssetId)
        {
            // Get the CampaignExtensionSettingServiceClient.
            CampaignExtensionSettingServiceClient campaignExtensionSettingService =
                client.GetService(Services.V10.CampaignExtensionSettingService);

            try
            {
                // Creates an image extension.
                string imageExtensionResourceName =
                    CreateImageExtension(client, customerId, imageAssetId);
                string campaignResourceName = ResourceNames.Campaign(customerId, campaignId);

                // Creates a CampaignExtensionSetting.
                CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting()
                {
                    Campaign           = campaignResourceName,
                    ExtensionType      = ExtensionType.Image,
                    ExtensionFeedItems = { imageExtensionResourceName }
                };

                // Creates the operation.
                CampaignExtensionSettingOperation operation =
                    new CampaignExtensionSettingOperation()
                {
                    Create = campaignExtensionSetting
                };

                // Creates the campaign extension.
                MutateCampaignExtensionSettingsResponse response =
                    campaignExtensionSettingService.MutateCampaignExtensionSettings(
                        customerId.ToString(), new[] { operation });
                foreach (MutateCampaignExtensionSettingResult result in response.Results)
                {
                    Console.WriteLine($"Created campaign extension setting with resource " +
                                      $"name '{result.ResourceName}'.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Example #8
0
        /// <summary>Snippet for GetCampaignExtensionSettingAsync</summary>
        public async Task GetCampaignExtensionSettingRequestObjectAsync()
        {
            // Snippet: GetCampaignExtensionSettingAsync(GetCampaignExtensionSettingRequest, CallSettings)
            // Additional: GetCampaignExtensionSettingAsync(GetCampaignExtensionSettingRequest, CancellationToken)
            // Create client
            CampaignExtensionSettingServiceClient campaignExtensionSettingServiceClient = await CampaignExtensionSettingServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignExtensionSettingRequest request = new GetCampaignExtensionSettingRequest
            {
                ResourceNameAsCampaignExtensionSettingName = CampaignExtensionSettingName.FromCustomerCampaignExtensionSetting("[CUSTOMER]", "[CAMPAIGN_EXTENSION_SETTING]"),
            };
            // Make the request
            CampaignExtensionSetting response = await campaignExtensionSettingServiceClient.GetCampaignExtensionSettingAsync(request);

            // End snippet
        }
Example #9
0
        /// <summary>
        /// Updates Site Link Extension at Campaign Level
        /// </summary>
        /// <param name="user">Adwords User Object</param>
        /// <param name="sitelinkFeedItem">SiteLinkFeedItem containing Values to be update</param>
        /// <param name="campaignId">Campaign ID</param>
        /// <returns>Campaign Extension Setting Object with Updated Values</returns>
        public CampaignExtensionSetting UpdateSiteLinkAtCampaignLevel(AdWordsUser user, SitelinkFeedItem sitelinkFeedItem, long campaignId)
        {
            CampaignExtensionSettingService campaignExtensionSettingService = (CampaignExtensionSettingService)user.GetService(AdWordsService.v201809.CampaignExtensionSettingService);

            ExtensionFeedItem[] extensionFeedItems = new ExtensionFeedItem[] { sitelinkFeedItem };

            ExtensionSetting extensionSetting = new ExtensionSetting();

            extensionSetting.extensions = extensionFeedItems;

            CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();

            campaignExtensionSetting.campaignId       = campaignId;
            campaignExtensionSetting.extensionType    = FeedType.SITELINK;
            campaignExtensionSetting.extensionSetting = extensionSetting;

            CampaignExtensionSettingOperation campaignExtensionSettingOperation = new CampaignExtensionSettingOperation();

            campaignExtensionSettingOperation.operand   = campaignExtensionSetting;
            campaignExtensionSettingOperation.@operator = Operator.SET;

            try
            {
                // Add the extensions.
                CampaignExtensionSettingReturnValue campaignExtensionSettingReturnValue = campaignExtensionSettingService.mutate(new [] { campaignExtensionSettingOperation });
                if (campaignExtensionSettingReturnValue.value != null && campaignExtensionSettingReturnValue.value.Length > 0)
                {
                    CampaignExtensionSetting modifiedExtensionItem = campaignExtensionSettingReturnValue.value[0];
                    Logger.Log(Logger.LogType.INFO, "Modification Successful for Feed(ID): " + sitelinkFeedItem.feedId + " with FeedItem(ID): " + sitelinkFeedItem.feedItemId);
                    return(modifiedExtensionItem);
                }
                else
                {
                    Logger.Log(Logger.LogType.WARNING, "Nothing Modified for Feed(ID): " + sitelinkFeedItem.feedId + " with FeedItem(ID): " + sitelinkFeedItem.feedItemId);
                    return(null);
                }
            }
            catch (AdWordsApiException ex)
            {
                Logger.Log(Logger.LogType.EXCEPTION, Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException);
                return(null);
            }
        }
        public void GetCampaignExtensionSetting2()
        {
            Mock <CampaignExtensionSettingService.CampaignExtensionSettingServiceClient> mockGrpcClient = new Mock <CampaignExtensionSettingService.CampaignExtensionSettingServiceClient>(MockBehavior.Strict);
            GetCampaignExtensionSettingRequest request = new GetCampaignExtensionSettingRequest
            {
                ResourceName = new CampaignExtensionSettingName("[CUSTOMER]", "[CAMPAIGN_EXTENSION_SETTING]").ToString(),
            };
            CampaignExtensionSetting expectedResponse = new CampaignExtensionSetting
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignExtensionSetting(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            CampaignExtensionSettingServiceClient client = new CampaignExtensionSettingServiceClientImpl(mockGrpcClient.Object, null);
            CampaignExtensionSetting response            = client.GetCampaignExtensionSetting(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetCampaignExtensionSettingAsync()
        {
            Mock <CampaignExtensionSettingService.CampaignExtensionSettingServiceClient> mockGrpcClient = new Mock <CampaignExtensionSettingService.CampaignExtensionSettingServiceClient>(MockBehavior.Strict);
            GetCampaignExtensionSettingRequest expectedRequest = new GetCampaignExtensionSettingRequest
            {
                ResourceName = new CampaignExtensionSettingName("[CUSTOMER]", "[CAMPAIGN_EXTENSION_SETTING]").ToString(),
            };
            CampaignExtensionSetting expectedResponse = new CampaignExtensionSetting
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignExtensionSettingAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CampaignExtensionSetting>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignExtensionSettingServiceClient client = new CampaignExtensionSettingServiceClientImpl(mockGrpcClient.Object, null);
            string formattedResourceName      = new CampaignExtensionSettingName("[CUSTOMER]", "[CAMPAIGN_EXTENSION_SETTING]").ToString();
            CampaignExtensionSetting response = await client.GetCampaignExtensionSettingAsync(formattedResourceName);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which sitelinks will
        /// be added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignExtensionSettingService.
            CampaignExtensionSettingService campaignExtensionSettingService =
                (CampaignExtensionSettingService)user.GetService(
                    AdWordsService.v201601.CampaignExtensionSettingService);

            CustomerService customerService = (CustomerService)user.GetService(
                AdWordsService.v201601.CustomerService);
            Customer customer = customerService.get();

            List <ExtensionFeedItem> extensions = new List <ExtensionFeedItem>();

            // Create your sitelinks.
            SitelinkFeedItem sitelink1 = new SitelinkFeedItem()
            {
                sitelinkText      = "Store Hours",
                sitelinkFinalUrls = new string[] { "http://www.example.com/storehours" }
            };

            extensions.Add(sitelink1);

            DateTime startOfThanksGiving = new DateTime(DateTime.Now.Year, 11, 20, 0, 0, 0);
            DateTime endOfThanksGiving   = new DateTime(DateTime.Now.Year, 11, 27, 23, 59, 59);

            // Add check to make sure we don't create a sitelink with end date in the
            // past.
            if (DateTime.Now < endOfThanksGiving)
            {
                // Show the Thanksgiving specials link only from 20 - 27 Nov.
                SitelinkFeedItem sitelink2 = new SitelinkFeedItem()
                {
                    sitelinkText      = "Thanksgiving Specials",
                    sitelinkFinalUrls = new string[] { "http://www.example.com/thanksgiving" },
                    startTime         = string.Format("{0} {1}", startOfThanksGiving.ToString("yyyyMMdd HHmmss"),
                                                      customer.dateTimeZone),
                    endTime = string.Format("{0} {1}", endOfThanksGiving.ToString("yyyyMMdd HHmmss"),
                                            customer.dateTimeZone)
                };
                extensions.Add(sitelink2);
            }
            // Show the wifi details primarily for high end mobile users.
            SitelinkFeedItem sitelink3 = new SitelinkFeedItem()
            {
                sitelinkText      = "Wifi available",
                sitelinkFinalUrls = new string[] { "http://www.example.com/mobile/wifi" },
                devicePreference  = new FeedItemDevicePreference()
                {
                    // See https://developers.google.com/adwords/api/docs/appendix/platforms
                    // for device criteria IDs.
                    devicePreference = 30001
                }
            };

            extensions.Add(sitelink3);

            // Show the happy hours link only during Mon - Fri 6PM to 9PM.
            SitelinkFeedItem sitelink4 = new SitelinkFeedItem()
            {
                sitelinkText      = "Happy hours",
                sitelinkFinalUrls = new string[] { "http://www.example.com/happyhours" },
                scheduling        = new FeedItemSchedule[] {
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = DayOfWeek.MONDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = DayOfWeek.TUESDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = DayOfWeek.WEDNESDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = DayOfWeek.THURSDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = DayOfWeek.FRIDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    }
                }
            };

            extensions.Add(sitelink4);

            // Create your campaign extension settings. This associates the sitelinks
            // to your campaign.
            CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();

            campaignExtensionSetting.campaignId       = campaignId;
            campaignExtensionSetting.extensionType    = FeedType.SITELINK;
            campaignExtensionSetting.extensionSetting = new ExtensionSetting()
            {
                extensions = extensions.ToArray()
            };

            CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation()
            {
                operand   = campaignExtensionSetting,
                @operator = Operator.ADD
            };

            try {
                // Add the extensions.
                CampaignExtensionSettingReturnValue retVal = campaignExtensionSettingService.mutate(
                    new CampaignExtensionSettingOperation[] { operation });

                // Display the results.
                if (retVal.value != null && retVal.value.Length > 0)
                {
                    CampaignExtensionSetting newExtensionSetting = retVal.value[0];
                    Console.WriteLine("Extension setting with type = {0} was added to campaign ID {1}.",
                                      newExtensionSetting.extensionType, newExtensionSetting.campaignId);
                }
                else
                {
                    Console.WriteLine("No extension settings were created.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to create extension settings.", e);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which sitelinks will
        /// be added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            using (CampaignExtensionSettingService campaignExtensionSettingService =
                       (CampaignExtensionSettingService)user.GetService(
                           AdWordsService.v201802.CampaignExtensionSettingService)) {
                Customer customer = null;
                using (CustomerService customerService = (CustomerService)user.GetService(
                           AdWordsService.v201802.CustomerService)) {
                    // Find the matching customer and its time zone. The getCustomers method
                    // will return a single Customer object corresponding to the session's
                    // clientCustomerId.
                    customer = customerService.getCustomers()[0];
                    Console.WriteLine("Found customer ID {0:###-###-####} with time zone '{1}'.",
                                      customer.customerId, customer.dateTimeZone);
                }
                List <ExtensionFeedItem> extensions = new List <ExtensionFeedItem>();

                // Create your sitelinks.
                SitelinkFeedItem sitelink1 = new SitelinkFeedItem()
                {
                    sitelinkText      = "Store Hours",
                    sitelinkFinalUrls = new UrlList()
                    {
                        urls = new string[] { "http://www.example.com/storehours" }
                    }
                };
                extensions.Add(sitelink1);

                DateTime startOfThanksGiving = new DateTime(DateTime.Now.Year, 11, 20, 0, 0, 0);
                DateTime endOfThanksGiving   = new DateTime(DateTime.Now.Year, 11, 27, 23, 59, 59);

                // Add check to make sure we don't create a sitelink with end date in the
                // past.
                if (DateTime.Now < endOfThanksGiving)
                {
                    // Show the Thanksgiving specials link only from 20 - 27 Nov.
                    SitelinkFeedItem sitelink2 = new SitelinkFeedItem()
                    {
                        sitelinkText      = "Thanksgiving Specials",
                        sitelinkFinalUrls = new UrlList()
                        {
                            urls = new string[] { "http://www.example.com/thanksgiving" }
                        },
                        startTime = string.Format("{0} {1}", startOfThanksGiving.ToString("yyyyMMdd HHmmss"),
                                                  customer.dateTimeZone),
                        endTime = string.Format("{0} {1}", endOfThanksGiving.ToString("yyyyMMdd HHmmss"),
                                                customer.dateTimeZone),

                        // Target this sitelink for United States only. See
                        // https://developers.google.com/adwords/api/docs/appendix/geotargeting
                        // for valid geolocation codes.
                        geoTargeting = new Location()
                        {
                            id = 2840
                        },

                        // Restrict targeting only to people physically within the United States.
                        // Otherwise, this could also show to people interested in the United States
                        // but not physically located there.
                        geoTargetingRestriction = new FeedItemGeoRestriction()
                        {
                            geoRestriction = GeoRestriction.LOCATION_OF_PRESENCE
                        }
                    };
                    extensions.Add(sitelink2);
                }
                // Show the wifi details primarily for high end mobile users.
                SitelinkFeedItem sitelink3 = new SitelinkFeedItem()
                {
                    sitelinkText      = "Wifi available",
                    sitelinkFinalUrls = new UrlList()
                    {
                        urls = new string[] { "http://www.example.com/mobile/wifi" }
                    },
                    devicePreference = new FeedItemDevicePreference()
                    {
                        // See https://developers.google.com/adwords/api/docs/appendix/platforms
                        // for device criteria IDs.
                        devicePreference = 30001
                    },

                    // Target this sitelink for the keyword "free wifi".
                    keywordTargeting = new Keyword()
                    {
                        text      = "free wifi",
                        matchType = KeywordMatchType.BROAD
                    }
                };
                extensions.Add(sitelink3);

                // Show the happy hours link only during Mon - Fri 6PM to 9PM.
                SitelinkFeedItem sitelink4 = new SitelinkFeedItem()
                {
                    sitelinkText      = "Happy hours",
                    sitelinkFinalUrls = new UrlList()
                    {
                        urls = new string[] { "http://www.example.com/happyhours" },
                    },
                    scheduling = new FeedItemSchedule[] {
                        new FeedItemSchedule()
                        {
                            dayOfWeek   = DayOfWeek.MONDAY,
                            startHour   = 18,
                            startMinute = MinuteOfHour.ZERO,
                            endHour     = 21,
                            endMinute   = MinuteOfHour.ZERO
                        },
                        new FeedItemSchedule()
                        {
                            dayOfWeek   = DayOfWeek.TUESDAY,
                            startHour   = 18,
                            startMinute = MinuteOfHour.ZERO,
                            endHour     = 21,
                            endMinute   = MinuteOfHour.ZERO
                        },
                        new FeedItemSchedule()
                        {
                            dayOfWeek   = DayOfWeek.WEDNESDAY,
                            startHour   = 18,
                            startMinute = MinuteOfHour.ZERO,
                            endHour     = 21,
                            endMinute   = MinuteOfHour.ZERO
                        },
                        new FeedItemSchedule()
                        {
                            dayOfWeek   = DayOfWeek.THURSDAY,
                            startHour   = 18,
                            startMinute = MinuteOfHour.ZERO,
                            endHour     = 21,
                            endMinute   = MinuteOfHour.ZERO
                        },
                        new FeedItemSchedule()
                        {
                            dayOfWeek   = DayOfWeek.FRIDAY,
                            startHour   = 18,
                            startMinute = MinuteOfHour.ZERO,
                            endHour     = 21,
                            endMinute   = MinuteOfHour.ZERO
                        }
                    }
                };
                extensions.Add(sitelink4);

                // Create your campaign extension settings. This associates the sitelinks
                // to your campaign.
                CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();
                campaignExtensionSetting.campaignId       = campaignId;
                campaignExtensionSetting.extensionType    = FeedType.SITELINK;
                campaignExtensionSetting.extensionSetting = new ExtensionSetting()
                {
                    extensions = extensions.ToArray()
                };

                CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation()
                {
                    operand   = campaignExtensionSetting,
                    @operator = Operator.ADD
                };

                try {
                    // Add the extensions.
                    CampaignExtensionSettingReturnValue retVal = campaignExtensionSettingService.mutate(
                        new CampaignExtensionSettingOperation[] { operation });

                    // Display the results.
                    if (retVal.value != null && retVal.value.Length > 0)
                    {
                        CampaignExtensionSetting newExtensionSetting = retVal.value[0];
                        Console.WriteLine("Extension setting with type = {0} was added to campaign ID {1}.",
                                          newExtensionSetting.extensionType, newExtensionSetting.campaignId);
                    }
                    else
                    {
                        Console.WriteLine("No extension settings were created.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create extension settings.", e);
                }
            }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaignId">Id of the campaign to which sitelinks will
    /// be added.</param>
    public void Run(AdWordsUser user, long campaignId) {
      // Get the CampaignExtensionSettingService.
      CampaignExtensionSettingService campaignExtensionSettingService =
          (CampaignExtensionSettingService) user.GetService(
               AdWordsService.v201509.CampaignExtensionSettingService);

      CustomerService customerService = (CustomerService) user.GetService(
          AdWordsService.v201509.CustomerService);
      Customer customer = customerService.get();

      List<ExtensionFeedItem> extensions = new List<ExtensionFeedItem>();

      // Create your sitelinks.
      SitelinkFeedItem sitelink1 = new SitelinkFeedItem() {
        sitelinkText = "Store Hours",
        sitelinkFinalUrls = new string[] { "http://www.example.com/storehours" }
      };
      extensions.Add(sitelink1);

      DateTime startOfThanksGiving = new DateTime(DateTime.Now.Year, 11, 20, 0, 0, 0);
      DateTime endOfThanksGiving = new DateTime(DateTime.Now.Year, 11, 27, 23, 59, 59);

      // Add check to make sure we don't create a sitelink with end date in the
      // past.
      if (DateTime.Now < endOfThanksGiving) {
        // Show the Thanksgiving specials link only from 20 - 27 Nov.
        SitelinkFeedItem sitelink2 = new SitelinkFeedItem() {
          sitelinkText = "Thanksgiving Specials",
          sitelinkFinalUrls = new string[] { "http://www.example.com/thanksgiving" },
          startTime = string.Format("{0} {1}", startOfThanksGiving.ToString("yyyyMMdd HHmmss"),
              customer.dateTimeZone),
          endTime = string.Format("{0} {1}", endOfThanksGiving.ToString("yyyyMMdd HHmmss"),
              customer.dateTimeZone)
        };
        extensions.Add(sitelink2);
      }
      // Show the wifi details primarily for high end mobile users.
      SitelinkFeedItem sitelink3 = new SitelinkFeedItem() {
        sitelinkText = "Wifi available",
        sitelinkFinalUrls = new string[] { "http://www.example.com/mobile/wifi" },
        devicePreference = new FeedItemDevicePreference() {
          // See https://developers.google.com/adwords/api/docs/appendix/platforms
          // for device criteria IDs.
          devicePreference = 30001
        }
      };
      extensions.Add(sitelink3);

      // Show the happy hours link only during Mon - Fri 6PM to 9PM.
      SitelinkFeedItem sitelink4 = new SitelinkFeedItem() {
        sitelinkText = "Happy hours",
        sitelinkFinalUrls = new string[] { "http://www.example.com/happyhours" },
        scheduling = new FeedItemSchedule[] {
            new FeedItemSchedule() {
                dayOfWeek = DayOfWeek.MONDAY,
                startHour = 18,
                startMinute = MinuteOfHour.ZERO,
                endHour = 21,
                endMinute = MinuteOfHour.ZERO
            },
            new FeedItemSchedule() {
                dayOfWeek = DayOfWeek.TUESDAY,
                startHour = 18,
                startMinute = MinuteOfHour.ZERO,
                endHour = 21,
                endMinute = MinuteOfHour.ZERO
            },
            new FeedItemSchedule() {
                dayOfWeek = DayOfWeek.WEDNESDAY,
                startHour = 18,
                startMinute = MinuteOfHour.ZERO,
                endHour = 21,
                endMinute = MinuteOfHour.ZERO
            },
            new FeedItemSchedule() {
                dayOfWeek = DayOfWeek.THURSDAY,
                startHour = 18,
                startMinute = MinuteOfHour.ZERO,
                endHour = 21,
                endMinute = MinuteOfHour.ZERO
            },
            new FeedItemSchedule() {
                dayOfWeek = DayOfWeek.FRIDAY,
                startHour = 18,
                startMinute = MinuteOfHour.ZERO,
                endHour = 21,
                endMinute = MinuteOfHour.ZERO
            }
        }
      };
      extensions.Add(sitelink4);

      // Create your campaign extension settings. This associates the sitelinks
      // to your campaign.
      CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();
      campaignExtensionSetting.campaignId = campaignId;
      campaignExtensionSetting.extensionType = FeedType.SITELINK;
      campaignExtensionSetting.extensionSetting = new ExtensionSetting() {
        extensions = extensions.ToArray()
      };

      CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation() {
        operand = campaignExtensionSetting,
        @operator = Operator.ADD
      };

      try {
        // Add the extensions.
        CampaignExtensionSettingReturnValue retVal = campaignExtensionSettingService.mutate(
            new CampaignExtensionSettingOperation[] { operation });

        // Display the results.
        if (retVal.value != null && retVal.value.Length > 0) {
          CampaignExtensionSetting newExtensionSetting = retVal.value[0];
          Console.WriteLine("Extension setting with type = {0} was added to campaign ID {1}.",
              newExtensionSetting.extensionType, newExtensionSetting.campaignId);
        } else {
          Console.WriteLine("No extension settings were created.");
        }
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to create extension settings.", e);
      }
    }
Example #15
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which sitelinks will
        /// be added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignExtensionSettingService.
            CampaignExtensionSettingService campaignExtensionSettingService =
                (CampaignExtensionSettingService)user.GetService(
                    AdWordsService.v201502.CampaignExtensionSettingService);

            // Create your sitelinks.
            SitelinkFeedItem sitelink1 = new SitelinkFeedItem()
            {
                sitelinkText      = "Store Hours",
                sitelinkFinalUrls = new string[] { "http://www.example.com/storehours" }
            };

            // Show the Thanksgiving specials link only from 20 - 27 Nov.
            SitelinkFeedItem sitelink2 = new SitelinkFeedItem()
            {
                sitelinkText      = "Thanksgiving Specials",
                sitelinkFinalUrls = new string[] { "http://www.example.com/thanksgiving" },
                startTime         = string.Format("{0}1120 000000 EST", DateTime.Now.Year),
                endTime           = string.Format("{0}1127 235959 EST", DateTime.Now.Year)
            };

            // Show the wifi details primarily for high end mobile users.
            SitelinkFeedItem sitelink3 = new SitelinkFeedItem()
            {
                sitelinkText      = "Wifi available",
                sitelinkFinalUrls = new string[] { "http://www.example.com/mobile/wifi" },
                devicePreference  = new FeedItemDevicePreference()
                {
                    // See https://developers.google.com/adwords/api/docs/appendix/platforms
                    // for device criteria IDs.
                    devicePreference = 30001
                }
            };

            // Show the happy hours link only during Mon - Fri 6PM to 9PM.
            SitelinkFeedItem sitelink4 = new SitelinkFeedItem()
            {
                sitelinkText      = "Happy hours",
                sitelinkFinalUrls = new string[] { "http://www.example.com/happyhours" },
                scheduling        = new FeedItemSchedule[] {
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = AdWords.v201502.DayOfWeek.MONDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = AdWords.v201502.DayOfWeek.TUESDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = AdWords.v201502.DayOfWeek.WEDNESDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = AdWords.v201502.DayOfWeek.THURSDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    },
                    new FeedItemSchedule()
                    {
                        dayOfWeek   = AdWords.v201502.DayOfWeek.FRIDAY,
                        startHour   = 18,
                        startMinute = MinuteOfHour.ZERO,
                        endHour     = 21,
                        endMinute   = MinuteOfHour.ZERO
                    }
                }
            };

            // Create your campaign extension settings. This associates the sitelinks
            // to your campaign.
            CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();

            campaignExtensionSetting.campaignId       = campaignId;
            campaignExtensionSetting.extensionType    = FeedType.SITELINK;
            campaignExtensionSetting.extensionSetting = new ExtensionSetting()
            {
                extensions = new ExtensionFeedItem[] {
                    sitelink1, sitelink2, sitelink3, sitelink4
                }
            };

            CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation()
            {
                operand   = campaignExtensionSetting,
                @operator = Operator.ADD
            };

            try {
                // Add the extensions.
                CampaignExtensionSettingReturnValue retVal = campaignExtensionSettingService.mutate(
                    new CampaignExtensionSettingOperation[] { operation });

                // Display the results.
                if (retVal.value != null && retVal.value.Length > 0)
                {
                    CampaignExtensionSetting newExtensionSetting = retVal.value[0];
                    Console.WriteLine("Extension setting with type = {0} was added to campaign ID {1}.",
                                      newExtensionSetting.extensionType, newExtensionSetting.campaignId);
                }
                else
                {
                    Console.WriteLine("No extension settings were created.");
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to create extension settings.", ex);
            }
        }
    /// <summary>
    /// Creates the extension setting fo a list of feed items.
    /// </summary>
    /// <param name="user">The user for which extension settings are created.
    /// </param>
    /// <param name="feedItems">The list of all feed items.</param>
    /// <param name="campaignId">ID of the campaign to which extension settings
    /// are added.</param>
    /// <param name="feedItemIds">IDs of the feed items for which extension
    /// settings should be created.</param>
    /// <param name="platformRestrictions">The platform restrictions for the
    /// extension setting.</param>
    private static void CreateExtensionSetting(AdWordsUser user, Dictionary<long,
        SiteLinkFromFeed> feedItems, long campaignId, List<long> feedItemIds,
        ExtensionSettingPlatform platformRestrictions) {
      CampaignExtensionSetting extensionSetting = new CampaignExtensionSetting() {
        campaignId = campaignId,
        extensionType = FeedType.SITELINK,
        extensionSetting = new ExtensionSetting() {
        }
      };

      List<ExtensionFeedItem> extensionFeedItems = new List<ExtensionFeedItem>();

      foreach (long feedItemId in feedItemIds) {
        SiteLinkFromFeed feedItem = feedItems[feedItemId];
        SitelinkFeedItem newFeedItem = new SitelinkFeedItem() {
          sitelinkText = feedItem.Text,
          sitelinkUrl = feedItem.Url,
          sitelinkFinalUrls = feedItem.FinalUrls,
          sitelinkFinalMobileUrls = feedItem.FinalMobileUrls,
          sitelinkTrackingUrlTemplate = feedItem.TrackingUrlTemplate,
          sitelinkLine2 = feedItem.Line2,
          sitelinkLine3 = feedItem.Line3,
          scheduling = feedItem.Scheduling
        };

        extensionFeedItems.Add(newFeedItem);
      }
      extensionSetting.extensionSetting.extensions = extensionFeedItems.ToArray();
      extensionSetting.extensionSetting.platformRestrictions = platformRestrictions;
      extensionSetting.extensionType = FeedType.SITELINK;

      CampaignExtensionSettingService campaignExtensionSettingService =
          (CampaignExtensionSettingService) user.GetService(
              AdWordsService.v201509.CampaignExtensionSettingService);
      CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation() {
        operand = extensionSetting,
        @operator = Operator.ADD
      };

      campaignExtensionSettingService.mutate(new CampaignExtensionSettingOperation[] { operation });
      return;
    }