Website Traffic Analysis Project with Python

Data Analytics project 07

Website Traffic Analysis Project with Python

Build a complete website traffic analysis portfolio project with documented metrics, reproducible Python code, validation checks, and responsible interpretation.

Explore Data Analytics training in VizagView all project ideas

Business question

How do traffic volume, engagement, and conversion differ by channel and month?

Dataset and grain

Eight thousand synthetic sessions with date, acquisition channel, pageviews, duration, bounce flag, and conversion flag.

Requirements

Python 3.10 or later with numpy and pandas installed.

Method and validation checks

Aggregate distinct sessions, pageviews, mean Boolean rates, and duration by channel; derive monthly conversion rate from monthly totals.

  • Session ID is the reporting grain
  • Bounce and conversion definitions are explicit
  • Monthly sessions reconcile to the source total
  • Channel comparison does not claim causal acquisition impact

Complete Python code

Save the code as da_website_traffic_analysis.py. Review the stated model and field assumptions before using another dataset.

"""Analyse synthetic website sessions by date and acquisition channel."""

from __future__ import annotations

import numpy as np
import pandas as pd


def make_demo_sessions(n: int = 8_000, seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    channel = rng.choice(["Organic", "Paid Search", "Social", "Email", "Direct"], n, p=[0.34, 0.22, 0.16, 0.1, 0.18])
    pageviews = np.maximum(1, rng.poisson(2.8, n))
    converted = rng.random(n) < np.select([channel == "Email", channel == "Paid Search"], [0.065, 0.048], default=0.031)
    return pd.DataFrame({"session_id": range(1, n + 1), "date": pd.Timestamp("2025-01-01") + pd.to_timedelta(rng.integers(0, 365, n), unit="D"),
                         "channel": channel, "pageviews": pageviews, "duration_seconds": rng.gamma(2.2, 75, n).round(),
                         "bounced": pageviews == 1, "converted": converted})


def analyse_traffic(data: pd.DataFrame) -> tuple[pd.DataFrame, pd.DataFrame]:
    sessions = data.copy()
    by_channel = sessions.groupby("channel", as_index=False).agg(sessions=("session_id", "nunique"), pageviews=("pageviews", "sum"), bounce_rate=("bounced", "mean"), conversion_rate=("converted", "mean"), average_duration=("duration_seconds", "mean"))
    sessions["month"] = pd.to_datetime(sessions["date"]).dt.to_period("M").astype(str)
    monthly = sessions.groupby("month", as_index=False).agg(sessions=("session_id", "nunique"), conversions=("converted", "sum"))
    monthly["conversion_rate"] = monthly["conversions"] / monthly["sessions"]
    return by_channel.sort_values("sessions", ascending=False), monthly


def main() -> None:
    channel, monthly = analyse_traffic(make_demo_sessions())
    print(channel.round(3).to_string(index=False))
    print("\nMonthly:\n", monthly.round(3).to_string(index=False))
    print("Synthetic sessions; metric definitions must match the real analytics implementation.")


if __name__ == "__main__":
    main()

Build and run the project

Run python da_website_traffic_analysis.py to create channel and monthly performance tables.

  1. Confirm the source grain and field definitions.
  2. Reconcile record counts and additive totals.
  3. Validate rate denominators and date filters.
  4. Review outliers and missing values.
  5. Read the interpretation limits before sharing conclusions.

Expected analytical output

Channel sessions, pageviews, bounce rate, conversion rate, average duration, and a monthly conversion trend.

Interpretation and responsible-use limits

Synthetic metrics may not match GA4 or another platform. Confirm session boundaries, consent loss, bots, identity, attribution, conversion windows, and timezone before comparison.

Ways to extend the project

Add landing pages, devices, new-versus-returning users, source-medium taxonomy, bot filtering, campaign joins, and confidence intervals.

Continue learning Data Analytics

Try the next project, return to the Softenant project library, or explore the Data Analytics course in Vizag for guided SQL, Excel, Power BI, Python, dashboard, and portfolio practice.