Hi there,

I'm trying to use the API with the Targeting Idea Service to get 
"targeted_monthly_searches" for various search terms: e.g., react.js, 
vue.js, angular.js. The trick is that I clearly get different results 
between, say, react.js and reactjs. So I'd prefer the aggregated related 
search term result be returned (i.e., the search traffic for "react.js" OR 
"reactjs"). I assume this is what occurs when match type is "broad," but 
I'm not sure how to specify different types of match when using the 
Targeting Idea Service (I see that the Traffic Estimator Service offers the 
ability to specify matchType as "BROAD", but this doesn't seem to be an 
option with the Targeting Idea Service.

Also, is there a way to put filtering in the query? I.e., when you're 
searching YouTube or Google you can be more specific by including OR, AND, 
and NOT parameters. But there doesn't seem to be any way to do that beyond 
just specifying matchType = BROAD. But does "broad" match type even 
function as desired (giving you, for example, an aggregate result for 
vuejs/vue.js/"vue js"/etc.?

############# Here's what works:

from googleads import adwords
import pandas as pd


adwords_client = adwords.AdWordsClient.LoadFromStorage()

PAGE_SIZE = 10

# Initialize appropriate service.
targeting_idea_service = adwords_client.GetService(
    'TargetingIdeaService', version='v201609')

# Construct selector object and retrieve related keywords.
offset = 0
stats_selector = {
    'searchParameters': [
        {
            'xsi_type': 'RelatedToQuerySearchParameter',
            'queries': ['react.js', 'reactjs', 'vuejs', 'vue.js']
        },
        {
        # Language setting (optional).
        # The ID can be found in the documentation:
        # 
 https://developers.google.com/adwords/api/docs/appendix/languagecodes
            'xsi_type': 'LanguageSearchParameter',
            'languages': [{'id': '1000'}],
        },
        {
              # Network search parameter (optional)
              'xsi_type': 'NetworkSearchParameter',
              'networkSetting': {
                  'targetGoogleSearch': True,
                  'targetSearchNetwork': False,
                  'targetContentNetwork': False,
                  'targetPartnerSearchNetwork': False
              }
         }
    ],
    'ideaType': 'KEYWORD',
    'requestType': 'STATS',
    'requestedAttributeTypes': ['KEYWORD_TEXT', 
'TARGETED_MONTHLY_SEARCHES'],
    'paging': {
        'startIndex': str(offset),
        'numberResults': str(PAGE_SIZE)
    }
}

stats_page = targeting_idea_service.get(stats_selector)


# Parse results to pandas dataframe

stats_pd = pd.DataFrame()

if 'entries' in stats_page:
    for stats_result in stats_page['entries']:
        stats_attributes = {}
        for stats_attribute in stats_result['data']:
            #print (stats_attribute)
            if stats_attribute['key'] == 'KEYWORD_TEXT':
                kt = stats_attribute['value']['value']
            else:
                for i, val in enumerate(stats_attribute['value'][1]):       
         
                    data = {'keyword': kt,
                            'year': val['year'],
                            'month': val['month'],
                            'count': val['count']}
                    data = pd.DataFrame(data, index = [i])                
                    stats_pd = stats_pd.append(data, ignore_index=True)


print(stats_pd)






########  And this doesn't (but would be appealing):

from googleads import adwords
import pandas as pd


adwords_client = adwords.AdWordsClient.LoadFromStorage()

PAGE_SIZE = 10

# Initialize appropriate service.
targeting_idea_service = adwords_client.GetService(
    'TargetingIdeaService', version='v201609')

# Construct selector object and retrieve related keywords.
offset = 0
stats_selector = {
    'searchParameters': [
        {
            'xsi_type': 'RelatedToQuerySearchParameter',
            'queries':  [
                            {'term': 'react js', 'matchType': 'BROAD'},
                            {'term': 'reactjs', 'matchType': 'PHRASE'},
                            {'term': 'react.js', 'matchType': 'EXACT'}
                        ]
        },
        {
        # Language setting (optional).
        # The ID can be found in the documentation:
        # 
 https://developers.google.com/adwords/api/docs/appendix/languagecodes
            'xsi_type': 'LanguageSearchParameter',
            'languages': [{'id': '1000'}],
        },
        {
              # Network search parameter (optional)
              'xsi_type': 'NetworkSearchParameter',
              'networkSetting': {
                  'targetGoogleSearch': True,
                  'targetSearchNetwork': False,
                  'targetContentNetwork': False,
                  'targetPartnerSearchNetwork': False
              }
         }
    ],
    'ideaType': 'KEYWORD',
    'requestType': 'STATS',
    'requestedAttributeTypes': ['KEYWORD_TEXT', 
'TARGETED_MONTHLY_SEARCHES'],
    'paging': {
        'startIndex': str(offset),
        'numberResults': str(PAGE_SIZE)
    }
}

stats_page = targeting_idea_service.get(stats_selector)


# Parse results to pandas dataframe

stats_pd = pd.DataFrame()

if 'entries' in stats_page:
    for stats_result in stats_page['entries']:
        stats_attributes = {}
        for stats_attribute in stats_result['data']:
            #print (stats_attribute)
            if stats_attribute['key'] == 'KEYWORD_TEXT':
                kt = stats_attribute['value']['value']
            else:
                for i, val in enumerate(stats_attribute['value'][1]):       
         
                    data = {'keyword': kt,
                            'year': val['year'],
                            'month': val['month'],
                            'count': val['count']}
                    data = pd.DataFrame(data, index = [i])                
                    stats_pd = stats_pd.append(data, ignore_index=True)


print(stats_pd)






######### Or this would be a nice solution:


from googleads import adwords
import pandas as pd


adwords_client = adwords.AdWordsClient.LoadFromStorage()

PAGE_SIZE = 10

# Initialize appropriate service.
targeting_idea_service = adwords_client.GetService(
    'TargetingIdeaService', version='v201609')

# Construct selector object and retrieve related keywords.
offset = 0
stats_selector = {
    'searchParameters': [
        {
            'xsi_type': 'RelatedToQuerySearchParameter',
            'queries':  [
                            {'term': 'vue js|vue.js|vuejs', 'as': 'vue.js'},
                            {'term': 'react js|react.js|reactjs', 'as': 
'react.js'},
                            {'term': 'angular js|angular.js|angularjs', 
'as': 'angular.js'}
                        ]
        },
        {
        # Language setting (optional).
        # The ID can be found in the documentation:
        # 
 https://developers.google.com/adwords/api/docs/appendix/languagecodes
            'xsi_type': 'LanguageSearchParameter',
            'languages': [{'id': '1000'}],
        },
        {
              # Network search parameter (optional)
              'xsi_type': 'NetworkSearchParameter',
              'networkSetting': {
                  'targetGoogleSearch': True,
                  'targetSearchNetwork': False,
                  'targetContentNetwork': False,
                  'targetPartnerSearchNetwork': False
              }
         }
    ],
    'ideaType': 'KEYWORD',
    'requestType': 'STATS',
    'requestedAttributeTypes': ['KEYWORD_TEXT', 
'TARGETED_MONTHLY_SEARCHES'],
    'paging': {
        'startIndex': str(offset),
        'numberResults': str(PAGE_SIZE)
    }
}

stats_page = targeting_idea_service.get(stats_selector)


# Parse results to pandas dataframe

stats_pd = pd.DataFrame()

if 'entries' in stats_page:
    for stats_result in stats_page['entries']:
        stats_attributes = {}
        for stats_attribute in stats_result['data']:
            #print (stats_attribute)
            if stats_attribute['key'] == 'KEYWORD_TEXT':
                kt = stats_attribute['value']['value']
            else:
                for i, val in enumerate(stats_attribute['value'][1]):       
         
                    data = {'keyword': kt,
                            'year': val['year'],
                            'month': val['month'],
                            'count': val['count']}
                    data = pd.DataFrame(data, index = [i])                
                    stats_pd = stats_pd.append(data, ignore_index=True)


print(stats_pd)

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
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/244b4dd1-f91e-4caa-affa-b27ca5834999%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to