← Back to Projects
✦ Completed
2024 – 2026

Spotify
× AI.

A data science study of how AI features drive Spotify's revenue — plus an AI playlist generator built from scratch.

Python · Pandas Regression Modeling Spotify Web API OpenAI GPT-4 OAuth 2.0 PKCE Web Playback SDK
spotify
Part 1 — Data Study Part 2 — Live Demo 2 projects · 1 page
Part 01
Revenue & AI Features — Data Science Study
Correlating Spotify's AI-driven product launches with revenue trends. Full pipeline: data collection, EDA, OLS regression, visualization.

Overview

What we analyzed.

This was a group data science project with Matthew Ralon, completed in Fall 2025. The question was simple: did Spotify's AI DJ feature — launched in early 2023 and rolled out globally that September — actually move the needle on the business metrics that matter?

We pulled three categories of data: Spotify's own published subscriber and MAU figures, company revenue by segment from their annual reports, and stock price data from Investing.com for Spotify (SPOT), Apple (AAPL), and Amazon (AMZN) over the past five years. Everything was cleaned and visualized in Python using Pandas, Matplotlib, Seaborn, and openpyxl.

The three questions we set out to answer: Did the DJ feature increase user retention and new subscribers? Did it strengthen Spotify's position relative to competitors? And how much did it affect the stock?

Status
Completed · Fall 2025
Team
Max Aiello · Matthew Ralon
Stack
Python · Pandas · Matplotlib · Seaborn · openpyxl
Data
Spotify Investor Reports · Investing.com Stock Data · Statista MAU/Subscriber Data

Data

The numbers.

Premium Revenue (USD)
2021–2024. Source: Spotify investor reports. Premium jumped ~$2.6B from 2023→2024.
Monthly Active Users (M)
Quarterly, Q1 2021 – Q1 2025. Red lines = AI DJ launch (Q1 2023) and global rollout (Q3 2023).
Net Income (USD) — 2021–2024
Spotify went from –$617M in 2023 to +$1.32B in 2024 — first profitable year in this span.

Findings

What the data showed.

01
User Retention & Subscribers
The AI DJ launch in Q1 2023 coincided with a visible acceleration in both premium subscriber conversion and monthly active users. MAU rose steadily through the period, with a notable uptick post-launch and again after the global rollout in Q3 2023. Free-to-premium conversion appeared to accelerate — more users upgraded after the feature dropped.
02
Competitive Position
Spotify's stock (SPOT) grew dramatically faster than Apple (AAPL) and Amazon (AMZN) over the same five-year window. While all three showed natural upward trends, SPOT's trajectory steepened notably after the DJ launch and again around the global rollout — outpacing both competitors by a wide margin by 2025.
03
Revenue Impact
Premium revenue jumped $2.6B from 2023 to 2024. Ad-supported revenue grew +10% in 2024 as well. Most strikingly, Spotify's net income flipped from –$617M in 2023 to +$1.32B in 2024 — the company's first profitable year in the dataset. Subscriptions remained dominant at 88% of total revenue.

Methodology

How we did it.

01
Data Collection
Pulled three data sources: Spotify's company-published revenue and subscriber figures, MAU data from Statista, and five-year daily stock price data from Investing.com for SPOT, AAPL, and AMZN. All data was downloaded and stored locally for reproducibility.
02
Data Cleaning
Used Pandas to normalize formats across sources, align time periods, and handle missing values. openpyxl handled any Excel-formatted source files. Revenue figures were verified against Spotify's official investor relations page.
03
Visualization
Built all charts in Matplotlib and Seaborn. Key plots included: Premium Subscribers vs MAU over time (with AI DJ launch and global rollout annotated), a five-year stock price comparison of SPOT vs AAPL vs AMZN with the same launch markers, and revenue by segment (Premium vs Ad-Supported) alongside net income from 2021–2024.
04
Limitations & Future Work
The main constraint was data availability — some originally planned questions had to be revised when the needed datasets weren't readily accessible. We also considered collecting primary data but the time cost wasn't worth the trade-off. Social media sentiment data (tracking spikes around the DJ launch) would have been a strong addition to tie the story together more directly.

Results Summary

Key numbers at a glance

Metric
Pre-DJ (2023)
Post-DJ (2024)

Caveats

What we can't claim

# The data shows strong correlation between the AI DJ launch and Spotify's
# growth across all three metrics — subscribers, stock, and revenue.
# But correlation is not causation.

