A data science study of how AI features drive Spotify's revenue — plus an AI playlist generator built from scratch.
Overview
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?
Data
Findings
Methodology
Results Summary
Caveats
# 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.Overview
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.
Live Demo
Technical Design
preview_url clips through the browser's native Audio API. Both paths share the same playlist controller and auto-advance.Code Snippet
// 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; })); }