Time Series Analysis in Web Analytics — The Theory Behind the Trend
Most marketers read traffic charts as pictures. Time series analysis treats them as data — with structure, decomposable components, and testable properties. Here's the theory.
Most analysts look at a traffic chart and see a picture. Time series analysis treats that picture as data — structured, decomposable, and governed by mathematical properties that can be estimated, tested, and forecasted. The difference in what you can extract is enormous.
What is a Time Series?
Formally, a time series is a sequence of observations indexed by time:
where is the value of some metric (sessions, users, revenue) at time , and the observations are ordered and equally spaced. That last part matters: web analytics data is almost always daily or weekly, and gaps in that regularity introduce analytical problems before you even start modeling.
The key distinction between a time series and a cross-sectional dataset is that observations are not independent. What happens on Monday is correlated with what happened on Sunday. That dependence is not noise — it is the signal.
The Decomposition Model
The foundational idea in time series analysis is that any observed series can be broken into components that have different causes and different behaviors. The classical additive decomposition is:
where:
- is the trend — the long-run direction of the series
- is the seasonal component — periodic fluctuations that repeat with a fixed frequency
- is the residual — everything left over after trend and seasonality are removed
For web analytics, this decomposition is not merely academic. Organic search traffic has a strong weekly seasonality (): B2B sites consistently drop on weekends. Campaign effects show up as trend shifts in . A technical outage or a viral moment appears as a spike in . Conflating these components leads to bad decisions — attributing a weekend dip to a content problem, or a seasonal peak to a campaign that happened to run at the right time.
When the seasonal amplitude grows with the trend (common in e-commerce), the multiplicative form is more appropriate:
The choice between additive and multiplicative is empirical, not arbitrary — you check whether the seasonal swings scale with the level of the series.
Stationarity — Why It Matters
A time series is stationary if its statistical properties do not change over time. Formally, weak stationarity requires:
Most web traffic series are not stationary — they trend upward (or downward), and their variance shifts. This matters because most classical forecasting models assume stationarity. The standard fix is differencing: instead of modeling , you model .
You can test for stationarity formally using the Augmented Dickey-Fuller test, which tests the null hypothesis that a unit root is present:
Rejecting the null ( significantly) means the series is stationary. Failing to reject means you difference and test again.
Autocorrelation — The Memory of a Series
Because time series observations are dependent, the correlation between and is the core quantity of interest. The autocorrelation function (ACF) at lag is:
For organic search traffic, is typically high — today's traffic correlates with traffic 7 days ago. That's the weekly seasonal pattern expressed mathematically.
The partial autocorrelation function (PACF) at lag measures the correlation between and after removing the linear effect of all intermediate lags . Together, ACF and PACF plots are the primary diagnostic tools for model identification — their decay patterns tell you what kind of model your data is asking for.
Classical Models — AR, MA, ARIMA
The workhorse model family for stationary time series is ARIMA(, , ):
where is the backshift operator (), is the differencing operator applied times, and is white noise.
Unpacking the components:
Autoregressive term — AR(): The current value is a linear function of the previous values:
Moving average term — MA(): The current value is a linear function of the previous error terms:
Integration — I(): The in ARIMA indicates how many times the series must be differenced to achieve stationarity.
For seasonal data, the model extends to SARIMA(,,)(,,), where is the seasonal period (7 for weekly patterns in daily data) and the uppercase parameters capture the seasonal autoregressive and moving average structure.
Prophet's Additive Model
Facebook's Prophet, widely used for web traffic forecasting, takes a different approach — it models the decomposition directly rather than fitting ARIMA parameters:
where:
- is a piecewise linear or logistic trend with automatic changepoint detection
- is a Fourier series representation of seasonality
- captures holiday and special event effects
- is the error term
The seasonality component uses a Fourier series because it can represent arbitrary periodic patterns with a small number of parameters:
where is the period and controls how quickly the seasonality can change. For weekly seasonality with daily data, and is typically sufficient.
The practical advantage of Prophet over ARIMA for web analytics is that it handles missing data, outliers, and structural breaks (a site redesign, a major campaign launch) more gracefully — because those are explicitly part of the model rather than violations of its assumptions.
The Residual is the Real Story
Once trend and seasonality are accounted for, what remains — — is where the analytically interesting events live. A residual that spikes on a particular date tells you something happened that the model didn't expect. That anomaly might be:
- A technical issue (tracking broke, site went down)
- An external event (press mention, algorithm update)
- A campaign effect you want to measure
This is the connection between time series analysis and causal inference. The residual is what's left after the predictable variation is removed — it's your cleanest window into the effect of specific interventions. If you ran a campaign on day , the causal question is whether is large relative to the distribution of residuals before and after. That's the logic behind methods like Bayesian Structural Time Series (BSTS) and synthetic control.
The Iterative Nature of the Work
Time series analysis is not a linear pipeline. It is a flywheel:
- You decompose the series and examine the residuals
- The residuals reveal structure you didn't account for — a secondary seasonal pattern, a trend shift
- You update the model and decompose again
- You check whether the new residuals look like white noise
White noise residuals — zero autocorrelation at all lags, constant variance — are the goal. They mean the model has captured everything systematic in the data, and what's left is genuinely unpredictable. That's when you trust the forecast.
from statsmodels.stats.diagnostic import acorr_ljungbox
# Ljung-Box test: null hypothesis is that residuals are white noise
result = acorr_ljungbox(residuals, lags=[7, 14, 21], return_df=True)
print(result)
# p-values > 0.05 → residuals are white noise → model is well-specifiedMost of the work in time series analysis is in this diagnostic loop — not in running the forecast itself. A model that fails the white noise test is telling you something systematic is still in the residuals. Listening to it is how you get from a technically correct model to one that actually understands your data.