Hi,
I'm trying to get keyword statistics and related keywords using
TargetingIdeaService in C#. My code is very similar to the provided
example and works with my testing account. The issue I'm facing is that the
results I'm getting are completely off comparing to the results I'm getting
online.
I tried my code on this input: "business intelligence software" and the
output I'm getting is: "For keyword business intelligence software, result
keyword is 'business intelligence software', average monthly search volume
6215512, average CPC 11305247, and competition 0.51. Number of related
keywords found: 1.". Running the same query online returns traffic
estimation of 1K - 10K (see attached screenshot)
Full HTTP request & response as well as my C# code is attached.
Any help will be much appreciated,
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/a779f352-3e51-47a4-b29d-e93f521efd0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Request:
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><RequestHeader
xmlns="https://adwords.google.com/api/adwords/o/v201710"><clientCustomerId>XXX</clientCustomerId><developerToken>YYY</developerToken><userAgent>unknown
(AwApi-DotNet/22.4.0, Common-Dotnet/8.1.0, .NET CLR/4.0.30319.42000, Logging,
OAuthApplicationFlow, SelectorBuilder,
gzip)</userAgent></RequestHeader></s:Header><s:Body
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><get
xmlns="https://adwords.google.com/api/adwords/o/v201710"><selector><searchParameters
xsi:type="RelatedToQuerySearchParameter"><queries>business intelligence
software</queries></searchParameters><searchParameters
xsi:type="LanguageSearchParameter"><languages><id
xmlns="https://adwords.google.com/api/adwords/cm/v201710">1000</id></languages></searchParameters><searchParameters
xsi:type="NetworkSearchParameter"><networkSetting><targetGoogleSearch
xmlns="https://adwords.google.com/api/adwords/cm/v201710">true</targetGoogleSearch><targetSearchNetwork
xmlns="https://adwords.google.com/api/adwords/cm/v201710">false</targetSearchNetwork><targetContentNetwork
xmlns="https://adwords.google.com/api/adwords/cm/v201710">false</targetContentNetwork><targetPartnerSearchNetwork
xmlns="https://adwords.google.com/api/adwords/cm/v201710">false</targetPartnerSearchNetwork></networkSetting></searchParameters><ideaType>KEYWORD</ideaType><requestType>STATS</requestType><requestedAttributeTypes>KEYWORD_TEXT</requestedAttributeTypes><requestedAttributeTypes>SEARCH_VOLUME</requestedAttributeTypes><requestedAttributeTypes>AVERAGE_CPC</requestedAttributeTypes><requestedAttributeTypes>COMPETITION</requestedAttributeTypes><requestedAttributeTypes>TARGETED_MONTHLY_SEARCHES</requestedAttributeTypes><paging><startIndex
xmlns="https://adwords.google.com/api/adwords/cm/v201710">0</startIndex><numberResults
xmlns="https://adwords.google.com/api/adwords/cm/v201710">500</numberResults></paging></selector></get></s:Body></s:Envelope>
Response:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><ResponseHeader
xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201710"
xmlns="https://adwords.google.com/api/adwords/o/v201710"><ns2:requestId>00055fa78ddad7e00a56e441c20a6c71</ns2:requestId><ns2:serviceName>TargetingIdeaService</ns2:serviceName><ns2:methodName>get</ns2:methodName><ns2:operations>1</ns2:operations><ns2:responseTime>178</ns2:responseTime></ResponseHeader></soap:Header><soap:Body><getResponse
xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201710"
xmlns="https://adwords.google.com/api/adwords/o/v201710"><rval><totalNumEntries>1</totalNumEntries><entries><data><key>KEYWORD_TEXT</key><value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="StringAttribute"><Attribute.Type>StringAttribute</Attribute.Type><value>business
intelligence software</value></value></data><data><key>COMPETITION</key><value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="DoubleAttribute"><Attribute.Type>DoubleAttribute</Attribute.Type><value>0.5079278334113464</value></value></data><data><key>TARGETED_MONTHLY_SEARCHES</key><value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="MonthlySearchVolumeAttribute"><Attribute.Type>MonthlySearchVolumeAttribute</Attribute.Type><value><year>2017</year><month>11</month><count>6532298</count></value><value><year>2017</year><month>10</month><count>3263189</count></value><value><year>2017</year><month>9</month><count>9322089</count></value><value><year>2017</year><month>8</month><count>4566792</count></value><value><year>2017</year><month>7</month><count>8780853</count></value><value><year>2017</year><month>6</month><count>5636080</count></value><value><year>2017</year><month>5</month><count>3370925</count></value><value><year>2017</year><month>4</month><count>7799183</count></value><value><year>2017</year><month>3</month><count>9975124</count></value><value><year>2017</year><month>2</month><count>6404625</count></value><value><year>2017</year><month>1</month><count>1095159</count></value><value><year>2016</year><month>12</month><count>7839827</count></value></value></data><data><key>AVERAGE_CPC</key><value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="MoneyAttribute"><Attribute.Type>MoneyAttribute</Attribute.Type><value><ns2:ComparableValue.Type>Money</ns2:ComparableValue.Type><ns2:microAmount>11305247</ns2:microAmount></value></value></data><data><key>SEARCH_VOLUME</key><value
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="LongAttribute"><Attribute.Type>LongAttribute</Attribute.Type><value>6215512</value></value></data></entries></rval></getResponse></soap:Body></soap:Envelope>
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,
AttributeType.TARGETED_MONTHLY_SEARCHES
};
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);
NetworkSetting networkSetting = new NetworkSetting();
networkSetting.targetContentNetwork = false;
networkSetting.targetGoogleSearch = true;
networkSetting.targetPartnerSearchNetwork = false;
networkSetting.targetSearchNetwork = false;
NetworkSearchParameter networkSearchParameter = new 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();
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.TARGETED_MONTHLY_SEARCHES] as LongAttribute).value;
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);
}
}
}
public void GetKeywordRelatedKeywords(string keyword)
{
AdWordsUser user = new AdWordsUser();
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
};
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);
NetworkSetting networkSetting = new NetworkSetting();
networkSetting.targetContentNetwork = false;
networkSetting.targetGoogleSearch = true;
networkSetting.targetPartnerSearchNetwork = false;
networkSetting.targetSearchNetwork = false;
NetworkSearchParameter networkSearchParameter = new 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();
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}, related 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
}
}