This report explores how we can pull in website data from Google Analytics and find insights on SEO. If you want to run this notebook, the install & setup instructions are kept in the Readme.md.
Google Analytics is a website traffic analysis application that provides real-time statistics and analysis of user interaction with the website. Google analytics enables website owners to analyze their visitors, with the objective of interpreting and optimizing website's performance.
In this report we will learn how to pull in the data using the Google Analytics Reporting API and graph some interesting SEO metrics to show meaningful insights for an online educational platform that has been running an extensive content marketing campaign for the last 18 months in order to drive more traffic to their website.
First let's import the libraries we will require:
If you haven't already, check out the Readme.md file on this repository for instructions on how to creeate a project in the Google API Console, to enable the API, and create the key file, which you should save to this directory as client_secrets.json
Remeber to add the client_secrets.json file to your .gitignore!
Replace the VIEW_ID value below with your own. You can use the Account Explorer to find your View ID.
Below we are initializing an Analytics Reporting API V4 service object with our credentials created above, defining our queries to the Google Analytics API and returning its response.
Now let's parse the JSON response returend from our queries defined in the previous step into pandas dataframes, which will make it much easier to manipulate and graph the data.
Let's save everything to cache file so we dont need to download all the time. This is also handy to save data for APIs that have historical limits.
Let's visualize the progression of both organic and all other traffic to the website through time.