By Rudderstack Team

How to load data from Google AdWords to SQL Data Warehouse

Marketing is becoming heavily data-driven. How can you get all marketing data like Facebook Ads or Bing Ads or Google AdWords in one place like SQL Data Warehouse? This post is a guide to help you define a process or pipeline, to load data from Google AdWords to SQL Data Warehouse for further analysis.

We will see how to access and extract data from Google AdWords through its API and load it into SQL Data Warehouse. This process requires you to write the code to get the data and ensure that it will run every time new data are generated. Alternatively, you can use RudderStack that can handle this kind of problem automatically for you.

About Google AdWords

Google AdWords is an online advertising service by Google for businesses wanting to display ads on Google and its advertising network. At its core, Google AdWords is a Real-Time Bidding system where advertisers compete to display their advertising material to web users using Google products like its search engine. Programmatic and instantaneous auctions are performed, similar to how financial markets operate. Among the benefits of AdWords are:

  • Pay-per-click – advertisers pay only for ads that the user has clicked.
  • Any budget – You can start with any budget, although you have to be aware of AdWords’ Real-Time Bidding nature, which means that the effectiveness of your campaigns is linked to what your competitors are also willing to pay.
  • Reach – you can reach billions of people worldwide.

Additionally, Google AdWords, just like every other product from Google, has excellent support, and it exposes a rich ecosystem of tools and APIs that you can use to get the most out of their services.

About Microsoft Azure SQL Data Warehouse

SQL Data Warehouse is the data warehousing solution you can use if you are a user of Microsoft Azure. It’s an elastic data warehousing as a service solution, emphasizing its enterprise focus. It also speaks SQL like the previous two solutions, and it supports querying both relational and non-relational data. It offers a number of enterprise-class features like support for hybrid cloud installations and strong security. It’s probably the less mature solution compared to the two others though, it’s still in “Preview” mode although accessible to existing Azure subscribers.

Extract your data from Google AdWords

The AdWords API allows applications to interact directly with the AdWords platform. You can build applications to more efficiently manage large or complex AdWords accounts and campaigns. Contrary to the rest of the APIs that we have covered in this series of posts, the Google AdWords API is implemented only using the SOAP protocol. It doesn’t offer a RESTful web implementation.

Nevertheless, they offer a number of client libraries that you can use for your language or framework of choice. They officially support clients in the following languages:

  • Java
  • .Net
  • PHP
  • PERL
  • Python
  • Ruby

The AdWords API is a complex product that exposes a lot of functionality to the user, ranging from reporting to do the bidding and programmatic advertisement. As this post’s scope is the extraction of data from it, we’ll focus only on that part of the Google AdWords API to load the data to a data warehouse for further analysis.

There are many ways of interacting with the data that adWords API gathers. One way is to link your Google Analytics and AdWords accounts and actually enrich your analytics data with data coming from AdWords. If you have the luxury to afford a Google analytics premium account, the other possible way is to load your data directly to Google BigQuery. From there, you can either do your analysis from BigQuery or export your data to another data warehouse.

We’ll assume that you do not have a Google Analytics premium account, to be honest, if you had you wouldn’t be looking at this post anyway, but you still want to extract data and load it to your own data warehouse solution. To do that, we’ll utilize the Report related functionality of the AdWords API. The API supports a huge number of reports that you can request, and it is possible to change the granularity of your results by passing specific parameters. Defining what kind of data you want to get back as part of your report can be done in two different ways.

  • Using an XML-based report definition.
  • Using an AWQL-based report definition.

If you want to use an XML-based report definition you have to include a parameter named “__rdxml” that will contain an XML serialized definition of the report you want to retrieve.

<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201509">
 <selector>
   <fields>CampaignId</fields>
   <fields>Id</fields>
   <fields>Impressions</fields>
   <fields>Clicks</fields>
   <fields>Cost</fields>
   <predicates>
     <field>Status</field>
     <operator>IN</operator>
     <values>ENABLED</values>
     <values>PAUSED</values>
   </predicates>
 </selector>
 <reportName>Custom Adgroup Performance Report</reportName>
 <reportType>ADGROUP_PERFORMANCE_REPORT</reportType>
 <dateRangeType>LAST_7_DAYS</dateRangeType>
 <downloadFormat>CSV</downloadFormat>
</reportDefinition>

AWQL is a SQL-like language for performing queries against most common AdWords API services. Any service with a query method is supported; queryable fields for each service are listed here.

