How to Get Resource Data (Query Attributes, Segments, Metrics) — Google Ads Connector for Power BI

Introduction

In this article we will delve deeper into Google Ads and Power BI integration, and will learn how to get resource data (query attributes, segments, metrics). We are continuing from where we left off. By this time, you must have created ODBC Data Source and connected to Google Ads. So, let's not waste time and begin.

Use Query Builder to generate SQL query

  1. The first thing you have to do is open Query Builder:

    ZappySys API Driver - Google Ads
    Read / write Google Ads data inside your app (e.g. Campaigns, Ad Groups, Keywords, Spending, Performance); perform many Google Ads operations without coding, just using easy to use high performance API Connector for Google Ads
    GoogleAdsDSN
    Open Query Builder in API ODBC Driver to read and write data to REST API
  2. Then simply select the Get Resource Data (Query Attributes, Segments, Metrics) endpoint (action).

  3. Continue by configuring the Required parameters. You can also set optional parameters too.

  4. Move on by hitting Preview Data button to preview the results.

  5. If you see the results you need, simply copy the generated query:

    Get Resource Data (Query Attributes, Segments, Metrics)
    Required Parameters
    Filter Select the value from the dropdown
    Resource Select the value from the dropdown
    Where Clause Select the value from the dropdown
    Optional Parameters
    Attributes (Leave blank to select all)
    Segments (Group By)
    Metrics (Aggregate Fields)
    OrderBy Clause
    Limit Clause (i.e. Max Rows) - Blank means all rows
    SELECT * FROM get_resource_data
    WITH (
    Resource='Campaign'
    
    --//Optional Parameters 
    --, Attributes='' --Keep blank to output all attributes
    --OR--
    --, Attributes='campaign.id~campaign.name~campaign.end_date' 
    
    --, Metrics='metrics.clicks~metrics.impressions'
    --, Segments='segments.year~segments.month'
    --//must supply where clause if certain segments used (e.g. date, year, month)
    --, Where='segments.date between ''<<yearstart,FUN_TO_DATE>>'' AND ''<<today-1d,FUN_TO_DATE>>'' '
    --, OrderBy='segments.year DESC, segments.month ASC'
    )
    
    /*
    --OR-- Simple Mode (Query by Resource Name in FROM clause).
    
    Step-1: Findout all resource you can query using  
    select * from get_resources
    
    Step-2: Use resource name like below (in FROM)
    Example resources (If data is missing it may throw error)
    
    select * from ad_group
    select * from ad_group_ad
    select * from ad_group_ad_asset_combination_view
    select * from ad_group_ad_asset_view
    select * from ad_group_asset
    select * from ad_group_audience_view
    select * from ad_schedule_view
    select * from age_range_view
    select * from android_privacy_shared_key_google_ad_group
    select * from android_privacy_shared_key_google_campaign
    select * from android_privacy_shared_key_google_network_type
    select * from asset
    select * from asset_field_type_view
    select * from asset_group
    select * from asset_group_asset
    select * from asset_group_product_group_view
    select * from asset_group_top_combination_view
    select * from asset_set_asset
    select * from asset_set_type_view
    select * from bidding_strategy
    select * from campaign
    select * from campaign_aggregate_asset_view
    select * from campaign_asset
    select * from campaign_audience_view
    select * from campaign_budget
    select * from campaign_group
    select * from campaign_search_term_insight
    select * from channel_aggregate_asset_view
    select * from click_view
    select * from content_criterion_view
    select * from conversion_action
    select * from customer
    select * from customer_asset
    select * from customer_search_term_insight
    select * from detail_placement_view
    select * from display_keyword_view
    select * from distance_view
    select * from dynamic_search_ads_search_term_view
    select * from expanded_landing_page_view
    select * from gender_view
    select * from geographic_view
    select * from group_placement_view
    select * from hotel_group_view
    select * from hotel_performance_view
    select * from hotel_reconciliation
    select * from income_range_view
    select * from keyword_view
    select * from landing_page_view
    select * from location_view
    select * from managed_placement_view
    select * from paid_organic_search_term_view
    select * from parental_status_view
    select * from per_store_view
    select * from performance_max_placement_view
    select * from product_group_view
    select * from search_term_view
    select * from shared_set
    select * from shopping_performance_view
    select * from shopping_product
    select * from smart_campaign_search_term_view
    select * from topic_view
    select * from travel_activity_group_view
    select * from travel_activity_performance_view
    select * from user_location_view
    select * from video
    select * from webpage_view
    */
    Query Builder
  6. That's it! You can use this query in Power BI.

Let's not stop here and explore SQL query examples, including how to use them in Stored Procedures and Views (virtual tables) in the next steps.

SQL query examples

Use these SQL queries in your Power BI data source:

