Forecasting Site Traffic With Google Colab

Published On:

In today’s digital age, a website is crucial for businesses and individuals. However, it can be challenging to predict how much organic traffic growth your website will receive on a daily, weekly, or monthly basis. This uncertainty can make planning marketing strategies, allocating resources, and making informed decisions challenging. We offer a powerful tool from Google Colab that can help you accurately forecast your site traffic. In this video, we will explore how to use Google Colab to forecast site traffic.


What’s up? And welcome to Hack My Growth. In this video, we will be looking at how to forecast site traffic using Google Colab. Forecasting traffic can be helpful, especially when you’re a marketer, if you want to project forward and help your clients or internal team better understand the potential moving forward.

Getting Started

So we can forecast site traffic with the help of Google Colab. And to do this, we’re going to need a few things.

  • A Google Colab account
  • A CSV with click data.

These two things are all you need, and I will show you how you can set these up inside Colab to start projecting or forecasting your data.

RememberThis is a forecasting prediction.

Make sure the people you’re sharing it with understand that this is not something we can promise. This is just running a simple model to help us understand what may be possible based on past data.

Create a Google Colab Account

Let’s jump over to Google Colab. The first thing you’re going to need is a Google Colab account. If you have a Google account, sign up with Google Colab.

To use this Colab file, you will need to go to “file” and click “save a copy in Drive. That will save a copy into your Drive, and then you can make any updates and edits you need to make.

Download the Site Traffic Forecast Colab file 

Install Libraries

So the first thing we have to do is install some libraries. In this case, we’re using a library called Prophet. The people provide this library over at Meta, and it is the forecasting library that will run within this Python Colab file. Hit run. We’ll also have to import a few other things like Pandas, NumPy, and then from Prophet, we’ll import, of course, Prophet. 

Export Data 

Now we need data. And to have the right data in the right formats, we need to make sure that we download it into a CSV. For this example, I will be using data from Google Search Console. You can also use data from other sources, like Google Analytics or other analytics sources or things of that nature.

Make sure that when you export your data, you have two columns – dates and, in this case, clicks (because we’re using clicks as part of the calls later on). 

I want to go over to search results, and for this instance, I want to pull all the data for the last 16 months. That way, I have an extended data set. I want to pull the clicks, and I can click “export.”

You can export it to Google Sheets and Excel, but we need it in a CSV format. I’m going to click download CSV. The only two columns that we need are “dates” and “clicks,” so remove the rest of this data and click “save as.” I’ll save it on my desktop.

File Uploads and Data Prep

Go back over to Google Colab and run this cell. It’s going to install something that’s going to allow us to import files.  Choose the files that we want to import. We will go to our desktop and pick out the file that we saved. It will run the file, and it looks like it all came in how we wanted it to.

It’s uploading the CSV, and it’s taking the CSV and converting it into a data frame that we’ve called “Traffic.” Traffic.head allows us to see the top. We can look at the clicks over time and see that data.

It’s in reverse order if we look at this one, and we want to project going forward and not project going backward. So what do we need to do there? We need to flip the data source that’s coming in from Search Console.

There are a couple of ways to do it. We could do it here in Python, but if you are unfamiliar with it, there’s an easy way to do it. You reopen the CSV file, add a filter, and then select ascending. Re-save this data ascending, so you don’t have to worry about going into Python and doing anything.

When you do this inside of Colab, it’s really good to delete this data source. You do that by finding the file and deleting it because we will replace it, and we want the traffic to be right.

If you do what I did and you want to rechange those files into ascending, go and run this cell one more time. It’s going to open up this. We can find that date again, and now you’ll see it flipped. Now we’re looking at traffic predictions from 2022 into 2023. This is going to give us the right traffic forecasting direction. That’s important that you have your dates set up correctly. Anytime you’re using artificial intelligence or forecasting models, “Garbage in, garbage out” should be your motto.

Converting Columns Into FB Prophet Names

Now that we’ve got this into the right format, we will convert the columns into FB Prophet names. I do this to follow the documentation so I don’t have to change many things.

Holidays (One-Time Events) Using Google Core Updates

We’re using these “Holidays” to put in Google Core updates. This lets us know that there have been different changes to the algorithm that will affect our data.

I’ve added these as core updates, and you can see up to 2023. We’re up-to-date on these core updates, and we can run this, and now we know that there are potential changes due to core updates. This informs our model as it’s making some projections.

Creating a Forecast

We will hit the button which allows this to do some forecasting for us. What is this doing? Getting our date ranges here is DS. Then it gives us what the prediction is as well as the upper and the lower bounds of that prediction. When making a prediction, we’ll have something in the middle, which is average, but we’ll also have the upper and the lower bounds. It could potentially be as high as this and as low as this. It allows us to forecast more correctly instead of assuming something will go perfectly.

Examine the Forcast Graph

Now we can save this data. If you want to save the forecasting data, you can run it in another program, or we can use these cool graph figures inside Prophet.

Now as you can see, the data goes up and down. Each one of these black dots is a data point. Along this data point, it’s trending. It was trending this forecast in a negative direction.

Suppose we were forecasting down, and we continue on the same trajectory as we are right now. In that case, we’re looking at forecasting negative growth for this specific site or specific marketing campaign that we’re running at the time. This would be very good if we said, “How well is this going to perform?” We’d say, “Well, it looks like it’s going to perform badly, so we need to change our approach.”

This is where it can be helpful when you work with clients or people within your agency to understand the effectiveness of what’s going on. Again, we can do it on a different platform, which shows the same kind of data, just in a different format.  All the different options are available to us, and it’s projected out to the middle of next year. We’re doing a projection that gives us an idea of what’s happening.

You can also make these charts interactive. For instance, I could run this cell now and look at weekly trends – one month, six months, one year, or all the available data. I can also zoom in on these charts here.

This will allow you to see trends in the historical data and use that data to inform your direction. In this instance, this would be something that would raise a red flag, and you might want to go back to your team and say, “Hey, let’s change what we’re doing and adjust to see more of a positive swing on things.”

It looks like this when the data’s headed in the wrong direction. I have other data sets we can look at. You can restart, go back to the file, upload data, choose files, and I can upload this data from another campaign.

When we can run the forecasting here and see a different data trend. This data actually sees a very big, positive jump. We’ll repeat the same thing and run all the cells. You need to run all the cells when you’re processing this data. Then, we’ll run the forecasting data. We can return to these charts and say, “All right, so we saw a massive jump right around this time. If this trend continues, we are looking at a potential of seeing anywhere between minimal growth, maybe even some loss, all the way up to positive growth.”

The interactive section is nice because now you can zoom in and say, “Okay, well, what was happening around this timeframe here where we saw this massive jump? It wasn’t looking good in December, and then January hit, and we saw some growth, and now we’ve been on some steady incline ever since then.”

This can help you set accurate forecasts when a client says, “If we continue on this trend, what can we expect to see?” You have data that predicts by next year, we’re looking at an average of 1,800 to 1,900 clicks per day, and that will be much better than where we are right now – almost 1,000 more clicks per day. This allows you to do some positive and negative trends where you can create an SEO strategy by predicting and forecasting future performance.

Make sure you have the date set in the right order to predict going forward and remember, the people you’re sharing this with must understand that these are simply predictions. Nothing more, nothing less.

I hope you found this video helpful today. Check out this Site Forecast Python file within Google Colab. Make a copy for yourself and use your data. I’d love to hear what you come up with if you find this helpful. If you find anything else helpful and would like us to do a video on it, contact us and let us know! Thanks again for watching, and until next time, happy marketing.

New Call-to-action

About the Author: