Пример #1
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 = new UrlList()
                    {
                        urls = feedItem.FinalUrls
                    },
                    sitelinkFinalMobileUrls = new UrlList()
                    {
                        urls = 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;

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

                campaignExtensionSettingService.mutate(
                    new CampaignExtensionSettingOperation[] { operation });
            }
            return;
        }
Пример #2
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);
            }
        }
Пример #3
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.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);
            }
        }
Пример #4
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)
        {
            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);
                }
            }
        }
Пример #5
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);
            }
        }