This is legacy documentation, and may not be complete. To see the latest documentation, if you are a marketer, refer to the Marketers site. If you are a measurement partner, refer to the Measurement Partners site.
Click + Create query. The Analysis query templates page opens.
Optional: Preview template SQL by clicking
expand_moreExpand.
Select the template you would like to use by clicking Use template,
or click Blank to start from scratch.
Enter a name for your report.
Write or edit the query using BigQuery compatible
SQL. You can find available tables and fields and insert them into your
SQL from the Google tables tab.
Parameters make queries more flexible. For example, you may want to run
the same query over different campaigns. Rather than making duplicate
queries or hardcoding the campaign IDs before each execution, you can
configure a parameter that accepts one or more campaign IDs to be entered from
the Run card when you run a query. Using parameters keeps your code clean,
reduces your chances of introducing errors through editing, and makes it
possible for your query to be reused without editing. Parameters are
scoped to the query where they are created, so you can reuse a parameter
name in another query.
Enter a name in the Name field. You’ll use this name to reference the
parameter in the query text.
Use the drop-down menu to select the parameter type.
If you select array, an additional drop-down menu appears. Select the
array type in the drop-down menu.
Optional: Repeat steps 2-4 until you have added all the parameters you want.
Click Save
Use a parameter
In the query text, use the standard SQL parameter format, which is to
precede the parameter name with @. In the following example, the query
contains a parameter called @campaign_ids:
/* Parameters: * @campaign_ids (ARRAY of INT64): A list of campaign IDs * to conduct analysis on */WITHuser_reachAS(SELECTuser_id,count(*)ASnum_viewsFROMadh.google_ads_impressionsWHEREcampaign_idinUNNEST(@campaign_ids)GROUPBYuser_id)SELECTCOUNT(*)ASunique_users,COUNTIF(num_views=1)ASone_view,COUNTIF(num_views > 1ANDnum_views<=5)ASless_or_equal_five_views,COUNTIF(num_views > 5)ASmore_than_five_viewsFROMuser_reach
When you run the query, the New job dialog will contain a
Parameters field. Enter values for each parameter you've defined.
Remove a parameter
Open the query that has the parameter you want to delete.
Open the Properties tab.
In the Parameters card, Click
delete Delete next to the parameter you want to delete.
Click Save.
Reserved parameters
The following table lists parameters reserved by Ads Data Hub. You can use these
parameters in your queries, but you cannot create a parameter with the
same name as a reserved parameter.
start_date
date
The start date (inclusive) for the query job. A user-defined parameter
with this name will be ignored and replaced with the values set in the
New job dialog.
end_date
date
The end date (inclusive) for the query job. A user-defined parameter
with this name will be ignored and replaced with the values set in the
New job dialog.
time_zone
string
The time zone for the query job. A user-defined parameter with this
name will be ignored and replaced with the values set in the
New job dialog.
Filtered row summary
Filtered row summaries tally data that was filtered due to privacy checks. Data from filtered rows is summed and added to a catch-all row. While the filtered data can't be further analyzed, it provides a summary of how much data was filtered from the results.
Before running a query, ensure that you've given the service account
dataEditor permission to the dataset that will contain the output of your
joins.
Learn more about access control in BigQuery.
Navigate to the Queries tab in Ads Data Hub.
Click the name of the query you want to run.
Click play_arrowRun.
The expected number of bytes that the query will use shows at the
top of the page.
Select an ID in the Ads data from field. This should be the account ID
associated with the ads data you want to query. (If you would like to query
sandbox data, select ADH Sandbox Customer.)
If using a match table, select the match table in the Match table from
field.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-27 UTC."],[[["\u003cp\u003eAds Data Hub allows users to create, edit, and run SQL queries to analyze their ads data.\u003c/p\u003e\n"],["\u003cp\u003eUsers can create queries from templates or from scratch, utilizing parameters for flexibility and reusability.\u003c/p\u003e\n"],["\u003cp\u003eQueries can be run on real or sandbox data, with options to specify the data source, date range, and privacy settings.\u003c/p\u003e\n"],["\u003cp\u003eQuery results can be previewed within Ads Data Hub, and explored further in BigQuery, Google Sheets, or Data Studio.\u003c/p\u003e\n"],["\u003cp\u003eFiltered row summaries provide insights into the amount of data filtered due to privacy checks.\u003c/p\u003e\n"]]],["To create a query, navigate to the \"Queries\" tab, click \"+ Create query,\" select a template or start blank, name the report, and write/edit SQL. Parameters can be added by clicking \"Properties,\" then adding parameters and defining their types. To use a parameter, prefix its name with `@` in the query text. Queries can be run by navigating to the \"Queries\" tab, clicking the query name, specifying settings, and clicking \"Run\". Results can be viewed on the \"Jobs\" page, BigQuery, Sheets, or Data Studio.\n"],null,["# Write and run queries\n\nCreate a query\n--------------\n\n| **Note:** Not all users can create and edit queries. Learn more about [access\n| control](/ads-data-hub/guides/assign-access-by-role) in Ads Data Hub.\n\n1. Navigate to the **Queries** tab in [Ads Data Hub](https://%0Aadsdatahub.google.com/#).\n2. Click **+ Create query** . The **Analysis query templates** page opens.\n3. Optional: Preview template SQL by clicking expand_more **Expand**.\n4. Select the template you would like to use by clicking **Use template** , or click **Blank** to start from scratch.\n5. Enter a name for your report.\n6. Write or edit the query using [BigQuery compatible](https://cloud.google.com/bigquery/docs/reference/standard-sql/) SQL. You can find available tables and fields and insert them into your SQL from the **Google tables** tab.\n7. Optional: Configure [parameters](#parameters).\n8. Optional: Configure the [filtered row summary](#filtered_row_summary).\n9. Click **Save**.\n\n### Parameters\n\nParameters make queries more flexible. For example, you may want to run\nthe same query over different campaigns. Rather than making duplicate\nqueries or hardcoding the campaign IDs before each execution, you can\nconfigure a parameter that accepts one or more campaign IDs to be entered from\nthe Run card when you run a query. Using parameters keeps your code clean,\nreduces your chances of introducing errors through editing, and makes it\npossible for your query to be reused without editing. Parameters are\nscoped to the query where they are created, so you can reuse a parameter\nname in another query.\n\n#### Parameter types\n\nThe following types of parameters are permitted:\n\n- `int64`\n- `float64`\n- `bool`\n- `string`\n- `date`\n- `timestamp`\n- `array`, of any of the permitted types\n\n#### Create a parameter\n\n1. Open a saved query, or [create a new one](#create_a_query).\n2. Click **Properties** \\\u003e **Parameters** \\\u003e **Add parameter**.\n3. Enter a name in the **Name** field. You'll use this name to reference the parameter in the query text.\n4. Use the drop-down menu to select the parameter type.\n - If you select array, an additional drop-down menu appears. Select the array type in the drop-down menu.\n5. Optional: Repeat steps 2-4 until you have added all the parameters you want.\n6. Click Save\n\n#### Use a parameter\n\nIn the query text, use the standard SQL parameter format, which is to\nprecede the parameter name with `@`. In the following example, the query\ncontains a parameter called `@campaign_ids`: \n\n /* Parameters:\n * @campaign_ids (ARRAY of INT64): A list of campaign IDs\n * to conduct analysis on */\n\n WITH user_reach AS (\n SELECT \n user_id,\n count(*) AS num_views\n FROM \n adh.google_ads_impressions\n WHERE \n campaign_id in UNNEST(@campaign_ids)\n GROUP BY \n user_id\n )\n SELECT\n COUNT(*) AS unique_users,\n COUNTIF(num_views = 1) AS one_view,\n COUNTIF(num_views \u003e 1 AND num_views \u003c= 5) AS less_or_equal_five_views,\n COUNTIF(num_views \u003e 5) AS more_than_five_views\n FROM \n user_reach\n\nWhen you [run the query](#run_a_query), the **New job** dialog will contain a\n**Parameters** field. Enter values for each parameter you've defined.\n\n#### Remove a parameter\n\n1. Open the query that has the parameter you want to delete.\n2. Open the **Properties** tab.\n3. In the **Parameters** card, Click delete **Delete** next to the parameter you want to delete.\n4. Click Save.\n\n#### Reserved parameters\n\nThe following table lists parameters reserved by Ads Data Hub. You can use these\nparameters in your queries, but you cannot create a parameter with the\nsame name as a reserved parameter.\n\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `start_date` | `date` The start date (inclusive) for the query job. A user-defined parameter with this name will be ignored and replaced with the values set in the **New job** dialog. |\n| `end_date` | `date` The end date (inclusive) for the query job. A user-defined parameter with this name will be ignored and replaced with the values set in the **New job** dialog. |\n| `time_zone` | `string` The time zone for the query job. A user-defined parameter with this name will be ignored and replaced with the values set in the **New job** dialog. | **Tip:** To prevent discrepancies when using timezones in your query, such as in `WHERE` clauses, you can use `time_zone` to match the timezone set in **New job**. It's also important to use the same timezone as the data source. |\n\n### Filtered row summary\n\n[Filtered row summaries](/ads-data-hub/guides/filtered-row-summary) tally data that was filtered due to privacy checks. Data from filtered rows is summed and added to a catch-all row. While the filtered data can't be further analyzed, it provides a summary of how much data was filtered from the results.\n| **Note:** Aggregation requirements apply to filtered row summaries themselves. If the resulting filtered row summary falls below aggregation requirements, the filtered row summary itself will be filtered.\n\nEdit a query\n------------\n\n1. Navigate to the **Queries** tab in [Ads Data Hub](https://%0Aadsdatahub.google.com/#).\n2. Click the name of the query you want to edit.\n3. Edit the query.\n4. Click **Save**.\n\nRun a query\n-----------\n\n| **Key Point:** You should write and test your queries using the [sandbox](/%0Aads-data-hub/guides/sandbox) before running them on real data. [Learn more\n| best practices for writing queries in Ads Data Hub](/ads-data-hub/guides/best-practices)\n\nBefore running a query, ensure that you've given the service account\n`dataEditor` permission to the dataset that will contain the output of your\njoins.\n[Learn more about access control in BigQuery](https://cloud.google.com/bigquery/docs/access-control#bigquery.dataEditor).\n\n1. Navigate to the **Queries** tab in Ads Data Hub.\n2. Click the name of the query you want to run.\n3. Click play_arrow **Run** .\n - The expected number of bytes that the query will use shows at the top of the page.\n4. Select an ID in the **Ads data from** field. This should be the account ID associated with the ads data you want to query. (If you would like to query sandbox data, select **ADH Sandbox Customer**.)\n5. If using a match table, select the match table in the **Match table from** field.\n6. Select the privacy mode. [Learn more about privacy\n modes](https://developers.google.com/ads-data-hub/marketers/guides/privacy-checks#privacy_modes).\n7. Specify where your query results should be saved in the **Destination\n table** field.\n8. Enter start and end dates to determine the date range of your query.\n9. Enter a time zone. This should match the time zone of the buying door.\n10. Optional: Enter values for any parameters.\n11. Click **Run**.\n\nView your results\n-----------------\n\nAfter your query finishes running, you can preview the results on the \"Jobs\"\npage. You can also explore the data in BigQuery, Sheets, or Data Studio.\n\n### Preview\n\nClick **Preview** within the finished job. The first 20 results will appear\nbelow the job.\n\n### BigQuery\n\nYour results are exported to BigQuery by default. Click **View table** to open\nBigQuery in a new window.\n\n### Sheets and Data Studio\n\nOpen the **Explore** dropdown menu and select **Explore with Sheets** or\n**Explore with Data Studio** from the options. This opens the data in a new\nwindow."]]