Scrape Competitors' Google Ads Data Using Python
Data from Google Ads Transparency Center
Google Ads Transparency Center is a search engine for ads that are published through Google. It was created to empower users to make informed decisions about the ads and advertisers they see through Google - this means providing greater transparency about who the advertisers are, which ads they show, and what kind of ads are shown.
Marketers can leverage this tool as a powerful resource for analyzing competitors' Google ads and gaining deeper insights into their strategies across platforms. It offers the ability to explore ads on various topics by various companies and allows you to filter results by date, region, and creative format for more tailored findings.
About our Google Ads Transparency Center API
Our Google Ads Transparency Center API allows you to scrape ads information from the Google Ads Transparency Center page.
To begin scraping Google Ads data using our APIs, first, create a free account on serpapi.com. You'll receive one hundred free search credits each month to explore the API.
Let's head to our playground and see what a response for this API looks like:
Parts of the API Request
Search Query Parameters [At least one of these is required]
advertiser_id
: Specifies the Google Advertiser ID. You can input a single ID or multiple IDs separated by commas. Alternatively, a free-text search can be performed using the text parameter.
advertiser_id
is a unique identifier assigned to each advertiser within the Google Ads platform. This ID is critical in distinguishing between the different advertisers and accessing data specific to each one. text
: Allows you to perform a search based on a specific text, often related to a domain search within the context of Google Ads. This can be used instead of the advertiser_id
parameter.
text
parameter offers a different way to query ads, ideal for exploring a larger pool of advertisers connected to a specific domain or name. You can use the text
parameter when aiming to compare advertising strategies of multiple entities within the same industry or domain, or in cases where the specific advertiser_id
is unknown.Location Parameter
region
: Sets the geographic origin of the search results. By default, it retrieves results from all regions. Head to the Google Ads Transparency Center Regions page for a full list of supported regions.
region
parameter, by filtering ad data by specific geographic areas.Date Range Parameters
start_date
: Defines the beginning date for your search, formatted as YYYYMMDD.end_date
: Sets the ending date for your search results, also in the format YYYYMMDD.
Filter Parameter
creative_format
: Allows you to filter search results based on the format (e.g., text, image, video).
creative_format
parameter allows you to filter ad data based on the type of creative medium used. It includes three primary options: Text, Image, and Video. Pagination Parameters
num
: Determines the maximum number of search results to be returned. In a single API request, the default is 40 and the maximum is 100.next_page_token
: Used for paginating through search results, enabling you to retrieve the next set of results.
SerpApi Parameters
engine
: [Required] Set parameter to google_ads_transparency_center
to use the Google Ads Transparency Center API engine.
api_key
: [Required] Parameter defines the SerpApi private key to use.
There are some additional optional SerpApi parameters you can set - no_cache
, async
, and output
, which can help you get the desired results.
You can find the API documentation here.
Parts of the API Response
The response is comprised of four parts:
search_metadata
: This contains basic data about the search such as search_id
, status, endpoint details, timestamps, and more.search_parameters
: This specifies which API parameters have been selected for this particular search.search_information
: This contains extra information about the search such as total number of results, and more.ad_creatives
: This contains a list of ads scraped from Google Ads Transparency Center corresponding to the search parameters.
Scrape Google Ads Transparency Center with our API using Python
- Start by getting your SerpApi API Key from the Manage API Key page.
- [Optional but Recommended] Set your API key in an environment variable, instead of directly pasting it in the code. Refer here to understand more about using environment variables. For this tutorial, I have saved the API key in an environment variable named '
API_KEY
'. - Next, on your local computer, you need to install the
google-search-results
Python library:pip install google-search-results
A side note: You can use this library to scrape search results from other Google Search pages and other search engines, not just Google Ads Transparency Center.
More Information About Our Python Libraries
We have two separate Python libraries serpapi
and google-search-results
, and both work perfectly fine. However, serpapi
is a new one, and all the examples you can find on our website are from the old one google-search-results
. If you'd like to use our Python library with all the examples from our website, you should install the google-search-results
module instead of serpapi
.
For this blog post, I am using google-search-results
because all of our documentation references this one.
You may encounter issues if you have both libraries installed at the same time. If you have the old library installed and want to proceed with using our new library, please follow these steps:
- Uninstall
google-search-results
module from your environment. - Make sure that neither
serpapi
norgoogle-search-results
are installed at that stage. - Install
serpapi
module, for example with the following command if you're usingpip
:pip install serpapi
Example using Advertiser ID
In this instance, the code focuses on Amazon's advertising campaigns by utilizing its advertiser_id
and region
(region code: 2840 is USA). Here is an example in Python:
Set your params
according to the parameters I mentioned above, based on which advertiser(s) and region you are looking to get ad details for.
from serpapi import GoogleSearch
import os, json
params = {
"api_key": os.environ["API_KEY"],
"engine": "google_ads_transparency_center",
"advertiser_id": "AR12815412684405080065",
"region": "2840"
}
search = GoogleSearch(params)
results = search.get_dict()
print(results)
Let's take a look at the response:
{
"search_metadata": {
"id": "66f748abd11195f945c1522a",
"status": "Success",
"json_endpoint": "https://serpapi.com/searches/7938d618e515f1ba/66f748abd11195f945c1522a.json",
...
},
"search_parameters": {
"engine": "google_ads_transparency_center",
"advertiser_id": "AR12815412684405080065",
"region": "2840"
},
"search_information": {
"total_results": 200
},
"ad_creatives": [
{
"advertiser_id": "AR12815412684405080065",
"advertiser": "Amazon",
"ad_creative_id": "CR07747174253753008129",
"format": "image",
"image": "https://tpc.googlesyndication.com/archive/simgad/325087086685235926",
"width": 320,
"height": 568,
"first_shown": 1687330800,
"last_shown": 1727477863,
"details_link": "https://adstransparency.google.com/advertiser/AR12815412684405080065/creative/CR07747174253753008129?region=US"
},
{
"advertiser_id": "AR12815412684405080065",
"advertiser": "Amazon",
"ad_creative_id": "CR01040404322208186369",
"format": "video",
"link": "https://displayads-formats.googleusercontent.com/ads/preview/content.js?client=ads-integrity-transparency&obfuscatedCustomerId=5062881991&creativeId=695104140890&uiFeatures=12,54&adGroupId=162330631111&assets=%3DH4sIAAAAAAAAAOPS4eLkeHd_7u63zAI8QObq_--OtDILcACZ36e8WX2PWYARyDz9_d_2u0wCslLsHGcnnFm-gwnIuHevd-pjRiBj8ob1h-4wAxm3wSIAQ97LJFIAAAA&sig=ACiVB_yyOCVA1QUUZyHIr8qNMDcxNEIYgA&htmlParentId=fletch-render-4423862239514963880&responseCallback=fletchCallback4423862239514963880",
"first_shown": 1712161096,
"last_shown": 1727467260,
"details_link": "https://adstransparency.google.com/advertiser/AR12815412684405080065/creative/CR01040404322208186369?region=US"
},
...
...
],
"serpapi_pagination": {
"next_page_token": "CgoAP7zndwR2zo33EhCZuwoWBinS4s1gtbkAAAAAGgn8+K6f+IlLygE=",
"next": "https://serpapi.com/search.json?advertiser_id=AR12815412684405080065&engine=google_ads_transparency_center&next_page_token=CgoAP7zndwR2zo33EhCZuwoWBinS4s1gtbkAAAAAGgn8%2BK6f%2BIlLygE%3D®ion=2840"
}
}
By reviewing the results in the ad_creatives
section, you can uncover details about Amazon's advertising approach, favored ad formats, and ad writing techniques. Not only that, you can also collect and analyze valuable ad data, including timestamps for when the ad was shown, and help businesses optimize their advertising strategies and maximize return on investment.
Example using Text
The text parameter can be used when you are looking for more generic data instead of data for specific advertisers.
Let's consider another example where we specify the text parameter and get the data from our Google Ads Transparency Center API. In this instance, the code conducts a search for Youtube related ads by utilizing the text
field and region
(region code: 2840 is USA). Here is an example in Python:
Set your params
according to the parameters I mentioned above, based on which query of interest and region you are looking to get ad details for.
from serpapi import GoogleSearch
import os, json
params = {
"api_key": os.environ["API_KEY"],
"engine": "google_ads_transparency_center",
"region": "2840",
"text": "Youtube"
}
search = GoogleSearch(params)
results = search.get_dict()
print(results)
Let's take a look at the response:
{
"search_metadata": {
"id": "66f74c18cdf15587150c6ab5",
"status": "Success",
"json_endpoint": "https://serpapi.com/searches/c1ca1966069adace/66f74c18cdf15587150c6ab5.json",
...
},
"search_parameters": {
"engine": "google_ads_transparency_center",
"text": "Youtube",
"region": "2840"
},
"search_information": {
"total_results": 500000
},
"ad_creatives": [
{
"advertiser_id": "AR10629003163685879809",
"advertiser": "Lullify Inc",
"ad_creative_id": "CR12961410373826641921",
"format": "text",
"target_domain": "youtube.com",
"image": "https://tpc.googlesyndication.com/archive/simgad/11346475487747450235",
"width": 380,
"height": 248,
"first_shown": 1649270477,
"last_shown": 1727481706,
"details_link": "https://adstransparency.google.com/advertiser/AR10629003163685879809/creative/CR12961410373826641921?region=US&domain=Youtube"
},
{
"advertiser_id": "AR11265600398800453633",
"advertiser": "Mattel, Inc.",
"ad_creative_id": "CR00149470926394621953",
"format": "video",
"link": "https://displayads-formats.googleusercontent.com/ads/preview/content.js?client=ads-integrity-transparency&obfuscatedCustomerId=7485590662&creativeId=714664694114&uiFeatures=12,54&adGroupId=172991759252&overlay=%3DH4sIAAAAAAAAAPNS4OJPrShJLcpLzAnLTEnN90wR4uXizit29M9wM8jRNUkGAHQ7ZWQiAAAA&sig=ACiVB_zGvtGhhyt2JaWKOvkb9f7BuD9qow&htmlParentId=fletch-render-4815481174598331435&responseCallback=fletchCallback4815481174598331435",
"target_domain": "youtube.com",
"first_shown": 1727204081,
"last_shown": 1727481620,
"details_link": "https://adstransparency.google.com/advertiser/AR11265600398800453633/creative/CR00149470926394621953?region=US&domain=Youtube"
},
...
...
],
"serpapi_pagination": {
"next_page_token": "CgoAP7znc3V6e6g3EhAtmb8sfupAptTcpJQAAAAAGgn8+K2P+Fo5dn0=",
"next": "https://serpapi.com/search.json?engine=google_ads_transparency_center&next_page_token=CgoAP7znc3V6e6g3EhAtmb8sfupAptTcpJQAAAAAGgn8%2BK2P%2BFo5dn0%3D®ion=2840&text=Youtube"
}
}
Example Using Start Dates and End Dates
The start_date
and end_date
parameters allow you to identify ad strategies over a time period. By specifying the dates, you can narrow down your search to a defined timeframe. This feature is essential for filtering ad data from particular events, such as holidays, promotional sales, or tied to specific company announcements. For example, using the dates, you could filter for ads run during a labor day weekend to see what strategies company may be using for their campaigns during that time.
Let's look at a code example to get data on ads run during labor day weekend in United States (region code: 2840) for Nike:
Playground Link: https://serpapi.com/playground?engine=google_ads_transparency_center&text=nike®ion=2840&start_date=20240830&end_date=20240903
from serpapi import GoogleSearch
import os, json
params = {
"api_key": os.environ["API_KEY"],
"engine": "google_ads_transparency_center",
"region": "2840",
"text": "nike",
"start_date": "20240830",
"end_date": "20240903"
}
search = GoogleSearch(params)
results = search.get_dict()
print(results)
Analyzing the resulting data is useful to understand how the ads strategy changes during holiday season. Companies can gain data on how other competitors adapt ads to specific timings and they may be able to get insights into how effective these strategies are to convert ad viewers to customers.
Example using Creative Format
Ads can be created in various formats. The format can inform a lot about a company's marketing strategy and mediums of reaching their audience.
Text Ads are direct and to-the-point ways of communicating content. They are short and effective, and convey a clear message. Image Ads use visuals to engage people and create interest. Video Ads are also a useful tool to create interest using visuals but are more useful to tell a story or narrative behind a brand or product using those visuals.
Let's take a look at an example to get ads for a specific creative format. Here, I'll be getting video ads by Amazon.com Services LLC (advertiser_id
: AR15974021587678527489) in United States (region ID: 2840).
from serpapi import GoogleSearch
import os, json
def getAdsByCreativeFormat(creativeFormat):
params = {
"api_key": os.environ["API_KEY"],
"engine": "google_ads_transparency_center",
"advertiser_id": "AR15974021587678527489",
"region": "2840",
"creative_format": creativeFormat
}
search = GoogleSearch(params)
results = search.get_dict()
return results
available_formats = ["text", "image", "video"]
for format in available_formats:
print(getAdsByCreativeFormat(format))
Playground Example for getting only Video Ads for an advertiser: https://serpapi.com/playground?engine=google_ads_transparency_center&advertiser_id=AR15974021587678527489®ion=2840&creative_format=video
Implementing Pagination To Get Results On All Pages
The Google Ads Transparency Center response may include multiple pages of ads. To efficiently retrieve data and navigate through multiple pages, we can utilize the num
and next_page_token
parameters.
About the Parameters:
num
: This parameter determines the maximum number of search results to be returned. The default is 40. You can maximize the results received per request by setting num to a higher value. 100 is the maximum you can set num
to.
next_page_token
: This parameter is used for paginating through search results, enabling you to retrieve the next set of results.
Here is how you can set up the pagination flow:
Initial Request: Execute an initial request with your parameters of interest without next_page_token
.
Sequential Access Of Results On Following Pages: Fetch the next results page using the next_page_token
from the current response.
Last Page: Implement a check for the existence of next_page_token
. If it's not present, it indicates that this is the last page and there are no more pages to retrieve.
Let's look at an example where we can use pagination to get all the pages of ads for Nestle Australia Ltd (advertiser_id
: AR15820237500506439681) present on Google Ads Transparency Center in United States (region ID: 2840), using Pagination.
from serpapi import GoogleSearch
import os, json
def getAds(next_page_token):
params = {
"api_key": os.environ["API_KEY"],
"engine": "google_ads_transparency_center",
"advertiser_id": "AR15820237500506439681",
"region": "2840",
"num": "50"
}
search = GoogleSearch(params)
results = search.get_dict()
if next_page_token != None:
params["next_page_token"] = next_page_token
search = GoogleSearch(params)
results = search.get_dict()
print(len(results["ad_creatives"]))
if "serpapi_pagination" in results and "next_page_token" in results["serpapi_pagination"]:
getAds(results["serpapi_pagination"]["next_page_token"])
else:
print("All pages retrieved")
return
return
getAds(next_page_token=None)
The function getAds
starts with the first page of results. Above, I have set num
to 50, but you can change that to any number between 1 and 100. If next_page_token
is present in the response, the function calls itself recursively with the next_page_token
, and gets the next set of results. When there is no next_page_token
, it indicates that all pages have been retrieved, and the recursive function prints the message “All pages retrieved“ and stops.
By retrieving all this data, you can analyze all the ads to understand brand strategy and ad campaigns.
Conclusion
We've covered how to scrape Google Ads Transparency Center with SerpApi's Google Ads Transparency Center API using our Python library.
As digital advertising becomes more prevalent and important, Google Ads Transparency Center API becomes a vital tool for staying competitive. Companies can use data from it and influence decision-making, shape strategies and identify impactful advertising methods.
I hope you found this tutorial helpful. If you have any questions, don't hesitate to reach out to me at sonika@serpapi.com.
Relevant Links
Documentation
- Google Ads Transparency Center API
- Google Ads Transparency Center Regions List
- Our Playground
- API Status Graph