Google Ads Connector for C#In this article you will learn how to quickly and efficiently integrate Google Ads data in C#. We will use high-performance Google Ads Connector to easily connect to Google Ads and then access the data inside C#. 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 Let's follow the steps below to see how we can accomplish that! Google Ads Connector for C# is based on ZappySys API Driver which is part of ODBC PowerPack. It is a collection of high-performance ODBC drivers that enable you to integrate data in SQL Server, SSIS, a programming language, or any other ODBC-compatible application. ODBC PowerPack supports various file formats, sources and destinations, including REST/SOAP API, SFTP/FTP, storage services, and plain files, to mention a few. |
Connect to Google Ads in other apps
|
Create ODBC Data Source (DSN) based on ZappySys API Driver
Step-by-step instructions
To get data from Google Ads using C# we first need to create a DSN (Data Source) which will access data from Google Ads. We will later be able to read data using C#. Perform these steps:
-
Install ZappySys ODBC PowerPack.
-
Open ODBC Data Sources (x64):
-
Create a User data source (User DSN) based on ZappySys API Driver
ZappySys API Driver-
Create and use User DSN
if the client application is run under a User Account.
This is an ideal option
in design-time , when developing a solution, e.g. in Visual Studio 2019. Use it for both type of applications - 64-bit and 32-bit. -
Create and use System DSN
if the client application is launched under a System Account, e.g. as a Windows Service.
Usually, this is an ideal option to use
in a production environment . Use ODBC Data Source Administrator (32-bit), instead of 64-bit version, if Windows Service is a 32-bit application.
-
Create and use User DSN
if the client application is run under a User Account.
This is an ideal option
-
When the Configuration window appears give your data source a name if you haven't done that already, then select "Google Ads" from the list of Popular Connectors. If "Google Ads" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:
GoogleAdsDSNGoogle Ads -
Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.
User accounts represent a developer, administrator, or any other person who interacts with Google APIs and services. User accounts are managed as Google Accounts, either with Google Workspace or Cloud Identity. They can also be user accounts that are managed by a third-party identity provider and federated with Workforce Identity Federation. [API reference]
Steps how to get and use Google Ads credentials
Follow these steps on how to create Client Credentials (User Account principle) to authenticate and access Google Ads API in SSIS package or ODBC data source:
WARNING: If you are planning to automate processes, we recommend that you use a Service Account authentication method. In case, you still need to use User Account, then make sure you use a system/generic account (e.g.automation@my-company.com
). When you use a personal account which is tied to a specific employee profile and that employee leaves the company, the token may become invalid and any automated processes using that token will start to fail.Manager Account Setup - Obtain Developer Token
To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.
- Create a Google Ads Manager account (formally known as MCC).
- Apply for Production data access (Upgrade Developer Token access Level to Basic).
- Link manager account with Google Ads Account.
- Create a new Project and obtain Client Id and Client Secret
Step-1: Create a Google Ads Manager account (formally known as MCC)
Very first step to access Google Ads API for your own account or someone else account, you will need something called Google Manager Account (formally known as MCC). It will look like a Normal Google Ads Account with some difference so dont get confused if you see similar interface as Ads account.
Click here to see detailed instructions on how to create a manager account. Once you created a manager account, you can login or switch between Ads account and Manager account like below. You can identify manager account using "Manager" word next to the account id when you click Profile dropdown.Step-2: Obtain Developer Token
Once you have created and logged in to your Google Ads Manager Account (formally known as MCC) we are ready for the next step which is obtain Developer Token. To access Google Ads API you need to pass developer token in each API call. By default Developer Token is only allowed to access Sandbox (Test) account. If you like to access Production data (Live Ads Account) then you must apply for Basic Access by clicking link under Access Level (See next section for information).
Here is how to can obtain your Developer Token.- Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
- Click on Admin icon
- Click on API Center (This option will be missing if you are logged in to Regular Ads account as Client and not using Manager Account (MMC)
- Expand Access Level, Click Apply for Basic Access if it says "Test". By default Developer Token is created with Test Account access only. To access Production Ads account you must apply for higher access level. Must be Basic or Standard (not Test). After click the link you will see form with few questions, please fill out that and submit the form. Apploval process may take 3-5 days (or longer in some cases if you did not provide enough information).
- If your token is already approved for the basic access then copy the token and paste on the Google Ads Connector - Connection UI (For Developer Token property)
Link Manager Account to Google Ads Account
After you have manager account ready, next step is to link manager account with Google Ads Account. You have to send invitation from Manager account to access Google Ads account (it can be your own account or someone else). Here is how to send invite to link Google Ads account.- Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
- Click on Accounts icon > Sub-account settings > Send Link Request
- Click on Add Sign (+) and select + Link existing account option
- When prompted enter Account Id(s) you like to link with this Manager Account.
- Click Send Request. You can find Ad Account Id usually at the Top-Right corner after you login to the Google Ads account.
- Now ask Google Ads Account owner to check email. Click Accept Invitation link in the email (If prompted login as Google Ads Account owner).
-OR-
Another way to see Invitation, Login to Google Ads account (Or Switch from the Top-Right corner by clicking Profile icon). Go to Admin icon > Access and security > Managers Tab. Find the pending invitation and click ACCEPT. - That's it. Now your Manager account is linked to the Google Ads account
Obtain ClientId and ClientSecret
Step-1: Create project
This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:
-
First of all, go to Google API Console.
-
Then click Select a project button and then click NEW PROJECT button:
-
Name your project and click CREATE button:
-
Wait until the project is created:
- Done! Let's proceed to the next step.
Step-2: Enable Google Ads API
In this step we will enable Google Ads API:
-
Select your project on the top bar:
-
Then click the "hamburger" icon on the top left and access APIs & Services:
-
Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:
-
In the search bar search for
Ads
and then locate and select Google Ads API: -
Enable Google Ads API:
- Done! Let's proceed to the next step.
Step-3: Create OAuth application
-
First of all, click the "hamburger" icon on the top left and then hit VIEW ALL PRODUCTS:
-
Then access Google Auth Platform to start creating an OAuth application:
-
Start by pressing GET STARTED button:
-
Next, continue by filling in App name and User support email fields:
-
Choose Internal option, if it's enabled, otherwise select External:
-
Optional step if you used
Internal
option in the previous step. Nevertheless, if you had to useExternal
option, then click ADD USERS to add a user: -
Then add your contact Email address:
-
Finally, check the checkbox and click CREATE button:
- Done! Let's create Client Credentials in the next step.
Step-4: Create Client Credentials
-
In Google Auth Platform, select Clients menu item and click CREATE CLIENT button:
-
Choose
Desktop app
as Application type and name your credentials: -
Continue by opening the created credentials:
-
Finally, copy Client ID and Client secret for the later step:
- Done! We have all the data needed for authentication, let's proceed to the last step!
Step-5: Configure connection
-
Now go to SSIS package or ODBC data source and use previously copied values in User Account authentication configuration:
- In the ClientId field paste the Client ID value.
- In the ClientSecret field paste the Client secret value.
- In the DeveloperToken field paste the Developer Token value.
-
Press Generate Token button to generate Access and Refresh Tokens.
-
Finally, click Test Connection to confirm the connection is working.
- Done! Now you are ready to use Google Ads Connector!
Fill in all required parameters and set optional parameters if needed:
GoogleAdsDSNGoogle AdsUser Account [OAuth]https://googleads.googleapis.com/[$ApiVersion$]Required Parameters UseCustomApp Fill-in the parameter... CustomerId (without dash e.g. 2125557752) Fill-in the parameter... DeveloperToken Fill-in the parameter... Optional Parameters ClientId ClientSecret Scope https://www.googleapis.com/auth/adwords Login CustomerId (without dash e.g. 2125557752) Linked CustomerId (without dash e.g. 2125557752) API Version v19 RetryMode RetryWhenStatusCodeMatch RetryStatusCodeList 429 RetryCountMax 5 RetryMultiplyWaitTime True Redirect URL (Only for Web App) Service accounts are accounts that do not represent a human user. They provide a way to manage authentication and authorization when a human is not directly involved, such as when an application needs to access Google Cloud resources. Service accounts are managed by IAM. [API reference]
Steps how to get and use Google Ads credentials
To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.
- Create a Manager account.
- Apply for Production data access (Upgrade Developer Token access Level to Basic).
- Link manager account with Google Ads Account.
- Inside Manager account apply for Basic API Access level so you can use Developer Token to access Live data (Production Ads account). Without Basic access level Developer Token can be only used for Test / Sandbox Ads account.
- Create a new Project and obtain Client Id and Client Secret
Manager Account Setup - Obtain Developer Token
To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.
- Create a Google Ads Manager account (formally known as MCC).
- Apply for Production data access (Upgrade Developer Token access Level to Basic).
- Link manager account with Google Ads Account.
- Create a new Project and obtain Service Account details
Step-1: Create a Google Ads Manager account (formally known as MCC)
Very first step to access Google Ads API for your own account or someone else account, you will need something called Google Manager Account (formally known as MCC). It will look like a Normal Google Ads Account with some difference so dont get confused if you see similar interface as Ads account.
Click here to see detailed instructions on how to create a manager account. Once you created a manager account, you can login or switch between Ads account and Manager account like below. You can identify manager account using "Manager" word next to the account id when you click Profile dropdown.Step-2: Obtain Developer Token
Once you have created and logged in to your Google Ads Manager Account (formally known as MCC) we are ready for the next step which is obtain Developer Token. To access Google Ads API you need to pass developer token in each API call. By default Developer Token is only allowed to access Sandbox (Test) account. If you like to access Production data (Live Ads Account) then you must apply for Basic Access by clicking link under Access Level (See next section for information).
Here is how to can obtain your Developer Token.- Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
- Click on Admin icon
- Click on API Center (This option will be missing if you are logged in to Regular Ads account as Client and not using Manager Account (MMC)
- Expand Access Level, Click Apply for Basic Access if it says "Test". By default Developer Token is created with Test Account access only. To access Production Ads account you must apply for higher access level. Must be Basic or Standard (not Test). After click the link you will see form with few questions, please fill out that and submit the form. Apploval process may take 3-5 days (or longer in some cases if you did not provide enough information).
- If your token is already approved for the basic access then copy the token and paste on the Google Ads Connector - Connection UI (For Developer Token property)
Link Manager Account to Google Ads Account
After you have manager account ready, next step is to link manager account with Google Ads Account. You have to send invitation from Manager account to access Google Ads account (it can be your own account or someone else). Here is how to send invite to link Google Ads account.- Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
- Click on Accounts icon > Sub-account settings > Send Link Request
- Click on Add Sign (+) and select + Link existing account option
- When prompted enter Account Id(s) you like to link with this Manager Account.
- Click Send Request. You can find Ad Account Id usually at the Top-Right corner after you login to the Google Ads account.
- Now ask Google Ads Account owner to check email. Click Accept Invitation link in the email (If prompted login as Google Ads Account owner).
-OR-
Another way to see Invitation, Login to Google Ads account (Or Switch from the Top-Right corner by clicking Profile icon). Go to Admin icon > Access and security > Managers Tab. Find the pending invitation and click ACCEPT. - That's it. Now your Manager account is linked to the Google Ads account
Obtain ClientId and ClientSecret
Step-1: Create project
This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:
-
First of all, go to Google API Console.
-
Then click Select a project button and then click NEW PROJECT button:
-
Name your project and click CREATE button:
-
Wait until the project is created:
- Done! Let's proceed to the next step.
Step-2: Enable Google Ads API
In this step we will enable Google Ads API:
-
Select your project on the top bar:
-
Then click the "hamburger" icon on the top left and access APIs & Services:
-
Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:
-
In the search bar search for
ads
and then locate and select Google Ads API: -
Enable Google Ads API:
- Done! Let's proceed to the next step.
Step-3: Create Service Account
Use the steps below to create a Service Account in Google Cloud:
-
First of all, go to IAM & Admin in Google Cloud console:
-
Once you do that, click Service Accounts on the left side and click CREATE SERVICE ACCOUNT button:
-
Then name your service account and click CREATE AND CONTINUE button:
-
Continue by clicking Select a role dropdown and start granting service account Project Viewer roles:
-
Find Project group and select Viewer role:
-
Finish adding roles by clicking CONTINUE button:
You can always add or modify permissions later in IAM & Admin. -
Finally, in the last step, just click button DONE:
-
Done! We are ready to add a Key to this service account in the next step.
Step-4: Add Key to Service Account
We are ready to add a Key (JSON or P12 key file) to the created Service Account:
-
In Service Accounts open newly created service account:
-
Next, copy email address of your service account for the later step:
-
Continue by selecting KEYS tab, then press ADD KEY dropdown, and click Create new key menu item:
-
Finally, select JSON (Engine v19+) or P12 option and hit CREATE button:
- Key file downloads into your machine. We have all the data needed for authentication, let's proceed to the last step!
Step-5: Give Permissions to Service Account
Now it's time to grant permission to Service Account we just created:
- Login to https://ads.google.com/aw/settings/account with Google Ads account credentials (If propmpted choose your Ads account).
-
Go to Admin section, Access and security, Click on Users tab.
- Click on Add Icon (+) and enter service account email address which you like to use for data access and choose permissions.
- That's it! Let's proceed to the configuration!
Step-6: Configure connection
-
Now go to SSIS package or ODBC data source and configure these fields in Service Account authentication configuration:
- In the Service Account Email field paste the service account Email address value you copied in the previous step.
- In the Service Account Private Key Path (i.e. *.json OR *.p12) field use downloaded key file path.
- Done! Now you are ready to use Google Ads Connector!
Each Google API Console project can be associated with the developer token from only one manager account. Once you make a Google Ads API request, the developer token is permanently paired to the Google API Console project. If you don't use a new Google API Console project, you'll get a DEVELOPER_TOKEN_PROHIBITED error when making a request. Unfortunatly there is no other way to Unlink old Developer Token from the API Project, so for now just create a new Project as a workaround to fix this error.Fill in all required parameters and set optional parameters if needed:
GoogleAdsDSNGoogle AdsService Account [OAuth]https://googleads.googleapis.com/[$ApiVersion$]Required Parameters Service Account Email Fill-in the parameter... Service Account Private Key Path (i.e. *.json OR *.p12) Fill-in the parameter... CustomerId (without dash e.g. 2125557752) Fill-in the parameter... DeveloperToken Fill-in the parameter... Optional Parameters Scope https://www.googleapis.com/auth/adwords Login CustomerId (without dash e.g. 2125557752) Linked CustomerId (without dash e.g. 2125557752) API Version v19 RetryMode RetryWhenStatusCodeMatch RetryStatusCodeList 429 RetryCountMax 5 RetryMultiplyWaitTime True Impersonate As (Google account email address) -
Once the data source has been configured, you can preview data. Select the Preview tab and use settings similar to the following to preview data:
-
Click OK to finish creating the data source.
Video instructions
Read data in C#
Using ODBC DSN
-
Create a new Console project and use this code to read the data:
"GoogleAdsDSN"; -
Press F5 to run the code and read the data:
-
Here is the code in text format:
using System; using System.Data.Odbc; namespace ConsoleApp { class Program { static void Main() { var dsn = "GoogleAdsDSN"; using (var conn = new OdbcConnection(String.Format("DSN={0}", dsn))) { conn.Open(); var cmd = new OdbcCommand("SELECT * FROM Products", conn); //Increase the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios cmd.CommandTimeout=600; // 600-Seconds var rdr = cmd.ExecuteReader(); while (rdr.Read()) { for (int i = 0; i < rdr.FieldCount; i++) { Console.Write("{0}\t", rdr[i]); } Console.WriteLine(); } } Console.ReadKey(); } } }
Using a full ODBC connection string
If you want to avoid being dependent on a DSN and creating multiple DSNs for each platform (x86, x64), then you can use a fully qualified connection string. Simply go to your DSN and copy the Connection String:
-
Open ODBC data source configuration and click Copy settings:
ZappySys API Driver - Google AdsRead / 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 AdsGoogleAdsDSN
-
The window opens, telling us the connection string was successfully copied to the clipboard:
-
Then in your C# code, pass the connection string as an argument when calling the OdbcConnection object's constructor, for example:
var connectionString = @"DRIVER={ZappySys API Driver};ServiceUrl=https://googleads.googleapis.com/[$ApiVersion$];Provider=GoogleAdWords;ScopeSeparator={space};RetryMode=[$RetryMode$];RetryStatusCodeList=[$RetryStatusCodeList$]"; using (var conn = new OdbcConnection(connectionString)) { // your code goes here }
Limitations of using a full connection string
Despite using a full ODBC connection string may be very convenient it comes with a limitation: it's length is limited to 1024 symbols (or sometimes more). It usually happens when API provider generates a very long Refresh Token when OAuth is at play. If you are using such a long ODBC connection string, you may get this error:
"Connection string exceeds maximum allowed length of 1024"
But there is a solution to this by storing the full connection string in a file. Follow the steps below to achieve this:
- Open your ODBC data source.
- Click Copy settings button to copy a full connection string (see the previous section on how to accomplish that).
- Then create a new file, let's say, in C:\temp\odbc-connection-string.txt.
- Continue by pasting the copied connection string into a newly created file and save it.
-
Finally, the last step! Just construct a shorter ODBC connection string using this format:
DRIVER={ZappySys API Driver};SettingsFile=C:\temp\odbc-connection-string.txt
- Our troubles are over! Now you should be able to use this connection string in C# with no problems.
Advanced topics
Create Custom Stored Procedure in ZappySys Driver
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
-
Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
-
Enter the desired Procedure name and click on OK:
-
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>';
-
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';
-
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([LINKED_SERVER_TO_GOOGLE_ADS_IN_DATA_GATEWAY], 'EXEC usp_get_orders @fromdate=''1996-07-30''')
-
Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
Create Custom Virtual Table in ZappySys Driver
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.
-
Go to Custom Objects Tab and Click on Add button and Select Add Table:
-
Enter the desired Table name and click on OK:
-
And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.
-
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'
-
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"
-
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([LINKED_SERVER_TO_GOOGLE_ADS_IN_DATA_GATEWAY], 'EXEC [usp_get_orders] ''1996-01-01''')
-
Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
Actions supported by Google Ads Connector
Google Ads Connector support following actions for REST API integration. If some actions are not listed below then you can easily edit Connector file and enhance out of the box functionality.Parameter | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Filter |
|
||||||||||
Enter Query (i.e. GAQL sql) |
|
Parameter | Description |
---|---|
Resource |
|
Parameter | Description |
---|---|
Resource |
|
Parameter | Description |
---|---|
Resource |
|
Parameter | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Filter |
|
||||||||||
Resource |
|
||||||||||
Attributes (Leave blank to select all) |
|
||||||||||
Segments (Group By) |
|
||||||||||
Metrics (Aggregate Fields) |
|
||||||||||
Where Clause |
|
||||||||||
OrderBy Clause |
|
||||||||||
Limit Clause (i.e. Max Rows) - Blank means all rows |
|
Parameter | Description | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Url |
|
||||||||||||||||||||||||||
Body |
|
||||||||||||||||||||||||||
IsMultiPart |
|
||||||||||||||||||||||||||
Filter |
|
||||||||||||||||||||||||||
Headers |
|
Parameter | Description |
---|---|
Url |
|
IsMultiPart |
|
Filter |
|
Headers |
|
Google Ads Connector Examples for C# Connection
This page offers a collection of SQL examples designed for seamless integration with the ZappySys API ODBC Driver under ODBC Data Source (36/64) or ZappySys Data Gateway, enhancing your ability to connect and interact with Prebuilt Connectors effectively.
Get Campaigns [ Read more... ]
Get all Campaigns for Google Ads account
SELECT * FROM get_campaigns
Get Customers [ Read more... ]
Get all customers you can query in your account
SELECT * FROM get_customers
Get campaign performance report by date [ Read more... ]
Get campaign performance data, group by date and campaign
SELECT * FROM get_report_campaign_performance_by_date WITH(ReportStartDate='monthstart', ReportEndDate='today-1d')
Get campaign performance report by month [ Read more... ]
Get campaign performance data, group by year, month and campaign
SELECT * FROM get_report_campaign_performance_by_month WITH(ReportStartDate='monthstart', ReportEndDate='today-1d')
Get keywords information (all campaigns / ad groups) [ Read more... ]
Get keywords for all campaigns and all ad groups (criterion_id is basically keyword_id)
select * from get_campaign_keywords
Get resource data (e.g. ad_group, ad_group_ad, keyword_view [ Read more... ]
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
*/
Query Google Ads data using GAQL (Google Ads Query Language) [ Read more... ]
Get Google Ads report data using GAQL (Google Ads Query Language) SQL query. Use Query builder from this link to select fields, segments, and metrics https://developers.google.com/google-ads/api/fields/v18/overview_query_builder (Click on Resource type you like to query) for SELECT, FROM and ORDER BY
--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query in Query='here'
SELECT
[campaign.id] as id,
[campaign.name] as name,
[metrics.impressions] as impressions,
[metrics.clicks] as clicks,
[metrics.costMicros] / 1000000 as cost --//API returns Unit in Micro so to get actual value divide by 1000000
FROM get_query_result
WITH(
Filter='$.results[*]'
, Query='SELECT campaign.id, campaign.name, metrics.impressions, metrics.clicks, metrics.cost_micros
FROM campaign
WHERE campaign.status = ''ENABLED''
AND metrics.impressions > 10
ORDER BY campaign.id
--LIMIT 1000
'
--Set different Customer Id here if not supplied in connection settings
--, CustomerId='1112223333'
)
Query Google Ads data (Simple Mode) - using #DirectSQL prefix [ Read more... ]
Get Google Ads report data using GAQL (Google Ads Query Language) - SQL query using simple mode. This example passes GAQL query to get_query_result endpoint with specifying endpoint details. You must prefix query with special tag #DirectSQL
#DirectSQL
--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query below
SELECT campaign.id, campaign.name, metrics.impressions, metrics.clicks, metrics.cost_micros
FROM campaign
--WHERE campaign.status = 'ENABLED'
--ORDER BY campaign.id
--LIMIT 1000
Query Google Ads Campaign Performance Data (Metrics / Segments) - using #DirectSQL prefix [ Read more... ]
Get Google Ads report data using GAQL (Google Ads Query Language) group by Date and Campaign. You must prefix query with special tag #DirectSQL
#DirectSQL
--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query below
SELECT
segments.date
, campaign.id
, campaign.name
, metrics.all_conversions
, metrics.average_cpc
, metrics.average_cost
, metrics.average_cpv
, metrics.average_cpm
, metrics.average_cpe
, metrics.average_impression_frequency_per_user
, metrics.average_page_views
, metrics.bounce_rate
, metrics.clicks
, metrics.conversions
, metrics.content_impression_share
, metrics.content_budget_lost_impression_share
, metrics.cost_micros
, metrics.cost_per_all_conversions
, metrics.cost_per_conversion
, metrics.ctr
, metrics.engagement_rate
, metrics.engagements
--, metrics.general_invalid_click_rate
--, metrics.general_invalid_clicks
, metrics.impressions
, metrics.interaction_rate
, metrics.interactions
, metrics.invalid_clicks
, metrics.search_absolute_top_impression_share
, metrics.search_budget_lost_absolute_top_impression_share
, metrics.search_budget_lost_impression_share
, metrics.search_budget_lost_top_impression_share
, metrics.search_click_share
, metrics.search_impression_share
, metrics.video_view_rate
, metrics.video_quartile_p75_rate
, metrics.video_quartile_p50_rate
, metrics.video_quartile_p25_rate
, metrics.video_quartile_p100_rate
, metrics.video_views
, metrics.view_through_conversions
, metrics.unique_users
, metrics.top_impression_percentage
, metrics.search_rank_lost_top_impression_share
, metrics.search_rank_lost_impression_share
, metrics.search_rank_lost_absolute_top_impression_share
, metrics.search_top_impression_share
, metrics.search_exact_match_impression_share
, metrics.absolute_top_impression_percentage
, metrics.active_view_cpm
, metrics.active_view_ctr
, metrics.active_view_impressions
FROM campaign
WHERE segments.date BETWEEN '<<monthstart,FUN_TO_DATE>>' and '<<today-1d,FUN_TO_DATE>>'
--WHERE segments.date BETWEEN '2025-01-25' and '2025-02-25'
--AND WHERE campaign.status = 'ENABLED'
--ORDER BY segments.date,campaign.id
--LIMIT 1000
Conclusion
In this article we showed you how to connect to Google Ads in C# and integrate data without any coding, saving you time and effort. We encourage you to download Google Ads Connector for C# and see how easy it is to use it for yourself or your team.
If you have any questions, feel free to contact ZappySys support team. You can also open a live chat immediately by clicking on the chat icon below.
Download Google Ads Connector for C# Documentation
More integrations
Other connectors for C#
Other application integration scenarios for Google Ads
How to connect Google Ads in C#?
How to get Google Ads data in C#?
How to read Google Ads data in C#?
How to load Google Ads data in C#?
How to import Google Ads data in C#?
How to pull Google Ads data in C#?
How to push data to Google Ads in C#?
How to write data to Google Ads in C#?
How to POST data to Google Ads in C#?
Call Google Ads API in C#
Consume Google Ads API in C#
Google Ads C# Automate
Google Ads C# Integration
Integration Google Ads in C#
Consume real-time Google Ads data in C#
Consume real-time Google Ads API data in C#
Google Ads ODBC Driver | ODBC Driver for Google Ads | ODBC Google Ads Driver | SSIS Google Ads Source | SSIS Google Ads Destination
Connect Google Ads in C#
Load Google Ads in C#
Load Google Ads data in C#
Read Google Ads data in C#
Google Ads API Call in C#