/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201601.TargetingIdeaService); // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES }; // Create the search parameters. string keywordText = "mars cruise"; // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { keywordText }; // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes // Note: As of v201302, only a single language parameter is allowed. LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; // Set the search parameters. selector.searchParameters = new SearchParameter[] { relatedToQuerySearchParameter, languageParameter, networkSearchParameter }; // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { string keyword = null; string categories = null; long averageMonthlySearches = 0; foreach (Type_AttributeMapEntry entry in targetingIdea.data) { if (entry.key == AttributeType.KEYWORD_TEXT) { keyword = (entry.value as StringAttribute).value; } if (entry.key == AttributeType.CATEGORY_PRODUCTS_AND_SERVICES) { IntegerSetAttribute categorySet = entry.value as IntegerSetAttribute; StringBuilder builder = new StringBuilder(); if (categorySet.value != null) { foreach (int value in categorySet.value) { builder.AppendFormat("{0}, ", value); } categories = builder.ToString().Trim(new char[] { ',', ' ' }); } } if (entry.key == AttributeType.SEARCH_VOLUME) { averageMonthlySearches = (entry.value as LongAttribute).value; } } Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">ID of the ad group to use for generating ideas.</param> public void Run(AdWordsUser user, long?adGroupId) { using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201710.TargetingIdeaService)) { // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES }; List <SearchParameter> searchParameters = new List <SearchParameter>(); // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { "bakery", "pastries", "birthday cake" }; searchParameters.Add(relatedToQuerySearchParameter); // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; searchParameters.Add(languageParameter); // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; searchParameters.Add(networkSearchParameter); // Optional: Use an existing ad group to generate ideas. if (adGroupId != null) { SeedAdGroupIdSearchParameter seedAdGroupIdSearchParameter = new SeedAdGroupIdSearchParameter(); seedAdGroupIdSearchParameter.adGroupId = adGroupId.Value; searchParameters.Add(seedAdGroupIdSearchParameter); } // Set the search parameters. selector.searchParameters = searchParameters.ToArray(); // Set selector paging (required for targeting idea service). selector.paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { Dictionary <AttributeType, Google.Api.Ads.AdWords.v201710.Attribute> ideas = targetingIdea.data.ToDict(); string keyword = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value; IntegerSetAttribute categorySet = ideas[AttributeType.CATEGORY_PRODUCTS_AND_SERVICES] as IntegerSetAttribute; string categories = ""; if (categorySet != null && categorySet.value != null) { categories = string.Join(", ", categorySet.value); } long averageMonthlySearches = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value; Money averageCpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value; double competition = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value; Console.WriteLine("Keyword with text '{0}', average monthly search " + "volume {1}, average CPC {2}, and competition {3:F2} was found with " + "categories: {4}", keyword, averageMonthlySearches, averageCpc?.microAmount, competition, categories); Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } } }
/// <summary> /// Gets keyword ideas for the list of Seed keywords. /// </summary> /// <param name="user">The user for which keyword ideas are generated. /// </param> /// <param name="seedKeywords">The seed keywords for generating ideas. /// </param> /// <param name="negativeTerms">The list of keywords to exclude.</param> /// <returns>A list of keyword ideas.</returns> private List <KeywordIdea> GetKeywordIdeas(AdWordsUser user, List <string> seedKeywords, SeedKeyword[] negativeTerms) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201607.TargetingIdeaService); IdeaTextFilterSearchParameter excludedTerms = null; if (negativeTerms.Length > 0) { excludedTerms = GetExcludedKeywordSearchParams(negativeTerms); } LanguageSearchParameter languageParams = GetLanguageSearchParams(); LocationSearchParameter locationParams = GetLocationSearchParams(); List <KeywordIdea> retval = new List <KeywordIdea>(); for (int i = 0; i < seedKeywords.Count; i += Settings.TIS_KEYWORDS_LIST_SIZE) { List <string> keywordsToSearch = new List <string>(); for (int j = i; j < i + Settings.TIS_KEYWORDS_LIST_SIZE && j < seedKeywords.Count; j++) { keywordsToSearch.Add(seedKeywords[j]); } // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION }; List <SearchParameter> paramList = new List <SearchParameter>(); paramList.Add(new RelatedToQuerySearchParameter() { queries = keywordsToSearch.ToArray(), }); if (excludedTerms != null) { paramList.Add(excludedTerms); } paramList.Add(locationParams); paramList.Add(languageParams); selector.searchParameters = paramList.ToArray(); // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { string keyword = null; long averageMonthlySearches = 0; long averageCpc = 0; double competition = 0f; foreach (Type_AttributeMapEntry entry in targetingIdea.data) { if (entry.key == AttributeType.KEYWORD_TEXT) { StringAttribute temp = (entry.value as StringAttribute); if (temp != null) { keyword = temp.value; } } if (entry.key == AttributeType.SEARCH_VOLUME) { LongAttribute temp = (entry.value as LongAttribute); if (temp != null) { averageMonthlySearches = temp.value; } } if (entry.key == AttributeType.AVERAGE_CPC) { MoneyAttribute temp = (entry.value as MoneyAttribute); if (temp != null && temp.value != null) { averageCpc = temp.value.microAmount; } } if (entry.key == AttributeType.COMPETITION) { DoubleAttribute temp = (entry.value as DoubleAttribute); if (temp != null) { competition = temp.value; } } } KeywordIdea keywordIdea = new KeywordIdea() { KeywordText = keyword, AverageSearches = averageMonthlySearches, AverageCpc = averageCpc, Competition = Math.Round(competition, Settings.ACCURACY, MidpointRounding.AwayFromZero) }; retval.Add(keywordIdea); } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } } return(retval); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService) user.GetService(AdWordsService.v201509.TargetingIdeaService); string keywordText = "mars cruise"; // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES}; // Language setting (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes // Note: As of v201302, only a single language parameter is allowed. LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] {english}; // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] {keywordText}; selector.searchParameters = new SearchParameter[] {relatedToQuerySearchParameter, languageParameter}; // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { string keyword = null; string categories = null; long averageMonthlySearches = 0; foreach (Type_AttributeMapEntry entry in targetingIdea.data) { if (entry.key == AttributeType.KEYWORD_TEXT) { keyword = (entry.value as StringAttribute).value; } if (entry.key == AttributeType.CATEGORY_PRODUCTS_AND_SERVICES) { IntegerSetAttribute categorySet = entry.value as IntegerSetAttribute; StringBuilder builder = new StringBuilder(); if (categorySet.value != null) { foreach (int value in categorySet.value) { builder.AppendFormat("{0}, ", value); } categories = builder.ToString().Trim(new char[] {',', ' '}); } } if (entry.key == AttributeType.SEARCH_VOLUME) { averageMonthlySearches = (entry.value as LongAttribute).value; } } Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201406.TargetingIdeaService); // Create seed url. string url = "mars.google.com"; // Create the selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.PLACEMENT; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.CRITERION, AttributeType.PLACEMENT_TYPE }; // Create related to url search parameter. RelatedToUrlSearchParameter relatedToUrlSearchParameter = new RelatedToUrlSearchParameter(); relatedToUrlSearchParameter.urls = new string[] { url }; relatedToUrlSearchParameter.includeSubUrls = false; selector.searchParameters = new SearchParameter[] { relatedToUrlSearchParameter }; // Set selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; TargetingIdeaPage page = new TargetingIdeaPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get placement ideas. page = targetingIdeaService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (TargetingIdea idea in page.entries) { foreach (Type_AttributeMapEntry entry in idea.data) { if (entry.key == AttributeType.CRITERION) { CriterionAttribute placementAttribute = entry.value as CriterionAttribute; Placement placement = (Placement)placementAttribute.value; Console.WriteLine("Related placement urls were found at '{0}'.", (placementAttribute.value as Placement).url); } } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of related placements found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve related placements.", ex); } }
private void GetTargetingIdea_Click(object sender, EventArgs e) { Dictionary <string, string> headers = new Dictionary <string, string>() { { "DeveloperToken", this.DeveloperToken.Text }, { "UserAgent", String.Format("Edge File Manager (version {0})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()) }, { "EnableGzipCompression", this.EnableGzipCompression.Text }, { "ClientCustomerId", this.ClientCustomerId.Text }, { "Email", this.Email.Text } }; User = new AdWordsUser(headers); try { //Getting AuthToken (User.Config as AdWordsAppConfig).AuthToken = AdwordsUtill.GetAuthToken(User); } catch (Exception exc) { this.rchtxt.Text = exc.Message + " #### " + exc.InnerException != null ? exc.InnerException.Message : string.Empty; } TargetingIdeaService targetingService = (TargetingIdeaService)User.GetService(AdWordsService.v201302.TargetingIdeaService); // Create the selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.currencyCode = "USD"; // selector.fields = new string[] { "Id", "Status", "Clicks" }; // Set the filters. // Predicate predicate = new Predicate(); // predicate.field = "CampaignId"; // predicate.@operator = PredicateOperator.EQUALS; // predicate.values = new string[] { campaignId.ToString() }; // selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; TargetingIdeaPage page = new TargetingIdeaPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all campaign targets. page = targetingService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (TargetingIdea target in page.entries) { i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of ad groups criteria found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get adgroup targeting criteria.", ex); } }
public string Get() { var user = new AdWordsUser(); using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(Google.Api.Ads.AdWords.Lib.AdWordsService.v201802.TargetingIdeaService)) { // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.STATS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME }; List <SearchParameter> searchParameters = new List <SearchParameter>(); // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { "bakery" }; searchParameters.Add(relatedToQuerySearchParameter); // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; searchParameters.Add(languageParameter); // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; searchParameters.Add(networkSearchParameter); // Set the search parameters. selector.searchParameters = searchParameters.ToArray(); // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; selector.paging = paging; TargetingIdeaPage page = new TargetingIdeaPage(); int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (var targetingIdea in page.entries) { Dictionary <AttributeType, Google.Api.Ads.AdWords.v201802.Attribute> ideas = targetingIdea.data.ToDict(); string keyword = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value; long averageMonthlySearches = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value; i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); } return("value"); }