As a comparison you can see the difference between using XML and AWQL below:

XML

<serviceSelector>
   <fields>Id</fields>
   <fields>Name</fields>
   <predicates>
       <field>Status</field>
       <operator>EQUALS</operator>
       <values>ENABLED</values>
   </predicates>
   <ordering>
       <field>Name</field>
       <sortOrder>ASCENDING</sortOrder>
   </ordering>
   <paging>
       <startIndex>0</startIndex>
       <numberResults>50</numberResults>
   </paging>
</serviceSelector>

AWQL

CampaignPage p = campaignService.query("SELECT Id, Name
                                       WHERE Status = 'ENABLED'
                                       ORDER BY Name
                                       DESC LIMIT 0,50");

As we can see, the Google AdWords API has a very expressive way of defining what data we want to get from it and various options to do that. If you feel more comfortable with SQL-like languages, you can use AWQL, or if you prefer XML, you can use that for defining your reports.

Regarding the format of the results you get from the API, there are also multiple options supported.

  • CSVFOREXCEL – Microsoft Excel compatible format
  • CSV – comma separated output format
  • TSV – tab separated output format
  • XML – xml output format
  • GZIPPED-CSV – compressed csv
  • GZIPPED-XML – compressed xml

Google AdWords exposes a very rich API which offers you the opportunity to get very granular data about your accounting activities and use it for analytic and reporting purposes. This richness comes with a price though many complex resources have to be handled through an also complex protocol.

Load Data from Google AdWords to SQL Data Warehouse

SQL Data Warehouse support numerous options for loading data, such as:

  • PolyBase
  • Azure Data Factory
  • BCP command-line utility
  • SQL Server integration services

As we are interested in loading data from online services by using their exposed HTTP APIs, we will not consider the usage of BCP command-line utility or SQL server integration in this guide. We’ll consider the case of loading our data as Azure storage Blobs and then use PolyBase to load the data into SQL Data Warehouse.


Accessing these services happens through HTTP APIs. APIs play an important role in both the extraction and the loading of data into our data warehouse. You can access these APIs by using a tool like CURL, Postman or Apirise. Or use the libraries provided by Microsoft for your favorite language. Before you upload any data, you have to create a container that is similar as a concept to the Amazon AWS Bucket, creating a container is a straightforward operation, and you can do it by following the instructions found on the Blog storage documentation from Microsoft. As an example, the following code can create a container in Node.js.

lobSvc.createContainerIfNotExists('mycontainer', function(error, result, response){
 if(!error){
  // Container exists and allows
  // anonymous read access to blob
  // content and metadata within this container
 }
});

After the creation of the container you can start uploading data to it by using again the given SDK of your choice in a similar fashion:

blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob', 'test.txt', function(error, result, response){
 if(!error){
  // file uploaded
 }
});

When you are done putting your data into Azure Blobs, you can load it into SQL Data Warehouse using PolyBase. To do that, you should follow the directions in the Load with PolyBase documentation. In summary, the required steps to do it are the following:

  • create a database master key
  • create a database scoped credentials
  • create an external file format
  • create an external data source

PolyBase’s ability to transparently parallelize loads from Azure Blob Storage will make it the fastest loading data tool. After configuring PolyBase, you can load data directly into your SQL Data Warehouse by simply creating an external table that points to your data in storage and then mapping it to a new table within SQL Data Warehouse.

Of course, you will need to establish a recurrent process that will extract any newly created data from your service, load them in the form of Azure Blobs and initiate the PolyBase process for importing the data again into SQL Data Warehouse. One way of doing this is by using the Azure Data Factory service. In case you would like to follow this path, you can read some good documentation on how to move data to and from Azure SQL Warehouse using Azure Data Factory.

The best way to load data from Google AdWords to SQL Data Warehouse and possible alternatives

So far, we just scraped the surface of what can be done with Microsoft Azure SQL Data Warehouse and how to load data into it. The way to proceed relies heavily on the data you want to load, from which service they are coming from the requirements of your use case.
Things can get even more complicated if you want to integrate data coming from different sources. Instead of writing, hosting, and maintaining a flexible data infrastructure, a possible alternative is to use a product like RudderStack to automatically handle this kind of problem for you.
RudderStack integrates with multiple sources or services like databases, CRM, e-mail campaigns, analytics, and more.

Quickly and safely move all your data from Google AdWords into SQL Data Warehouse and start generating insights from your data.

RudderStack is the easiest way to automate powerful data integrations.

Try RudderStack Free Today