1. Slack Request
  2. Gather data via API
  3. Compare the data between 2 date ranges.
  4. Send Report with TOP increasing & TOP dropping pages. (It can be clicks, Sign Ups, Leads…)

1. Setting up a Cloud Console project

  1. Create a Google Cloud Project.

  1. From your Google Workspace domain’s Admin console,go to Main menu menu > Security > API Controls.
  2. In the Domain wide delegation pane, select Manage Domain Wide Delegation.
  3. Click Add new.
  4. In the Client ID field, enter the service account’s Client ID. (You can find it under service accounts in GCP)
  5. In the OAuth scopes (comma-delimited) field, enter the list of scopes that your application should be granted access to. T
  6. You need to check the box that says “Overwrite existing client ID”
  7. Click Authorize.

2. Getting Search Console Data

3. Getting Google Analytics Data

ga_view_id="your-view-id"
ga_metrics=['ga:sessions', 'ga:newUsers', 'ga:avgTimeOnPage', 'ga:goal18Completions', 'ga:goal18ConversionRate']
ga_dimensions=['ga:landingPagePath']
ga_service=initialize__delegated_google_reporting('ga_service',credentials_file_location)
get_analytics_report(ga_service,ga_view_id,main_start,main_end,ga_metrics,ga_dimensions
google analytics API Python

  • df_last is the Data Frame with data from the most recent period (for example, last 30 days) and df_previous is the Data Frame with data from the previous period (previous 30 days). Both data frames follow the same structure.
  • kpi_metrics: This is a list of the metrics that we want to “compare”. In the case of search console we normally pass in [“clicks”,”impressions”], because those are the KPIs that we want to monitor.
  • join: This is a little dirty I know. But basically you need to specify which column should be use as join key . In the case of Search Console Data Frames the value of join will be “page” and when the Data Frames contain Google Analytics data the value of join will be “landingPagePath”
##Define some Global Variables
gsc_kpis=["impressions","clicks"]
window=30 #we define a window
start=datetime.today()-timedelta(days=window+2)
main_start=start.strftime("%Y-%m-%d")
end=datetime.today()-timedelta(days=3)
main_end=end.strftime("%Y-%m-%d")
previous_start=(start-timedelta(window)).strftime("%Y-%m-%d")
previous_end=(end-timedelta(window)).strftime("%Y-%m-%d")
url="your-url.com"
credentials_file_location="your-creds.json"
## Create the Auth Object
gsc_service=initialize__delegated_google_reporting("gsc_service",credentials_file_location)
## Get the Reports
df_last=get_search_console_report(gsc_service,main_start,main_end,url)
df_previous=get_search_console_report(gsc_service,previous_start,previous_end,url)
##Create Comparison
create_comparison(df_last,df_previous,gsc_kpis,join="page")

  • impressions_abs_diff
  • impressions_rel_diff
  • clicks_abs_diff
  • clicks_rel_diff
##Define Global Variables
ga_view_id="your-view-id"
ga_metrics=['ga:sessions', 'ga:newUsers', 'ga:avgTimeOnPage', 'ga:goal18Completions', 'ga:goal18ConversionRate']
ga_dimensions=['ga:landingPagePath']
ga_kpis=['newUsers', 'goal18Completions', 'goal18ConversionRate']
##Create Data Frames
ga_last=get_analytics_report(ga_service,ga_view_id,main_start,main_end,ga_metrics,ga_dimensions)
ga_previous=get_analytics_report(ga_service,ga_view_id,previous_start,previous_end,ga_metrics,ga_dimensions)
create_comparison(ga_last,ga_previous,ga_kpis,join="landingPagePath")

['newUsers', 'goal18Completions', 'goal18ConversionRate']

4.1 Create the Slack Application

  1. Sign in to Slack and then navigate to Slack API
  2. Click on “Create an App” -> From Scratch

4.2. Creating the code and Sending it via Slack

  1. We have created a project in Google Cloud Console to connect to Search Console and Analytics APIs.
  2. We’ve got 2 different sets of Data Frames from Search Console and Google Analytics, and created a function to compare them.
  3. We now have a Data Frame that has a comparison of the data.

  1. Create a “comparison data frame” with data from Search Console OR Google Analytics.
  2. Extract the highlights of that Data Frame with .nlargest or .nsmallest
  3. Create a written report
  4. Send it via Slack
  • Nightwatch API / or other rank trackers: Moving forward, my plan is to connect to Nightwatch API, which is the rank tracking tool I’m using to monitor visibility. This way I should be able to combine visibility data with clicks, to get possible answers
  • Google Indexing API
  • HubSpot API.

Leave a Comment

Your email address will not be published.