from googlewrapper import GoogleSearchConsole
gsc = GoogleSearchConsole()
The following all accept a datetime variable. By default the object will pull the last 7 days of data. There are 2 options for changing the date range to pull data for:
Use this option if you would like a range of dates
You need to call both these methods to assign start and end dates
.set_start_date(start_date)
.set_end_date(end_date)
Use this option if you only want to see one day worth of data
You only need to call the method below to make it work
.set_date(date)
.set_filters(filter_list)
Parameters
- filter_object: list of dictionaries
- how to filter your GSC object
example_filter = [
{
"dimension": "device",
"operator": "equals",
"expression": "mobile"
},
{
"dimension": "country",
"operator": "equals",
"expression": "usa"
}
]
gsc.set_filters(example_filter)
- See Google's Docs for more details
- metric filters are not assigned prior to the pull, filter data after the api pull
- to reset (remove) filters call the method with an empty list ->
gsc.set_filters([])
.set_dimensions(dimensions)
Parameters
- dimensions: list of dimension strings
- all dimensions should remain in lowercase
- Dimension String Options:
- "page"
- "query"
- "date"
- "country"
- "device"
- "searchAppearance"
Default values: ["page","date"]
.set_sites(sites_list)
Parameters
- sites_list: list
- list of gsc properties (strings) we want to pull
- domain properties should be prefaced with "sc-domain:"
- Example:
["sc-domain:example.com"]
Default values: self.all_sites()
.set_branded(branded_dictionary)
Parameters
- branded_dictionary: dict
- keys
- GSC Property Name - Match exactly to GSC Portal
- values
- list of branded strings
- if these values are found in any form in the query, marked as branded
- list of branded strings
- keys
Example:
{'https://www.oreo.com':['oreo','nabisco','milks favorite cookie']}
If .set_branded()
is not called, all queries will be marked as Branded = FALSE
.all_sites(site_filter)
Parameters
- site_filter: list of strings (optional)
- will filter your sites to sites including the strings in the list
Returns: list of all verified sites in the GSC profile
.get_data()
- After assigning all the parameters - with the other class methods - run this method to make the api request
- This method does not accept any parameters
Returns: dictionary object | pd.DataFrame (if len(self._site_list)==1)
- Keys: Site URLs from the site_list
- Values: pd.DataFrame of GSC data
- This dictionary object is also saved as the
self.output
attribute to use withself.ctr()
.ctr()
- Calculates custom Click Through Rates based our our GSC data we pulled
- For accurate results, make sure that you:
- have "query" in the dimension lis
- have set branded queries using .set_branded()
- This method does not accept any parameters
Returns: dictionary object
- Keys: ["all","branded","non-branded"]
- Values: pd.DataFrame with index as Position and columns ["Clicks","Impressions","CTR"]
- This dictionary object is also saved as the
self.my_ctr
attribute to be referenced later
# initialize our class
from googlewrapper import GoogleSearchConsole
gsc = GoogleSearchConsole()
# assign variables to our GSC object
gsc.set_sites(["sc-domain:example.com"])
gsc.set_date(dt.date.today())
gsc.set_dimensions(["page","date","query"])
# call the api to get the data
data = gsc.get_data()
# initialize our class
from googlewrapper import GoogleSearchConsole
gsc = GoogleSearchConsole()
#declare all the parameters
gsc.set_start_date(dt.date.today()-dt.timedelta(days=365))
gsc.set_end_date(dt.date.today())
gsc.set_dimensions(['query'])
gsc.set_branded({"sc-domain:example.com":["example","test"]})
gsc.set_sites(["sc-domain:example.com"])
data = gsc.get_data()
ctr = gsc.ctr()