Ads Developer Blog
The official blog for information about the Google Ads, Google Ad Manager, Google Mobile Ads SDKs for AdMob and IMA SDKs, and other Google Advertising Platform developer tools.
The Query Builder Blog Series: Part 4 - Creating the Resource Service
Monday, April 26, 2021
This
blog series
follows the journey of building the new and improved
Interactive Google Ads Query Builder
tool.
Part 3
of this series described how we used the
GoogleAdsFieldService
to create a detailed JSON resource schema to serve as the canonical data set for the angular application. In Part 4, we will discuss how to create a resource service that determines which fields are displayed to users in various parts of the application.
Background
One of the benefits of the new Interactive Google Ads Query Builder is that fields are dynamically updated based on user selections to display whether a field is selectable or not, and if not, users are provided with feedback to understand why a given field is not selectable. However, we must first present lists of fields that are available to select in each clause of a Google Ads Query Language (GAQL) string based on the main resource in the FROM clause of that GAQL string. We will create a service called the
ResourceService
that will contain this logic. Then, we can use Angular’s
services and dependency injection
model to pull the appropriate fields and their related information into any component.
Objective
The app is designed such that the FROM resource is
determined by the user’s current URL
. Therefore, the resource in the
FROM clause
and list of all available fields is constant based on that URL. For the sake of this post, we are only concerned with three GAQL clauses,
SELECT
,
WHERE
, and
ORDER BY
, because these are the only clauses that can be dynamically populated with fields.
LIMIT
accepts an integer, and
PARAMETERS
only has a single option.
Within each clause, we will organize each of the available fields into four categories:
attribute fields
,
metrics
,
segments
, and
attributed resource fields
for a better user experience. Our objective is to create a
ResourceService
that provides the relevant fields for a given clause and category.
Implementation
We can leverage the
resource schema we generated earlier
to select the entry for the main resource in the FROM clause as determined by the URL and filter its fields sub-entry to provide only
fields
that match specific criteria.
Let’s begin by categorizing our fields by clause.
Fields in the SELECT clause have the
selectable
property equal to true.
Fields in the WHERE clause have the
filterable
property equal to true.
Fields in the ORDER BY clause have the
sortable
property equal to true.
We can further break these field lists into attribute fields, metrics, segments, and attributed resource fields. Retrieving the metrics and segments in a given clause is trivial because our resource schema provides a list of metrics and segments (including
segmenting resources
). For each clause, we’ll include all of the segments and metrics that meet the clause-related criteria listed above.
Similarly, we can retrieve each clause’s main attribute fields by looking at the
attributes
of the resource in our FROM clause, filtering for those which begin with the resource name followed by a dot, and applying the clause-related filtering criteria above.
All of the other fields in our
attributes
entry are attributed resource fields. We can generate a list of attributed resources by creating a set of the unique prefixes (i.e., the text that precedes the dot) of the resource’s
attributes
excluding our main resource. Finally, we can create a list of fields by clause for each attributed resource by selecting the fields that are prefixed with each respective attributed resource’s name.
With all of this logic in place, we can create an interface that exposes methods for returning a list of fields in a given category and clause. Then, any component that is injected with the
ResourceService
can simply call the corresponding method to retrieve the appropriate list of fields.
Conclusion
We now have created a
ResourceService
that we can use to display relevant fields to a user constructing a GAQL query based on the clause and category they are viewing in the app. In this post, we’ve covered:
GAQL query structure.
The various types of fields that can appear in GAQL clauses.
Field properties
and how they correspond to different GAQL clauses.
Hopefully this has deepened your understanding of constructing GAQL queries with the Google Ads API. If you have any questions or need additional help, contact us via the
forum
or at googleadsapi-support@google.com.
- Devin Chasanoff, on behalf of the Google Ads API Team
Labels
account_management
ad_clicks
ad_customizers
ad_exchange
ad_exchange_buyer
ad_exchange_optimization-series
ad_exchange_rest
ad_exchange_rtb
ad_exchange_seller
ad_exchange_soap
ad_extensions
ad_inspector
ad_manager
ad_manager_api
ad_manager_api_v201805
ad_manager_api_v201808
ad_manager_api_v201811
ad_manager_api_v201902
ad_manager_api_v201905
ad_manager_api_v201908
ad_manager_api_v201911
ad_manager_api_v202002
ad_manager_api_v202005
ad_manager_api_v202008
ad_manager_api_v202011
ad_manager_api_v202102
ad_manager_api_v202105
ad_manager_api_v202108
ad_manager_api_v202111
ad_manager_api_v202202
ad_manager_api_v202205
ad_manager_api_v202208
ad_manager_api_v202211
ad_manager_api_v202302
ad_manager_api_v202305
ad_manager_api_v202308
ad_manager_api_v202311
ad_manager_api_v202402
ad_manager_api_v202405
ad_manager_api_v202408
ad_param
ad_speed
adexchangebuyer
AdGroup
AdGroupAd
admanager_api
admob
admob_api
admob_api_v1
admob_mediation
admob_sdk
admob_v4.3.1
admob_v5.0.5
admob_v6.0.1
ads
adsense
adsense_api
adsense_host_api
adsense_host_api_v3
adsense_management_api
adsense_management_api_v1
adsense_management_api_v1.1
adsense_management_api_v1.2
adsense_management_api_v1.3
adsense_management_api_v1.4
advanced_apis
adwhirl
adwhirl_v3.1.1
adwords
AdWords Scripts
adwords_AdGroupCriterionService
adwords_api
adwords_api_v201302
adwords_api_v201306
adwords_api_v201309
adwords_api_v201402
adwords_api_v201406
adwords_api_v201409
adwords_api_v201502
adwords_api_v201506
adwords_api_v201509
adwords_api_v201601
adwords_api_v201603
adwords_api_v201605
adwords_api_v201607
adwords_api_v201609
adwords_api_v201702
adwords_api_v201705
adwords_api_v201708
adwords_api_v201710
adwords_api_v201802
adwords_api_v201806
adwords_api_v201809
adwords_api_workshops
adwords_BatchJobService
adwords_CampaignService
adwords_CreateAccountService
adwords_for_video
adwords_ManagedCustomerService
adwords_MutateJobService
adwords_ReportDefinitionService
adwords_scripts
adwords_v201109
adwords_v201206
adwords_v201209
adwords_v201302
adwords_v201306
adwords_v201309
adwords_v201601
adwords_v201605
adwords_v201607
adwords_v201609
adwords_v201702
adwords_v201802
adwords_v201806
adwords_v201809
alerting
amp
analytics
analyticsapi
android
android_layout
animation
announcement
annual developer survey
api
app_engine
asset_group
asset_group_listing_group_filter
asset_group_signal
assets
attribution_reporting_api
audiences
authentication
authorization
authorized_buyer
authorized_buyers
aw_reporting
awql
batch_processing
beacon_api
best_practices
beta
bid_manager_api
bid_modifiers
bidding
billing
budget_order_service
budgets
builders
bulk_upload
c#
caf_sdk
call_extensions
call_metrics
call_only
call_tracking
call-only
callout_extensions
campaign
CampaignCriterion
case_study
cast
certificates
certification
chart_tools
chrome
chromecast
click
click_tracking
click_type
click-to-download
clicks
client_libraries
client_library
cm360
code_examples
common_questions
conference
content
content_api
conversion
conversions
ConversionTrackerService
converted_clicks
creative_platforms
creatives
custom_fields
DAI
dart
dbm_api
debugging
decorators
deprecation
developer
dfa_ad_service
dfa_api
dfa_api_v118
dfa_creative_service
dfa_reporting_api
dfa_site_service
dfa_v1.16
dfa_v1.17
dfa_v1.18
dfa_v1.19
dfa_v1.20
dfp
dfp_api
dfp_appengine
dfp_creatives
dfp_inventory
dfp_mobile
dfp_pql
dfp_reports
dfp_sales
dfp_teams
dfp_v201111
dfp_v201201
dfp_v201203
dfp_v201204
dfp_v201206
dfp_v201208
dfp_v201211
dfp_v201302
dfp_v201308
dfp_v201608
dfp_v201711
display
display_network
display_select
display_smart_campaign
docs
dotnet
doubleclick
DoubleClick_Rich_Media
doubleclick_studio
drafts
dsa
dv360
dv360_api
dynamic_creative
enhanced_campaigns
entity_read_files
erf
error handling
eta
examples
excluded_placement_lists
exoplayer
expanded_text_ads
experiment
experiments
faq
feedback
feeds
firebase
flash
flash_sdk
floc
forecast_service
games
gaql
gclid
gdc
gdl
geo_targets
geotargeting
gmail_ads
gmail_image_ads
gmail_multi_product_ads
gmail_single_promotion_ads
GMF
gmp
golang
google_ads
google_ads_api
google_ads_api_migration_workshop
google_ads_api_v0
google_ads_api_v0_1
google_ads_api_v0_3
google_ads_api_v0_4
google_ads_api_v0_5
google_ads_api_v0_6
google_ads_api_v0_7
google_ads_api_v1_0
google_ads_api_v1_1
google_ads_api_v1_2
google_ads_api_v1_3
google_ads_api_v2_1
google_ads_api_v3_0
google_ads_api_v3_1
google_ads_api_v4
google_ads_api_v5
google_ads_api_v6
google_ads_scripts
google_ads_solutions
google_apis
google_apps_script
google_drive
google_play_services
google_plus
gpt
guide
guides
hangout
hotel_ads
hotel_campaigns
html5
html5_ads
https
i18n
ids
ima_android
ima_flash
ima_html5
ima_ios
ima_sdk
image
image_ads
implementation
impression_share
interstitial
interview
io13
iOS
iOS9
java_app_engine
java_dart_api
jdbc
keyword_optimizer
keywords
kotlin
labels
limits
line_item
linq
listing_groups
location_extensions
location_feeds
LocationExtensionOperand
LocationGroups
logging
manager_accounts
maps_api
marketplace
maximize
mcc
media
media_bundle
mediation_test_suite
merchant_api
migration
mobile
mobile_ads
mobile_ads_garage
mobile_ads_sdk
mobile_sites
mobile_speed
mobile_targeting
mobile_ux
monitoring
native
native_ads_express
new_features
oauth
oauth2
offline_conversions
OfflineConversionFeedService
open_source
openrtb
optimization
Performance Max
performance_max
performance_max_api_workshop
php
PLA
placements
PMax
policy
policy_violation
PQL
price_extension
privacy
privacy_sandbox
product_listing_ads
proguard
promotion_line
publisher_ads_audits
python
qa
quality_score
query_builder_blog_series
query_language
quota
rate_limiter
rate_sheet
RateExceededError
realtime_bidding
realtime_bidding_api
realtime_bidding_protocol
realtimebidding
recommendations
referer
release
remarketing
reporting
reports
responsive_ads
rewarded_video
rmf
ruby
sa360
sandbox
scripts
sdf
sdkless
search
search audience
search terms
search_audience
search_network
search_theme
selector
sendbeacon
service_accounts
shared_negative_keywords
shopping
simulations
sitelinks
smart
snds
spend
ssl
StepInsideAdWords
success_stories
suggested_ad_units
sunset
survey
swift
swiftui
target
target_cpa
targeting
template_ads
terms
test_accounts
test_network
testing
text_ads
text_asset_automation
tools
trials
turtledove
ui
unity
update
updates
upgrade
upgraded_urls
v201509
vast3
vcpm
video
viewable-cpm
webinar
workshop
workshops
wp8
xml
youtube
Archive
2024
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2023
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2022
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2021
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2020
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2019
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2018
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2017
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2016
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2015
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2014
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2013
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2012
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2011
Dec
Nov
Give us feedback in our developer product forums:
Google Ads API
Google Ads scripts
Google Ad Manager API
DCM API
Google Mobile Ads SDK
Google AdMob API
Google Interactive Media Ads SDK
Google Content API for Shopping
Authorized Buyers API