This post will help you with syncing your Google AdWords data to Amazon Redshift. By doing this you will be able to perform advanced analytics on a system that is designed for this kind of data, like Amazon Redshift. Alternatively, you can simplify the process of syncing data from Google AdWords to Amazon Redshift by using Blendo, where the whole process will be handled by Blendo and you can focus on what matters, the analysis of your data.
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 and 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 for the following languages
The AdWords API is a quite complex product that exposes a lot of functionality to the user, ranging from reporting to do bidding and programmatic advertisement. As the scope of this post is the extraction of data from it, with the aim of loading the data to a data warehouse for further analysis, we’ll focus only on that part of the Google AdWords API.
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 the data of your analytics with data coming from AdWords. The other possible way, if you have the luxury to afford a Google analytics premium account, 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 utilise 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 serialised 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 bellow:
<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>
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, a large number of complex resources that have to be handled through an also complex protocol.
About Google AdWords
Google AdWords is an online advertising service by Google for businesses wanting to display ads on Google and its advertising network. In its core Google AdWords is a Real Time Bidding system where advertisers compete to display their advertising material to web users who are 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 have been clicked by the user
- Any budget – You can start with any budget, although you have to be aware of the Real Time Bidding nature of AdWords, which means that the effectiveness of your campaigns are 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.
Prepare your Google AdWords Data for Amazon Redshift
Amazon Redshift is built around industry-standard SQL with added functionality to manage very large datasets and high-performance analysis. So, in order to load your data into it, you will have to follow its data model which is a typical relational database model. The data you extract from your data source should be mapped into tables and columns. Where you can consider the table as a map to the resource you want to store and columns the attributes of that resource. Also, each attribute should adhere to the datatypes that are supported by Redshift, currently the datatypes that are supported are the following:
- DOUBLE PRECISION
As your data are probably coming in a representation like JSON that supports a much smaller range of data types you have to be really careful about what data you feed into Redshift and make sure that you have mapped your types into one of the datatypes that is supported by Redshift. Designing a Schema for Redshift and mapping the data from your data source to it is a process that you should take seriously as it can both affect the performance of your cluster and the questions that you can answer. It’s always a good idea to have in your mind the best practices that Amazon has published regarding the design of a Redshift database. When you have concluded on the design of your database you need to load your data on one of the datasources that are supported as input by Redshift, these are the following:
About Amazon Redshift
Amazon Redshift is one of the most popular data warehousing solutions which is part of the Amazon Web Services (AWS) ecosystem. It is a petabyte scale, fully managed data warehouse as a service solution that runs on the cloud. It is SQL based and you can communicate with it as you would do with PostgreSQL, actually you can use the same driver although it would be better to use the drivers recommended by Amazon. You can connect either through JDBC or ODBC connections.
Load data from Google AdWords to Redshift
The first step to load your Google AdWords data to Redshift, is to put them in a source that Redshift can pull it from. As it was mentioned earlier there are three main data sources supported, Amazon S3, Amazon DynamoDB and Amazon Kinesis Firehose, with Firehose being the most recent addition as a way to insert data into Redshift.
To upload your data to Amazon S3 you will have to use the AWS REST API, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. The first task that you have to perform is to create a bucket, you do that by executing an HTTP PUT on the Amazon AWS REST API endpoints for S3. You can do this by using a tool like CURL or Postman . Or use the libraries provided by Amazon for your favorite language. You can find more information by reading the API reference for the Bucket operations on Amazon AWS documentation.
After you have created your bucket you can start sending your data to Amazon S3, using again the same AWS REST API but by using the endpoints for Object operations. As in the Bucket case you can either access the HTTP endpoints directly or use the library of your preference.
DynamoDB imports data again from S3, it adds another step between S3 and Amazon Redshift so if you don’t need it for other reasons you can avoid it.
Amazon Kinesis Firehose is the latest addition as a way to insert data into Redshift and offers a real-time streaming approach into data importing. The necessary steps for adding data to Redshift through Kinesis Firehose are the following:
- create a delivery stream
- add data to the stream
whenever you add new data to the stream, Kinesis takes care of adding these data to S3 or Redshift, again going through S3 in this case is redundant if your goal is to move your data to Redshift. The execution of the previous two steps can be performed either through the REST API or through your favorite library just as in the previous two cases. The difference here is that for pushing your data into the stream you’ll be using a Kinesis Agent.
Amazon Redshift supports two methods for loading data into it. The first one is by invoking an INSERT command. You can connect to your Amazon Redshift instance with your client, using either a JDBC or ODBC connection and then you perform an INSERT command for your data.
insert into category_stage values (12, 'Concerts', 'Comedy', 'All stand-up comedy performances');
The way you invoke the INSERT command is the same as you would do with any other SQL database, for more information you can check the INSERT examples page on the Amazon Redshift documentation.
Redshift is not designed for INSERT like operations, on the contrary, the most efficient way of loading data into it is by doing bulk uploads using a COPY command. You can perform a COPY command for data that lives as flat files on S3 or from an Amazon DynamoDB table. When you perform COPY commands, Redshift is able to read multiple files in simultaneously and it automatically distributes the workload to the cluster nodes and performs the load in parallel. As a command COPY is quite flexible and allows for many different ways of using it, depending on your use case. Performing a COPY on amazon S3 is as simple as the following command:
copy listing from 's3://mybucket/data/listing/' credentials 'aws_access_key_id=;aws_secret_access_key=';
For more examples on how to invoke a COPY command you can check the
The best way to load data from Google AdWords to Amazon Redshift and possible alternatives
So far we just scraped the surface of what can be done with Amazon Redshift 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 and the requirements of your use case. Things can get even more complicated if you want to integrate data coming from different sources.
A possible alternative, instead of writing, hosting and maintaining a flexible data infrastructure, is to use an ETL as a service product like Blendo that can handle this kind of problems automatically for you.
Blendo integrates with multiple sources or services like databases, CRM, email campaigns, analytics and more. Quickly and safely move all your data from Google Adwords into your data warehouse and start generating insights from your data.