How to Get resource data (e.g. ad_group, ad_group_ad, keyword_view

Get data for any resource

SELECT * FROM get_resource_data
WITH (
Resource='Campaign'

--//Optional Parameters 
--, Attributes='' --Keep blank to output all attributes
--OR--
--, Attributes='campaign.id~campaign.name~campaign.end_date' 

--, Metrics='metrics.clicks~metrics.impressions'
--, Segments='segments.year~segments.month'
--//must supply where clause if certain segments used (e.g. date, year, month)
--, Where='segments.date between ''<<yearstart,FUN_TO_DATE>>'' AND ''<<today-1d,FUN_TO_DATE>>'' '
--, OrderBy='segments.year DESC, segments.month ASC'
)

/*
--OR-- Simple Mode (Query by Resource Name in FROM clause).

Step-1: Findout all resource you can query using  
select * from get_resources

Step-2: Use resource name like below (in FROM)
Example resources (If data is missing it may throw error)

select * from ad_group
select * from ad_group_ad
select * from ad_group_ad_asset_combination_view
select * from ad_group_ad_asset_view
select * from ad_group_asset
select * from ad_group_audience_view
select * from ad_schedule_view
select * from age_range_view
select * from android_privacy_shared_key_google_ad_group
select * from android_privacy_shared_key_google_campaign
select * from android_privacy_shared_key_google_network_type
select * from asset
select * from asset_field_type_view
select * from asset_group
select * from asset_group_asset
select * from asset_group_product_group_view
select * from asset_group_top_combination_view
select * from asset_set_asset
select * from asset_set_type_view
select * from bidding_strategy
select * from campaign
select * from campaign_aggregate_asset_view
select * from campaign_asset
select * from campaign_audience_view
select * from campaign_budget
select * from campaign_group
select * from campaign_search_term_insight
select * from channel_aggregate_asset_view
select * from click_view
select * from content_criterion_view
select * from conversion_action
select * from customer
select * from customer_asset
select * from customer_search_term_insight
select * from detail_placement_view
select * from display_keyword_view
select * from distance_view
select * from dynamic_search_ads_search_term_view
select * from expanded_landing_page_view
select * from gender_view
select * from geographic_view
select * from group_placement_view
select * from hotel_group_view
select * from hotel_performance_view
select * from hotel_reconciliation
select * from income_range_view
select * from keyword_view
select * from landing_page_view
select * from location_view
select * from managed_placement_view
select * from paid_organic_search_term_view
select * from parental_status_view
select * from per_store_view
select * from performance_max_placement_view
select * from product_group_view
select * from search_term_view
select * from shared_set
select * from shopping_performance_view
select * from shopping_product
select * from smart_campaign_search_term_view
select * from topic_view
select * from travel_activity_group_view
select * from travel_activity_performance_view
select * from user_location_view
select * from video
select * from webpage_view
*/

get_resource_data endpoint belongs to <<[Dynamic Table]|~|googleAdsFields/|~|,FUN_REPLACE>> table(s), and can therefore be used via those table(s).

Stored Procedures and Views

Create Custom Stored Procedure

You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.

Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

  1. Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
    ZappySys Driver - Add Stored Procedure

  2. Enter the desired Procedure name and click on OK:
    ZappySys Driver - Add Stored Procedure Name

  3. Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver:
    Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

    CREATE PROCEDURE [usp_get_orders]
        @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>'
     AS
        SELECT * FROM Orders where OrderDate >= '<@fromdate>';
    

    ZappySys Driver - Create Custom Stored Procedure

  4. That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:

    Exec usp_get_orders '1996-01-01';

    ZappySys Driver - Execute Custom Stored Procedure

  5. Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
    As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.

    SELECT * FROM OPENQUERY([LS_TO_GOOGLE_ADS_IN_GATEWAY], 'EXEC usp_get_orders @fromdate=''1996-07-30''')

    ZappySys Driver - Generate SQL Server Query

  6. Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
    ZappySys Driver - Generate SQL Server Query

Create Custom Virtual Table

ZappySys API Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you don't have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.

If you're dealing with Microsoft Access and need to import data from an SQL query, it's important to note that Access doesn't allow direct import of SQL queries. Instead, you can create custom objects (Virtual Tables) to handle the import process.

Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.

  1. Go to Custom Objects Tab and Click on Add button and Select Add Table:
    ZappySys Driver - Add Table

  2. Enter the desired Table name and click on OK:
    ZappySys Driver - Add Table Name

  3. And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.

  4. Select the created table, Select Text Type AS SQL and write the your desired SQL Query and Save it and it will create the custom table in the ZappySys Driver:
    Here is an example SQL query for ZappySys Driver. You can insert Placeholders also. Read more about placeholders here

    SELECT
      "ShipCountry",
      "OrderID",
      "CustomerID",
      "EmployeeID",
      "OrderDate",
      "RequiredDate",
      "ShippedDate",
      "ShipVia",
      "Freight",
      "ShipName",
      "ShipAddress",
      "ShipCity",
      "ShipRegion",
      "ShipPostalCode"
    FROM "Orders"
    Where "ShipCountry"='USA'

    ZappySys Driver - Create Custom Table

  5. That's it now go to Preview Tab and Execute your custom virtual table query. In this example it will extract the orders for the USA Shipping Country only:

    SELECT * FROM "vt__usa_orders_only"

    ZappySys Driver - Execute Custom Virtual Table Query

  6. Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
    As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.

    SELECT * FROM OPENQUERY([LS_TO_GOOGLE_ADS_IN_GATEWAY], 'EXEC [usp_get_orders] ''1996-01-01''')

    ZappySys Driver - Generate SQL Server Query

  7. Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
    ZappySys Driver - Generate SQL Server Query

Get Resource Data (Query Attributes, Segments, Metrics) in Power BI

We are at the point where we can reiterate on how to use the SQL query, Stored Procedures or Views in Power BI:

  1. Once you open Power BI Desktop click Get Data to get data from ODBC:
    Power Bi Get Data

  2. A window opens, and then search for "odbc" to get data from ODBC data source:
    Power Bi ODBC Get Data

  3. Another window opens and asks to select a Data Source we already created. Choose GoogleAdsDSN and continue:

    GoogleAdsDSN
    Power Bi Select ZappySys Driver DSN

  4. Most likely, you will be asked to authenticate to a newly created DSN. Just select Windows authentication option together with Use my current credentials option:

    GoogleAdsDSN
    Power Bi DSN Authentication

  5. Finally, you will be asked to select a table or view to get data from. Select one and load the data!
    Power Bi Load DSN Table Data

More integrations

Other application integration scenarios for Google Ads

All
Data Integration
Database
BI & Reporting
Productivity
Programming Languages
Automation & Scripting
ODBC applications