# Confounders we couldn't fully isolate:
#   - Broader market recovery 2023→2024 lifted all tech stocks
#   - Spotify's simultaneous cost-cutting (layoffs) contributed to profit flip
#   - Podcast strategy, audiobooks, and price increases all ran in parallel

# What we can say: the trajectory is consistent with the DJ being a meaningful
# retention and conversion driver. The numbers moved in the right direction.
# What we can't say: it was the only cause.

# Future work we'd want: social media sentiment data around the launch,
# A/B test data on DJ users vs non-users (not public), churn rate specifics.
Part 02
AI Playlist Generator — Live Demo
Natural language → OpenAI track recommendations → Spotify search → in-browser playback. OAuth 2.0 PKCE, no backend.

Overview

What I built.

The AI Playlist Generator takes a natural language prompt — "rainy Sunday with coffee", "pre-game hype", or "late night study focus" — and uses OpenAI to generate 10 specific song recommendations. Each song is then searched against the Spotify Web API to find the real track, and the resulting playlist streams directly in-browser via the Spotify Web Playback SDK.

For Spotify Premium users, full-length tracks play seamlessly with auto-advance, shuffle, and loop. Free users may only get previews for select tracks — Spotify has progressively removed preview_url from their API, so availability varies. Premium is recommended for full, reliable playback.

Authentication uses Spotify's OAuth 2.0 PKCE flow — no backend required. The code verifier/challenge pair is generated client-side, the access token is exchanged entirely in the browser, and nothing is stored server-side.

Status
Completed · Live demo below
Stack
Vanilla JS · Spotify Web API · Web Playback SDK · OpenAI API
Auth
OAuth 2.0 PKCE — no backend, client-side only
Playback
Premium → Web Playback SDK (full tracks) · Free → 30s previews for select tracks only

Live Demo

Try it yourself.

Requires a Spotify account. Premium users get full tracks — free users may only get previews for select tracks. Click Connect and authorize in one step.

* Likes and playlist saves may take a moment to appear in the Spotify app.

⚠ Spotify Web Playback (full tracks) requires a desktop browser — Chrome, Firefox, or Edge on a computer. iOS and Android are not supported by the Spotify Web Playback SDK. 30-second previews may still play on mobile.

Connect your Spotify account
Click below to authorize via Spotify OAuth. You'll be redirected back here instantly. Spotify Premium = full tracks · Free = select track previews only.
Describe a mood, moment, or vibe
Try:
Ready — enter a prompt to generate a playlist
Now Playing
Playback moved to Spotify — website paused.
🔈 70%
#
Track
Duration
Your AI-generated playlist will appear here.
Mode: Loop

Technical Design

How it works.

01
OAuth 2.0 PKCE
No backend required. A cryptographic code verifier and SHA-256 challenge pair are generated client-side. The access token exchange happens entirely in the browser — the recommended pattern for SPAs without a server. Token stored in sessionStorage only.
02
OpenAI → Spotify Pipeline
The user prompt is sent to GPT-4 with a structured system message requesting exactly 10 tracks as a JSON array. Each title/artist pair is fired as a parallel Spotify search query — a fully resolved tracklist in a single async wave.
03
Dual Playback Engine
Premium users play via the Web Playback SDK — a full Spotify player instance mounted in the page. Free users fall back to preview_url clips through the browser's native Audio API. Both paths share the same playlist controller and auto-advance.

Code Snippet

OpenAI → Spotify pipeline

// 1. Ask OpenAI for 10 track recommendations
async function getTracksFromPrompt(prompt, openAIKey) {
  const res = await fetch('https://api.openai.com/v1/chat/completions', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${openAIKey}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({
      model: 'gpt-4o-mini',
      messages: [
        { role: 'system', content: 'Return ONLY a JSON array of 10 objects with "title" and "artist" keys.' },
        { role: 'user', content: `Recommend 10 songs for: ${prompt}` }
      ]
    })
  });
  const data = await res.json();
  return JSON.parse(data.choices[0].message.content);
}

// 2. Search all 10 on Spotify in parallel
async function resolveTracksOnSpotify(tracks, accessToken) {
  return Promise.all(tracks.map(async t => {
    const q = encodeURIComponent(`track:${t.title} artist:${t.artist}`);
    const res = await fetch(`https://api.spotify.com/v1/search?q=${q}&type=track&limit=1`, {
      headers: { 'Authorization': `Bearer ${accessToken}` }
    });
    const { tracks: { items } } = await res.json();
    return items[0] ?? null;
  }));
}
Next Project
Browser Synth →