Hello,
I'm trying to use TargetingIdeaService (C#) to get average monthly volume
and other keyword related parameters.
The code I'm using almost identical to provided examples, I just changed
the requestType to RequestType.STATS as appears in the attached file.
But the results I'm getting when running this code seems to be completely
off.
I tried two queries: "business intelligence software" and "maximtesttest".
For both, average monthly search and average CPC shows very strange results
of millions:
For keyword 'maximtesttest', result keyword is 'maximtesttest', average
monthly search volume *4232209*, average CPC *15058881*, and competition
0.62. Number of related keywords found: 1
For keyword 'business intelligence software', result keyword is 'business
intelligence software', average monthly search volume *5978033*, average
CPC *6296117*, and competition 0.30. Number of related keywords found: 1
Testing these keywords online works well.
Any help will be appreciated.
Thanks,
Maxim
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/01826bdc-2bc5-490e-b1e1-de99899b92b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
using Google.Api.Ads.AdWords.Lib;
using SEOAPITest.Examples.CSharp;
using SEOAPITest.Examples.CSharp.v201710;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Api.Ads.AdWords.Lib;
using Google.Api.Ads.AdWords.v201710;
namespace SEOAPITest
{
public class GoogleAPI
{
public void GetKeywordStats(string keyword)
{
AdWordsUser user = new AdWordsUser();
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201710.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,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION
};
List<SearchParameter> searchParameters = new List<SearchParameter>();
// Create related to query search parameter.
RelatedToQuerySearchParameter relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.queries = new String[] { keyword };
searchParameters.Add(relatedToQuerySearchParameter);
LanguageSearchParameter languageParameter = new LanguageSearchParameter();
Language english = new Language();
english.id = 1000;
languageParameter.languages = new Language[] { english };
searchParameters.Add(languageParameter);
// 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();
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)
{
Dictionary<AttributeType, Google.Api.Ads.AdWords.v201710.Attribute> ideas =
targetingIdea.data.ToDict();
long averageMonthlySearches =
(ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value;
string keywordRes = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value;
Money averageCpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value;
double competition = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value;
Console.WriteLine("For keyword {0}, result keyword is '{1}', average monthly search " +
"volume {2}, average CPC {3}, and competition {4:F2}", keyword, keywordRes, averageMonthlySearches, averageCpc?.microAmount,
competition);
}
}
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);
}
}
}
#region Old
/*public void GetCampaignStats(string keyword)
{
AdWordsUser user = new AdWordsUser();
using (TrafficEstimatorService trafficEstimatorService =
(TrafficEstimatorService)user.GetService(AdWordsService.v201710.TrafficEstimatorService))
{
Keyword keyword2 = new Keyword() { text = keyword, matchType = KeywordMatchType.PHRASE };
KeywordEstimateRequest keywordEstimateRequest = new KeywordEstimateRequest() { keyword = keyword2 };
AdGroupEstimateRequest adGroupEstimateRequest = new AdGroupEstimateRequest();
adGroupEstimateRequest.keywordEstimateRequests = new KeywordEstimateRequest[] { keywordEstimateRequest };
adGroupEstimateRequest.maxCpc = new Money();
adGroupEstimateRequest.maxCpc.microAmount = 1000000;
CampaignEstimateRequest campaignEstimateRequest = new CampaignEstimateRequest();
Language languageCriterion = new Language();
languageCriterion.id = 1000; //en
campaignEstimateRequest.criteria = new Criterion[] { languageCriterion };
campaignEstimateRequest.adGroupEstimateRequests = new AdGroupEstimateRequest[] { adGroupEstimateRequest };
try
{
// Create the selector.
TrafficEstimatorSelector selector = new TrafficEstimatorSelector()
{
campaignEstimateRequests = new CampaignEstimateRequest[] { campaignEstimateRequest },
// Optional: Request a list of campaign level estimates segmented by platform.
platformEstimateRequested = false
};
// Get traffic estimates.
TrafficEstimatorResult result = trafficEstimatorService.get(selector);
// Display traffic estimates.
if (result != null && result.campaignEstimates != null &&
result.campaignEstimates.Length > 0)
{
CampaignEstimate campaignEstimate = result.campaignEstimates[0];
// Display the keyword estimates.
if (campaignEstimate.adGroupEstimates != null &&
campaignEstimate.adGroupEstimates.Length > 0)
{
AdGroupEstimate adGroupEstimate = campaignEstimate.adGroupEstimates[0];
if (adGroupEstimate.keywordEstimates != null)
{
for (int i = 0; i < adGroupEstimate.keywordEstimates.Length; i++)
{
KeywordEstimate keywordEstimate = adGroupEstimate.keywordEstimates[i];
string kwdMessage = string.Format("For keyword with text = '{0}' min estimate {1} max estimate {2} ", keyword, keywordEstimate.min, keywordEstimate.max);
}
}
}
}
else
{
Console.WriteLine("No traffic estimates were returned.");
}
trafficEstimatorService.Close();
}
catch (Exception e)
{
throw new System.ApplicationException("Failed to retrieve traffic estimates.", e);
}
}
}*/
#endregion
}
}