Alex Hoffmann, Managing Partner at Passion Digital and self-confessed tech nerd talks through how to integrate data from STAT into Google Data Studio (GDS) in this blog post. Alex oversees our Organic Marketing team and supports the entire agency with data and analytics, check out his other how to blog posts for more technical advice.
STAT has always been my all-time favourite ranking tool – Rob Bucci created a platform that is made for SEO analysts who want to sink their teeth into the data! My only issue with the programme was integrating said data into Google Data Studio, the tool we use to compile real-time performance for our clients. I found the current STAT connectors available limiting and VERY slow – no one wants to load a dashboard an hour before a client call!
So we took matters into our own hands and came up with a solution using a Node.js application, Google Cloud SQL database and Google App Engine. Let’s get into it – you’ll see just how easy it can be!
The syncSite() function is a key part of the Node.js application that synchronises data between two web services: STAT and Cloud SQL. Once this function is run, the script fetches the list of websites from STAT. However, only websites that are currently being tracked are considered valid. This is determined by the getAllSitesSTAT() function.
For each valid website, the script creates two tables in the Cloud SQL database. One table is used to store the keywords being tracked for that website and the other is used to store the daily rankings for each keyword. Keywords are stored only once in the database, as their rankings will change over time. Each time syncSite() is called, the latest ranking score for each keyword is stored in the appropriate table.
The syncSite() function is triggered by a cron job set up in Google App Engine. The job calls the /synchronize endpoint using an HTTP request. This endpoint is accessible only via the App Engine cron job, which is configured to run the syncSite() function every day at 6:00 pm GMT. This ensures that all tracked websites are synchronised with the Cloud SQL database daily.
Because the cron job runs automatically, any new websites added to STAT will be automatically added to their own Cloud SQL tables. This eliminates the need for manual intervention to ensure that all tracked websites are synchronised properly.
The script includes error handling to help identify and resolve any issues that arise during synchronisation. The logger.js file contains code for logging errors with Bunyan to Google Cloud Monitoring. This ensures that any issues with the synchronisation process can be addressed quickly, minimising any impact on the web services being synchronised.
The website’s keyword and ranking tables can then be pulled into Google Data Studio with this custom query.
With all that in mind, here’s how you set everything up.
Once you have these accounts in place, fork the repository and go through the read me.
Now that you have the application up and running on Google App Engine, you can sit back and let the cron job do its thing. All sites you’re tracking in STAT will sync to the Google Cloud SQL database. From there you can use this SQL code within Google Data Studio:
1. Open Google Data Studio in your web browser and login to your Google account
2. Click on the “Create” button in the top left corner of the screen
3. Choose “Data Source” from the dropdown menu
4. In the “Connect to Data” screen, search for “Cloud SQL”
5. Select “Cloud SQL (MySQL)” or “Cloud SQL (PostgreSQL)” depending on the database engine you’re using and click “Connect”
6. In the “Authenticate” screen, select your project from the dropdown menu and click “Connect”
7. In the “Configure Data Source” screen, choose “Custom Query” as the connection type
8. Enter the instance connection name, database name, username and password for your Cloud SQL instance
9. In the “Query” field, enter the SQL query you want to use to retrieve data from your Cloud SQL database
10. Click the “Validate” button to check that the query is valid
11. Click “Create Field” to create calculated fields based on your query
12. If you want to add any filters, click “Add a Filter” and select the fields you want to use as filters
13. Click “Save” to save your data source
14. You can now use this custom query data source in your reports and dashboards in Google Data Studio
Q: What is the syncSite() function?
A: The syncSite() function is a key part of a Node.js application that synchronises data between two web services: STAT and Cloud SQL.
Q: What does the script do when the syncSite() function is called?
A: When the syncSite() function is called, the script fetches the list of websites from STAT. For each valid website (determined by the getAllSitesSTAT() function), the script creates two tables in the Cloud SQL database.
Q: What is the purpose of having two tables created for each valid website in the Cloud SQL database?
A: One table is used to store the keywords being tracked for that website and the other is used to store the daily rankings for each keyword.
Q: How often does the cron job trigger the syncSite() function?
A: The cron job is set up to run the syncSite() function every day at 6:00 pm GMT.
Q: Does the syncSite() function require manual intervention to add new websites to the Cloud SQL database?
A: No, any new websites added to STAT will be immediately added to their own Cloud SQL tables, as the cron job runs automatically.
Q: Does the script include error handling?
A: Yes, the script includes error handling to help identify and resolve any issues that arise during synchronisation.
Q: How can the website’s keyword and ranking tables be pulled into Google Data Studio?
A: The website’s keyword and ranking tables can be pulled into Google Data Studio using a custom query – see the “Custom Query” section above.
And there you have it – we solved the STAT-GDS connectivity conundrum. Here at Passion, we pride ourselves on our proactivity and problem solving. Whether you need an innovative approach to your web performance, technical SEO support or something else, we can help you Imagine Better digital marketing. Get in touch with our team of experts today.