How to load data from Twitter Ads to Google BigQuery
Access your data on Twitter Ads
The first step in loading your Twitter Ads data to any kind of data warehouse solution is to access your data and start extracting it.
By using the Ads API program businesses can create, run and manage ad campaigns programmatically on Twitter. A big part of the API is also a rich reporting system that helps you tailor your campaigns by selecting different targeting options and placement parameters. You can also retrieve detailed statistics on the performance of your campaigns by generating reporting or historical backfills.
Using this API, a user can retrieve details associated with the current account regarding the following resources:
- Lineitem Apps & Lineitems
- Promoted Accounts & Promoted tweets reference
- Scheduled promoted tweets reference
- Funding Instruments
- Media Creatives
- Targeting Criteria
- Account Media
- Scheduled/Promoted/Organic/Draft Tweets
Various reports can also be fetched as long as they are valid combinations between an entity and segmentation types, such as:
- Reach Campaigns Report
- Reach Funding Instruments Report
- Auction Insights Report
In addition to the above, the things that you have to keep in mind when dealing with the Twitter API, are:
- Rate limits. There is no restriction for concurrent API calls. There is a restriction for API calls per endpoint in 15-minute windows. However, in general, limits are generous for most endpoints and should not impede use cases.
- Authentication. You authenticate on Twitter Ads using OAuth.
- Pagination. There is a pagination ability for retrieving data in some resources, with a page count that varies from 200 to 1000 depending on the specific resource endpoint. There is also a sorting method for retrieving data in some resources.
About Twitter Ads
Twitter Ads is a self-service advertising platform, announced in April 2013 by Twitter. The ads launched within this platform belong to one of the following categories:
- Promoted Trends. A sponsored topic on the top of the trending news section is supposed to be one of the most discussed topics at the given time.
- Promoted Accounts. Accounts that are put at top of the suggested accounts box. They are usually a way for brands to gain more followers.
- Promoted Tweets. Tweets that shown first in the search results of related topics.
Transform and prepare your Twitter Ads data for Google BigQuery
After you have accessed your data on Twitter Ads, you will have to transform it based on two main factors,
- The limitations of the database that the data will be loaded onto
- The type of analysis that you plan to perform
Each system has specific limitations on the data types and data structures that it supports. If for example, you want to push data into Google BigQuery, then you can send nested data like JSON directly.
Of course, when you are dealing with tabular data stores, like Microsoft SQL Server, this is not an option. Instead, you will have to flatten out your data, just as in the case of JSON, before loading it into the database.
Also, you have to choose the right data types. Again, depending on the system that you will send the data to and the data types that the API exposes to you, you will have to make the right choices. These choices are important because they can limit the expressivity of your queries and limit your analysts on what they can do directly out of the database.
Load data from Twitter Ads to Google BigQuery
If you want to load Twitter Ads data to Google BigQuery, you have to use one of the following supported data sources.
- Google Cloud Storage
- Sent data directly to BigQuery with a POST request
- Google Cloud Datastore Backup
- Streaming insert
- App Engine log files
- Cloud Storage logs
From the above list of sources, 5 and 6 are not applicable in our case.
For Google Cloud Storage, you first have to load your data into it, there are a few options on how to do this, for example, you can use the console directly as it is described here and do not forget to follow the best practices.
Another option is to post your data through the JSON API, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. In its simplest case, it’s just a matter of one HTTP POST request using a tool like CURL or Postman.
After you have loaded your data into Google Cloud Storage, you have to create a Load Job for BigQuery to actually load the data into it, this Job should point to the source data in Cloud Storage that have to be imported, this happens by providing source URIs that point to the appropriate objects.
The best way to load data from Twitter Ads to BigQuery
So far we just scraped the surface of what you can do with BigQuery and how to load data into it. Things can get even more complicated if you want to integrate data coming from different sources.
Are you striving to achieve results right now?
Instead of writing, hosting, and maintaining a flexible data infrastructure use RudderStack that can handle everything automatically for you.
RudderStack with one click integrates with sources or services, creates analytics-ready data, and syncs your Twitter Ads to BigQuery right away.