Google AdWords to Redshift

This page provides you with instructions on how to extract data from the Google AdWords API and load it into Amazon Redshift. (If this manual process is a bit more involved than you’d prefer, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

Pulling Data Out of Google AdWords

The first step of getting your AdWords data into AWS Redshift is actually pulling that data off of Google’s servers. You can do this using the AdWords API’s Reporting features, which are available to all AdWords customers. This is just a subset of that API’s functionality, which also includes the ability to manage ads.

You can also link your Google Analytics and Google AdWords accounts to allow the data to cross-pollinate. This can lead to much richer reporting due to the breadth of knowledge that exists in Google Analytics about the people who may have viewed or clicked your ads.

The data you extract from AdWords API reports can be quite granular, allowing you to see things like impressions, clickthrough rates, and CPC broken out by time period.

Preparing Google AdWords Data for Redshift

Here’s the tricky part: you need to map the data that comes out of each AdWords API result into a schema that can be inserted into a Redshift database. This means that, for each value in the response, you need to identify a predefined datatype (i.e. INTEGER, DATETIME, etc.) and build a table that can receive them. The AdWords API documentation can give you a good sense of what fields will be provided by each endpoint, along with their corresponding datatypes.

Inserting Google AdWords Data into Redshift

Once you have identified all of the columns you will want to insert, you can use the CREATE TABLE statement in Redshift to create a table that can receive all of this data.

With a table built, it may seem like the easiest way to add your data (especially if there isn’t much of it), is to build INSERT statements to add data to your Redshift table row-by-row. If you have any experience with SQL, this will be your gut reaction. But beware! Redshift isn’t optimized for inserting data one row at a time, and if you have any kind of high-volume data being inserted, you would be much better off loading the data into Amazon S3 and then using the COPY command to load it into Redshift.

Keeping Data Up-To-Date

So, now what? You’ve built a script that pulls data from AdWords and loads it into Redshift, but what happens tomorrow when you have thousands of new impressions?

The key is to build your script in such a way that it can also identify incremental updates to your data. You can set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

Other Data Warehouse Options

Redshift is totally awesome, but sometimes you need to start smaller or optimize for different things. In this case, many people choose to get started with Postgres, which is an open source RDBMS that uses nearly identical SQL syntax to Redshift. If you’re interested in seeing the relevant steps for loading this data into Postgres, check out AdWords to Postgres

Easier and Faster Alternatives

If all this sounds a bit overwhelming, don’t be alarmed. If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your AdWords data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Amazon Redshift data warehouse.