Marketing Analytics full course
Complete, structured, textbook-level course plan that builds your skills from scratch all the way to advanced mastery in Marketing Analytics, with a strong focus on MMM and MTA.
🎓 Complete Course Structure: Marketing Analytics Mastery with Focus on MMM & MTA
🧩 Phase 1: Foundations of Marketing & Analytics (Beginner)
Module 1: Fundamentals of Marketing
-
1.1 What is Marketing?
-
1.2 Marketing Objectives & KPIs
-
1.3 Marketing Channels: Traditional vs Digital
-
1.4 4Ps and 7Ps of Marketing Mix
-
1.5 Customer Journey & Funnel Stages
Module 2: Basics of Analytics & Data
-
2.1 What is Analytics in Marketing?
-
2.2 Types of Data: Structured vs Unstructured
-
2.3 Data Collection Methods (Surveys, CRMs, Web Logs, etc.)
-
2.4 Data Sources in Marketing (Google Analytics, Ad Platforms, etc.)
-
2.5 Exploratory Data Analysis (EDA)
📊 Phase 2: Core Marketing Analytics Tools (Beginner to Intermediate)
Module 3: Statistics for Marketing
-
3.1 Descriptive Statistics
-
3.2 Inferential Statistics
-
3.3 Hypothesis Testing
-
3.4 Correlation vs Causation
Module 4: Excel & SQL for Marketing Data
-
4.1 Excel Functions for Analysts
-
4.2 Pivot Tables & Dashboards
-
4.3 SQL Basics: SELECT, WHERE, GROUP BY
-
4.4 Advanced SQL for Segmentation & Funnel Analysis
Module 5: Python/R for Marketing Analytics
-
5.1 Data Wrangling with Pandas/dplyr
-
5.2 Visualizations: Matplotlib, Seaborn, ggplot2
-
5.3 Regression Analysis
-
5.4 Time Series Basics
📈 Phase 3: Introduction to MMM & MTA (Intermediate)
Module 6: Marketing Mix Modeling (MMM) Basics
-
6.1 What is MMM?
-
6.2 History and Use Cases of MMM
-
6.3 Marketing Channels and Media Spend
-
6.4 Building a Simple MMM using Linear Regression
-
6.5 Challenges: Adstock & Diminishing Returns
Module 7: Attribution Modeling Basics
-
7.1 What is Attribution?
-
7.2 Rules-Based Attribution Models (First-Touch, Last-Touch, Linear)
-
7.3 Introduction to Multi-Touch Attribution (MTA)
-
7.4 MTA vs MMM: Differences and Use Cases
📐 Phase 4: Advanced MMM Techniques (Expert Level)
Module 8: Advanced MMM Modeling
-
8.1 Adstock Transformation Theory
-
8.2 Saturation/Diminishing Returns (Hill Function)
-
8.3 Lag Effects in Marketing
-
8.4 Channel Interactions
-
8.5 Model Regularization (Ridge, Lasso)
-
8.6 Bayesian MMM with PyMC3/RStan
Module 9: MMM in Practice
-
9.1 Data Preparation for MMM
-
9.2 Model Calibration & Validation
-
9.3 Forecasting and Budget Allocation
-
9.4 MMM with Facebook Robyn (Open Source)
-
9.5 MMM Reporting Dashboards
🧠 Phase 5: Advanced Multi-Touch Attribution (Expert Level)
Module 10: Machine Learning for MTA
-
10.1 Logistic Regression for Conversion Prediction
-
10.2 Markov Chains for Attribution
-
10.3 Shapley Value Attribution
-
10.4 Gradient Boosting Trees (XGBoost) for MTA
-
10.5 Deep Learning-Based MTA Models
Module 11: Real-Time & Online Attribution
-
11.1 Probabilistic vs Deterministic Matching
-
11.2 Cookie & Pixel Tracking
-
11.3 Customer Data Platforms (CDPs)
-
11.4 Cross-Device Attribution
🚀 Phase 6: Deployment, Optimization & Projects (Industry-Ready)
Module 12: Data Engineering for Marketing Analytics
-
12.1 ETL Pipelines for Marketing Data
-
12.2 Data Lakes vs Data Warehouses
-
12.3 Airflow for Scheduling
-
12.4 Google BigQuery for Marketing Teams
Module 13: Dashboarding & Reporting
-
13.1 Power BI/Tableau Dashboards
-
13.2 Marketing KPIs to Track
-
13.3 Self-Serve Analytics Setup
Module 14: Capstone Projects
-
14.1 Build a Real MMM Model using Robyn
-
14.2 Build an MTA Model with Markov Chains & Shapley
-
14.3 Budget Optimization Recommendation Engine
-
14.4 End-to-End Marketing Analytics Pipeline
📚 Bonus Resources
-
Glossary of 100+ Marketing Analytics Terms
-
Case Studies (e.g. Coca-Cola, Amazon, P&G)
-
Recommended Textbooks:
-
“Marketing Analytics: Strategic Models and Metrics” by Stephan Sorger
-
“Advanced Marketing Analytics” by Mike Grigsby
-
“Bayesian Methods for MMM” by Taddy & Green
-
📘 Module 1.1: What is Marketing?
🔍 Definition and Meaning
Marketing is the discipline and process of identifying, anticipating, and satisfying customer needs profitably. It is not just about selling or advertising — it is about creating value for customers and building long-term relationships.
According to the American Marketing Association (AMA):
“Marketing is the activity, set of institutions, and processes for creating, communicating, delivering, and exchanging offerings that have value for customers, clients, partners, and society at large.”
🧠 Core Idea
At its core, marketing bridges the gap between business and customer by:
-
Understanding what the customer wants or needs
-
Designing products or services that fulfill those needs
-
Communicating effectively about those products
-
Delivering the product in a way that satisfies the customer
-
Ensuring the relationship continues profitably over time
💡 Why is Marketing Important?
-
Drives Business Revenue: Marketing creates demand — which ultimately drives sales and profit.
-
Customer-Centricity: In today’s digital age, businesses that don’t understand their customers don’t survive. Marketing is the voice of the customer inside the company.
-
Strategic Differentiator: In a saturated market, products can be similar, but how you market them (e.g., brand, experience, communication) sets them apart.
-
Market Research & Insights: Helps identify new opportunities, audience trends, and competitive threats.
-
Brand Building: A strong brand presence is often a result of consistent and effective marketing.
🛠️ Key Functions of Marketing
| Function | Description |
|---|---|
| Market Research | Gathering information about consumer behavior, competitors, and trends |
| Segmentation & Targeting | Dividing markets into segments and choosing which to focus on |
| Positioning & Branding | Crafting a unique identity and place in the customer's mind |
| Product Development | Designing or refining products based on customer feedback |
| Pricing Strategy | Determining optimal price for perceived value and competitiveness |
| Promotion & Advertising | Communicating the product's value via ads, PR, influencers, etc. |
| Sales Enablement | Supporting the sales team with collateral, presentations, and training |
| Distribution (Place) | Ensuring the product is available at the right time and place |
| Customer Experience | Managing the end-to-end interaction with customers |
🏢 Marketing in the Real World
Marketing is applied across:
-
B2C (Business to Consumer): E.g., Coca-Cola, Netflix
-
B2B (Business to Business): E.g., Salesforce, HubSpot
-
D2C (Direct to Consumer): E.g., Mamaearth, boAt
Each requires different approaches, but the underlying goal is always the same: value creation for both the company and the customer.
📱 Modern Marketing vs Traditional Marketing
| Feature | Traditional Marketing | Digital/Modern Marketing |
|---|---|---|
| Medium | TV, radio, print | Social media, email, search engines |
| Interactivity | One-way | Two-way (dialogue with customers) |
| Targeting | Broad & general | Hyper-targeted (based on behavior, interest) |
| Measurability | Difficult to track ROI | Real-time analytics and conversion tracking |
| Cost | High upfront | Cost-effective for all business sizes |
🧭 Evolution of Marketing (Timeline)
-
Product Orientation (Pre-1950s)
“If you build it, they will come” – Focus on production, not customer needs. -
Sales Orientation (1950s-1960s)
Aggressive sales tactics to push products to customers. -
Marketing Orientation (1970s-1990s)
Understanding and responding to customer needs became central. -
Relationship Marketing (1990s-2010s)
Long-term engagement, loyalty, and customer satisfaction became priority. -
Digital & Data-Driven Marketing (2010s–present)
Powered by analytics, personalization, and automation.
💬 Example: Marketing in Action – Apple Inc.
-
Research: Understands what customers want in tech — simplicity and design
-
Segmentation: Targets tech-savvy, premium audience
-
Product: iPhone — minimalist, high performance
-
Pricing: Premium pricing strategy (psychological + value-based)
-
Promotion: Highly emotional ad campaigns (“Shot on iPhone”)
-
Place: Sold via website, exclusive stores, and partners
This consistent and holistic marketing approach fuels Apple’s brand strength.
📈 Marketing vs Selling vs Advertising
| Term | Meaning |
|---|---|
| Marketing | End-to-end value creation and relationship management |
| Selling | Persuading people to buy what's already made |
| Advertising | Communicating a message to promote a product, usually paid |
🔑 Insight: Marketing includes both selling and advertising — but it starts before and continues after the sale.
📌 Summary Points
-
Marketing is value creation + value communication + value delivery.
-
It blends creativity, psychology, business, and analytics.
-
In today’s world, data-driven marketing is at the core of decision-making.
-
Whether you’re doing MMM or MTA, marketing principles remain foundational.
📘 Module 1.2: Marketing Objectives & KPIs
🎯 What are Marketing Objectives?
Marketing objectives are the specific, measurable goals a company sets to guide its marketing strategy and track progress. These objectives are aligned with broader business goals like revenue growth, market share, profitability, or customer retention.
✅ A good marketing objective is SMART:
Specific
Measurable
Achievable
Relevant
Time-bound
🧠 Purpose of Setting Objectives
-
Create direction and clarity for the marketing team
-
Ensure all campaigns support business strategy
-
Provide benchmarks for measurement and optimization
-
Allocate budget and resources efficiently
🗂️ Types of Marketing Objectives
1. Awareness Objectives
-
Increase brand visibility or product awareness
-
Typically used for new product launches or entering new markets
Example:
“Increase brand awareness by 30% among college students in Bangalore within 6 months.”
2. Acquisition Objectives
-
Attract new users or customers
-
Often linked to performance marketing campaigns (e.g., paid ads)
Example:
“Generate 10,000 new email sign-ups by the end of Q2.”
3. Engagement Objectives
-
Drive interaction with the brand (website, app, content)
Example:
“Increase Instagram engagement rate from 2% to 5% over 90 days.”
4. Conversion Objectives
-
Get people to perform desired actions (purchase, sign-up, download)
Example:
“Achieve a conversion rate of 4% on product landing pages by October.”
5. Retention & Loyalty Objectives
-
Retain existing users and reduce churn
-
Enhance Customer Lifetime Value (CLV)
Example:
“Improve repeat purchase rate by 20% in the next quarter.”
6. Revenue or Profit Objectives
-
Directly tie marketing impact to business bottom line
Example:
“Increase monthly recurring revenue (MRR) from digital campaigns by ₹2 lakhs.”
📈 What are KPIs (Key Performance Indicators)?
KPIs are the quantifiable metrics used to evaluate how successfully a company is achieving its marketing objectives.
They answer:
“Are we on track?” or “How do we measure progress?”
🔗 Objectives vs KPIs: The Difference
| Marketing Objective | KPI(s) to Track It |
|---|---|
| Increase website traffic | Website sessions, pageviews, bounce rate |
| Improve brand awareness | Ad impressions, branded search, social reach |
| Drive lead generation | Number of leads, cost per lead (CPL), lead quality |
| Increase conversions | Conversion rate, sales volume, CPA |
| Boost customer retention | Churn rate, repeat purchase rate, NPS |
📊 Examples of Common Marketing KPIs
| Category | KPI Examples |
|---|---|
| Awareness | Impressions, Reach, Brand Recall Survey |
| Acquisition | Click-Through Rate (CTR), Cost Per Click (CPC) |
| Engagement | Time on Site, Bounce Rate, Scroll Depth |
| Conversion | Sales Volume, Conversion Rate, Cart Abandonment |
| Loyalty | Repeat Purchase Rate, Customer Lifetime Value |
| Revenue | Marketing ROI, ROAS (Return on Ad Spend) |
⚙️ How KPIs Are Tracked (Tools)
| Tool/Platform | What it Measures |
|---|---|
| Google Analytics | Traffic, bounce, conversions |
| Facebook Ads Manager | Impressions, reach, CPC, CPM |
| CRM Tools (HubSpot) | Leads, lead scoring, email engagement |
| Attribution Tools | Customer journey, touchpoints, path to conversion |
| BI Tools (Tableau/Power BI) | Custom KPI dashboards |
💡 Case Study: E-Commerce Brand KPI Breakdown
Objective: Increase online sales by 20% in Q3
KPIs to Track:
-
Traffic from performance ads (Google/Facebook)
-
Conversion rate on landing pages
-
Cart abandonment rate
-
Cost per acquisition (CPA)
-
Monthly sales volume (₹)
🧮 KPI Formulas You Should Know
-
Conversion Rate = (Conversions / Total Visitors) × 100
-
Cost Per Acquisition (CPA) = Total Campaign Cost / Conversions
-
ROAS (Return on Ad Spend) = Revenue / Ad Spend
-
Customer Lifetime Value (CLV) = Avg. Value × Purchase Frequency × Lifespan
-
Churn Rate = (Lost Customers / Total Customers) × 100
🚩 Common Mistakes in Setting Objectives & KPIs
| Mistake | Example Problem |
|---|---|
| Vague goals | “Improve branding” → No clear metric |
| Not linking marketing to business | “More traffic” → But are they converting? |
| Tracking vanity metrics | Focusing on likes instead of ROI |
| No baseline/benchmark | Can’t know progress without a starting point |
🧠 Summary Key Takeaways
-
Marketing Objectives set the direction; KPIs measure the performance.
-
Not all KPIs are useful — choose metrics that directly tie to objectives.
-
Well-defined KPIs form the foundation of Marketing Mix Models and Attribution Models later.
-
Tools like Google Analytics, CRM dashboards, and ad platforms help track real-time progress.
📘 Module 1.3: Marketing Channels — Traditional vs Digital
🧠 What are Marketing Channels?
Marketing channels are the paths through which companies deliver their promotional messages and influence customer decisions. These channels serve as the bridge between the product and the customer and are chosen strategically to reach the right audience at the right time.
In simpler terms: Marketing channels are communication pathways between your brand and potential buyers.
🌐 Two Broad Types of Channels
1. Traditional Marketing Channels (Offline)
These channels were dominant before the digital era and still play a strong role in mass outreach.
2. Digital Marketing Channels (Online)
These emerged with the internet and allow highly targeted, measurable, and interactive marketing.
🏛️ Traditional Marketing Channels: Overview
✅ Key Features
-
Broad reach
-
One-way communication
-
High production & placement cost
-
Difficult to measure precisely
📺 Examples of Traditional Channels
| Channel | Description |
|---|---|
| TV | Ads during shows or sports events; good for mass reach |
| Radio | Local advertising and audio branding |
| Print (Newspapers, Magazines) | Good for older or regional demographics |
| Outdoor (OOH) | Billboards, bus stops, transit ads; high visibility |
| Events & Sponsorships | Brand presence at exhibitions, sports, concerts |
| Telemarketing | Calling potential leads directly for promotion or conversion |
🎯 When to Use:
-
Launching a national brand
-
Targeting less digitally connected demographics
-
Reinforcing credibility with mass audiences
🌍 Digital Marketing Channels: Overview
✅ Key Features
-
Real-time tracking and analytics
-
Two-way interaction
-
Hyper-targeting based on behavior, interests, location
-
Cost-effective and scalable
📲 Examples of Digital Channels
| Channel | Description |
|---|---|
| Search Engine Marketing (SEM) | Google Ads to appear on search result pages |
| Social Media Marketing (SMM) | Facebook, Instagram, LinkedIn, Twitter ads & posts |
| Email Marketing | Personalized campaigns, automation flows |
| Content Marketing | Blogs, videos, case studies, infographics |
| Affiliate/Influencer Marketing | Commission or sponsorship based on conversions |
| SEO (Search Engine Optimization) | Organic traffic through content and website optimization |
| Mobile Marketing | SMS, push notifications, in-app ads |
| Programmatic Advertising | Automated ad buying using AI for real-time bidding |
🎯 When to Use:
-
Want personalized messaging and segmentation
-
Limited budgets, need measurable ROI
-
Shorter feedback loops or A/B testing required
-
Want to optimize conversions across funnel stages
⚖️ Traditional vs Digital Channels: Side-by-Side Comparison
| Feature | Traditional Channels | Digital Channels |
|---|---|---|
| Communication Style | One-way (broadcast) | Two-way (interactive) |
| Cost | High (TV ads, print) | Low to moderate (pay-per-click, etc.) |
| Measurement Accuracy | Approximate (TRP, circulation) | Precise (clicks, conversions, ROAS) |
| Targeting | Broad, mass-market | Micro-targeting, segment-based |
| Speed of Execution | Slower (planning, production cycles) | Fast (ads can go live in minutes) |
| Adaptability | Fixed once published | Easy to edit, A/B test, and optimize |
| Best for | Brand awareness, mass recall | Conversion, engagement, personalization |
🔬 Marketing Mix Modeling (MMM) and Traditional Channels
MMM heavily relies on analyzing the impact of traditional media like TV, print, and radio, because:
-
These channels contribute to long-term brand effects (brand equity).
-
They're expensive, so optimization matters.
-
Measuring them is hard — statistical modeling helps estimate their true value.
For example: A spike in sales 2 weeks after a big TV campaign might be attributed through a lag variable in MMM.
🔎 MTA and Digital Channels
MTA is mostly applied to digital channels because:
-
Every customer interaction can be tracked (cookies, pixels, UTM tags).
-
Touchpoints are often multi-step (e.g., ad → website → email → purchase).
-
Attribution models can assign credit across various digital stages.
For example: A user sees a Facebook ad, clicks a Google search, then purchases. MTA will track and credit each step.
💡 Example: Channel Mix for a Tech Product Launch
| Channel | Objective | Expected KPI |
|---|---|---|
| TV Campaign | Mass awareness | GRPs, brand lift |
| Influencer Collaboration | Social proof | Engagement, followers, referral traffic |
| Search Ads (SEM) | Capture active intent | CTR, conversions, CPA |
| Retargeting Ads | Bring back lost visitors | ROAS, view-through conversions |
| Email Drip Campaigns | Nurture leads | Open rate, click rate, unsubscribe |
🧠 Summary
-
Marketing channels are the platforms that connect messages to customers.
-
Traditional channels are good for mass reach & brand building.
-
Digital channels are good for performance marketing & optimization.
-
MMM models evaluate the return on offline investments, while MTA tracks digital journey-level conversion paths.
-
A strong marketer knows how to blend both based on objectives, audience, and budget.
📘 Module 1.4: 4Ps and 7Ps of Marketing Mix
🧠 What is the Marketing Mix?
The Marketing Mix is a strategic framework used to structure how a product or service is marketed. It combines several controllable variables — known as the Ps — that influence how consumers perceive and interact with a brand.
Originally, the model consisted of 4Ps (Product, Price, Place, Promotion), later expanded to 7Ps for service-based industries.
🎯 Purpose of the Marketing Mix
-
Aligns product/service strategy with customer expectations
-
Ensures consistency across product design, pricing, delivery, and messaging
-
Helps marketers plan, execute, and optimize marketing activities
-
Forms the core structure behind budget allocation in MMM models
🔹 The 4Ps of Marketing (For Products)
1. Product – What you are offering
It includes the design, features, quality, packaging, and even warranty of the product or service.
Key considerations:
-
What problem does the product solve?
-
What features set it apart from competitors?
-
Is it aligned with customer needs and desires?
Example: Apple’s iPhone – Premium design, iOS experience, camera quality
2. Price – What the customer pays
This includes the pricing strategy and perception of value.
Key considerations:
-
Cost-based, value-based, or competitive pricing?
-
Discounts, bundles, dynamic pricing?
-
Is the price justified in terms of perceived value?
Example: Netflix’s tiered pricing for Basic, Standard, Premium plans
3. Place – Where and how it’s sold
Refers to distribution channels — online, retail, partners, direct-to-consumer — and the product’s availability.
Key considerations:
-
Online vs Offline?
-
Local vs International?
-
Direct vs Indirect channels?
Example: Amazon sells via e-commerce with Prime delivery logistics
4. Promotion – How the product is communicated
Includes advertising, PR, sales promotion, digital campaigns, influencer marketing, etc.
Key considerations:
-
Which channels reach your audience?
-
What message resonates?
-
Timing and frequency of promotions?
Example: Coca-Cola’s emotional TV ads during festivals
🧪 4Ps in MMM Modeling
Marketing Mix Modeling (MMM) uses the 4Ps to estimate which “P” contributes most to sales:
-
📦 Product: Are product upgrades increasing demand?
-
💰 Price: Do price cuts boost volume, or reduce profit?
-
🛒 Place: Are new store openings linked with uplift?
-
📢 Promotion: What is the ROI of advertising spend?
🔷 The 7Ps of Marketing (For Services)
In service industries (banking, SaaS, healthcare, education), three additional Ps are added to address intangibility:
5. People – The individuals involved in delivery
Includes customer service agents, sales staff, consultants, etc.
Key Questions:
-
Are employees trained and empathetic?
-
Is the service experience personalized?
Example: Zappos' customer support is known for delighting customers
6. Process – The way the service is delivered
Efficiency, automation, service standards, and operational workflow.
Key Questions:
-
Is the service delivery smooth and consistent?
-
How is waiting time managed?
-
Are digital touchpoints optimized?
Example: Swiggy’s real-time delivery updates and tracking
7. Physical Evidence – Tangible cues of service quality
In service marketing, you provide "evidence" of quality through branding, website design, ambiance, receipts, uniforms, etc.
Key Questions:
-
Is your office, app, or store environment aligned with your brand?
-
Are trust signals (e.g., certifications, ratings) visible?
Example: Hospitals with modern infrastructure signal quality care
📚 Real-World Example: Starbucks (7Ps Analysis)
| P | Strategy Used by Starbucks |
|---|---|
| Product | High-quality coffee, consistent menu globally |
| Price | Premium pricing based on experience and brand |
| Place | Strategic locations in malls, airports, IT parks |
| Promotion | Lifestyle branding, loyalty programs, Instagram ads |
| People | Trained baristas with strong customer service |
| Process | Efficient ordering (mobile app, queueing, name-calling) |
| Physical Evidence | Cozy store interiors, branded cups, merchandise |
🧩 Role of 7Ps in Data-Driven Analytics
| Element | How It's Analyzed |
|---|---|
| Product | Feature usage, return rate, product reviews |
| Price | Price elasticity testing, A/B pricing experiments |
| Place | Store-level sales performance, delivery coverage analysis |
| Promotion | ROAS from ad campaigns, email CTR, coupon redemptions |
| People | Customer support ratings, satisfaction surveys |
| Process | Drop-off rate in service funnel, ticket resolution time |
| Physical Evidence | Click-through rate on branded assets, landing page performance |
💡 Marketing Mix and MMM (Marketing Mix Modeling)
MMM aims to quantify how each P affects sales or ROI:
-
You can use regression models to see:
→ “How much of sales uplift is due to promotion vs pricing vs distribution?” -
Example:
TV Ads → +10% sales
Price Discount → +7% sales
New Store → +5% sales
These insights help in budget optimization and channel planning.
📌 Summary
-
4Ps = Product, Price, Place, Promotion
-
7Ps = + People, Process, Physical Evidence (for services)
-
This framework ensures a holistic approach to go-to-market planning
-
MMM analysts often break down variables in a campaign based on the 4Ps
-
Each “P” can have multiple KPIs and measurable inputs
📘 Module 1.5: Customer Journey & Funnel Stages
🧠 What is the Customer Journey?
The customer journey is the complete lifecycle a customer goes through while interacting with a brand — from awareness to purchase and often into post-purchase advocacy. It includes all the touchpoints a customer experiences across channels and devices.
Imagine buying a mobile phone:
You see a YouTube ad → Read reviews → Visit the store → Compare prices online → Buy → Leave a review
That’s a customer journey.
🧭 Why It Matters in Marketing Analytics
-
Helps marketers map where customers are dropping off
-
Enables precise targeting and messaging at each stage
-
Essential for building attribution models (MTA)
-
Allows for personalized marketing and journey orchestration
📐 The Traditional Marketing Funnel (AIDA Model)
The funnel is a visual model that represents the stages of customer decision-making.
| Funnel Stage | Meaning | Example Touchpoints |
|---|---|---|
| Awareness | Customer becomes aware of your product | Social media ad, TV ad, blog, PR |
| Interest | Customer starts engaging and showing curiosity | Website visit, YouTube review, comparison |
| Desire | Customer wants the product or adds to wishlist/cart | Wishlisting, reading testimonials |
| Action | Customer takes final purchase action | Checkout, signup, payment completed |
🌀 Expanded Funnel (Modern B2B/B2C Model)
Modern customer journeys are non-linear. So we also use:
-
Retention – Ensuring customer returns or repeats purchase
-
Advocacy – Customer promotes the product (reviews, referrals)
| Funnel Stage | Key Metrics | Tools/Channels |
|---|---|---|
| Awareness | Reach, Impressions, Brand Lift | Ads, SEO, Events, Influencers |
| Interest | CTR, Bounce Rate, Time on Page | Website, Blog, Email, YouTube |
| Consideration | Return Visitors, Demo Requests | Case Studies, Testimonials, Comparisons |
| Intent | Add-to-Cart, Form Fill, Download | Retargeting, Email Reminders |
| Purchase | Conversion Rate, CPA, ROAS | Checkout Funnels, Payment Systems |
| Retention | Repeat Rate, Churn, CLV | Loyalty Programs, CRM, Push Notifications |
| Advocacy | NPS, Referral Rate, Reviews | Referral Campaigns, Social Sharing |
📊 Touchpoints in a Customer Journey
| Type | Examples |
|---|---|
| Paid Media | Google Ads, Facebook Ads, Influencer posts |
| Owned Media | Website, App, Email newsletters, Landing pages |
| Earned Media | PR mentions, customer reviews, user posts |
| Offline | TV, radio, events, retail visits |
🔄 Customer Journey in Multi-Touch Attribution (MTA)
MTA analyzes each touchpoint along the journey and assigns value/credit for the final action.
Example: A customer sees a Google ad, opens an email, clicks an Instagram post, and finally buys.
Each of these touches gets partial credit in data-driven attribution.
📚 Real-Life Example: Nike E-commerce Journey
-
Awareness – User sees a YouTube ad for Nike Air Max
-
Interest – Clicks and explores product page
-
Consideration – Adds to wishlist, reads reviews
-
Intent – Receives email with 10% discount
-
Action – Completes purchase via mobile app
-
Retention – Gets push notification for new collection
-
Advocacy – Shares product pic on Instagram
This journey includes multiple online and mobile touchpoints — perfect for MTA modeling.
🛠️ Tools to Analyze Customer Journey
| Tool | Use Case |
|---|---|
| Google Analytics | Funnel tracking, user flow, conversion paths |
| Hotjar / Clarity | Session recordings, heatmaps |
| HubSpot | CRM-based journey mapping |
| Mixpanel / Amplitude | Behavioral analytics, journey flows |
| Segment / Tealium | Journey data unification across tools |
🧠 Key Takeaways
-
Customer journey is no longer linear — it’s multi-channel and dynamic
-
Funnel stages help identify gaps and optimize marketing strategy
-
Each stage uses different KPIs and channel tactics
-
Understanding the journey is essential for building MTA and MMM models
📘 Module 2.1: What is Analytics in Marketing?
🔍 What is Marketing Analytics?
Marketing Analytics refers to the systematic measurement, management, and analysis of marketing performance to maximize its effectiveness and optimize return on investment (ROI). It involves collecting data, cleaning it, analyzing it, and making decisions based on patterns or trends.
Think of it as:
“Using data to make smarter marketing decisions.”
💡 Core Purpose
-
Understand your audience: What are they doing? What do they want?
-
Measure effectiveness: Are your campaigns working?
-
Optimize strategies: Where should you allocate your budget?
-
Predict future behavior: What will customers do next?
📊 Scope of Marketing Analytics
| Area of Focus | Examples of Use |
|---|---|
| Customer Analytics | Segmenting users, predicting churn, lifetime value analysis |
| Channel Analytics | Analyzing ROI from Facebook vs Google vs Email |
| Campaign Analytics | Tracking A/B tests, open rates, click-through rates |
| Sales Attribution | Assigning value to touchpoints across the journey |
| Pricing & Revenue | Testing pricing elasticity, forecasting revenue |
| Product Analytics | Tracking feature usage, funnel drop-offs, product retention |
📈 Types of Analytics in Marketing
1. Descriptive Analytics – What happened?
-
Answers: “How many people clicked the ad?” or “What was our revenue last quarter?”
-
Tools: Excel, Google Analytics
2. Diagnostic Analytics – Why did it happen?
-
Uses correlation and statistical tests to find reasons for trends
-
Example: “Why did conversions drop on mobile last week?”
3. Predictive Analytics – What will happen?
-
Uses machine learning, regression, and forecasting models
-
Example: Forecast next month’s revenue from current campaigns
4. Prescriptive Analytics – What should we do?
-
Recommends actions based on optimization algorithms
-
Example: Suggests optimal ad spend distribution across channels
🧠 Marketing Analytics vs Business Intelligence
| Feature | Marketing Analytics | Business Intelligence |
|---|---|---|
| Focus | Customer behavior, campaigns, conversions | Overall business metrics (revenue, ops) |
| Time Sensitivity | Fast-paced, real-time required | Often monthly/quarterly |
| Data Granularity | Session-level, click-level | Aggregate-level |
| Common Tools | Google Analytics, Mixpanel, CRM, ad dashboards | Power BI, Tableau, Excel |
🔄 Data Sources in Marketing Analytics
| Source | Type of Data |
|---|---|
| Website Tracking (GA4) | Traffic, bounce rate, session time |
| CRM Systems (Salesforce) | Customer profile, history, communication logs |
| Ad Platforms (Meta, Google) | Impressions, CTR, CPC, conversions |
| Email Marketing (Mailchimp) | Open rate, click rate, unsubscribes |
| Social Media (Instagram) | Engagement rate, followers, shares |
| Survey Tools (SurveyMonkey) | NPS, CSAT, qualitative insights |
🛠️ Common Tools & Platforms
| Category | Tools/Platforms |
|---|---|
| Data Collection | Google Analytics, Segment, Hotjar |
| Data Storage | BigQuery, Snowflake, MySQL |
| Visualization | Tableau, Power BI, Data Studio |
| Analysis | Python (Pandas, Scikit-Learn), R |
| Campaign Mgmt | Meta Ads Manager, Google Ads, HubSpot |
📌 Example Use Case: Launching a New Product
Scenario: You're launching a fitness app.
You would use marketing analytics to:
-
Track how many users clicked your ads → Descriptive
-
Understand which channel performs best → Diagnostic
-
Predict how many installs you’ll get next week → Predictive
-
Decide where to allocate next month’s budget → Prescriptive
📉 Analytics in MMM & MTA
-
In Marketing Mix Modeling (MMM), analytics helps quantify the effect of marketing spend over time, even when data is not user-level.
-
In Multi-Touch Attribution (MTA), analytics operates at the user level to track exact contribution of each channel in a customer’s journey.
Both require:
-
Clean, structured data
-
Deep statistical and machine learning knowledge
-
Strong business understanding
🧠 Summary Points
-
Marketing Analytics is the data-driven heart of modern marketing
-
It blends data science, business intelligence, and consumer psychology
-
Enables informed decisions across the funnel
-
Provides the foundation for building MMM & MTA models
-
Knowing how and what to measure is as important as the tools you use.
📘 Module 2.2: Types of Data – Structured vs Unstructured
🔍 What is Data in Marketing?
In marketing analytics, data is the fuel that powers decision-making. It includes every digital trace, customer interaction, or business metric — from a click on an ad to a 5-star review.
However, not all data is created equal. Data can be categorized based on its format and how it can be stored, analyzed, or visualized.
📂 Two Primary Types of Data
1. Structured Data
2. Unstructured Data
There’s also a semi-structured category (hybrid), which we’ll explore briefly.
🔷 1. Structured Data
Structured data is organized, clearly formatted, and stored in tabular form — typically in rows and columns (like Excel or databases).
✅ Characteristics
-
Easy to store in relational databases (SQL)
-
Machine-readable
-
Cleanly labeled with headers/fields (e.g., Name, Email, Revenue)
🧠 Examples in Marketing:
| Field | Example |
|---|---|
| Customer ID | 100394 |
| Campaign Name | Diwali Sale |
| Clicks | 248 |
| Conversion Rate (%) | 3.2 |
📊 Where It’s Found
-
CRM Systems (HubSpot, Salesforce)
-
Ad dashboards (Meta, Google Ads)
-
Google Analytics reports
-
SQL databases, Excel sheets
🟣 2. Unstructured Data
Unstructured data is not organized in a pre-defined model or format. It’s often rich in context but harder to process.
✅ Characteristics
-
Doesn’t fit easily in tables
-
May contain natural language, visuals, or audio
-
Requires NLP (Natural Language Processing) or Computer Vision for analysis
🧠 Examples in Marketing:
| Type | Example |
|---|---|
| Customer Reviews | “Loved the fast delivery!” |
| Social Media Posts | Instagram captions, tweets |
| Audio | Voice feedback from call centers |
| Video | YouTube product unboxings |
| Chat Transcripts | WhatsApp conversations with support |
📍 Where It’s Found:
-
Social platforms (Twitter, Reddit)
-
Customer support recordings
-
Feedback forms (open-ended answers)
-
Blogs, YouTube comments, product Q&A
🟡 3. Semi-Structured Data (Hybrid)
Semi-structured data is not tabular, but it follows some internal logic or format (like JSON or XML).
Examples:
-
Google Analytics API response (JSON)
-
Email metadata (headers + message body)
-
SurveyMonkey API response
💡 Why This Matters for Analytics
| Factor | Structured Data | Unstructured Data |
|---|---|---|
| Ease of Analysis | High – SQL, Excel, dashboards | Low – Needs text/image processing |
| Tooling | SQL, Python (pandas), Tableau | NLP libraries (spaCy, NLTK), CV models |
| Use in MMM | Critical (spend, sales, impressions) | Less common but growing (brand buzz) |
| Use in MTA | Mostly structured (clickstream data) | Used for feedback analysis |
📈 Role in MMM & MTA
MMM
-
Relies on structured data: Ad spend, price, weather, seasonality
-
May include external unstructured data (brand sentiment) as control variables
MTA
-
Clickstream data is structured, but
-
User feedback or support tickets can be used to fine-tune segments (unstructured)
🧠 Visual Summary
Structured → Excel, SQL Tables, CRM Fields
Unstructured → Tweets, Voice Memos, Images
Semi-Structured → JSON, XML, Email Logs
🛠 Tools for Handling Each Type
| Type | Tools/Techniques |
|---|---|
| Structured | Excel, MySQL, pandas (Python), Tableau |
| Unstructured | NLP (spaCy, BERT), TextBlob, OpenAI APIs |
| Semi-Structured | JSON parsers, Regex, NoSQL (MongoDB) |
🧪 Real-Life Case Study: Ecommerce Analytics
| Data Source | Data Type | Use Case |
|---|---|---|
| Website traffic logs | Structured | Funnel drop-off tracking |
| Product reviews | Unstructured | Sentiment analysis |
| Campaign metadata (JSON) | Semi-structured | Automated report generation |
📌 Key Takeaways
-
Structured data is tabular, easy to analyze, and critical for core marketing KPIs
-
Unstructured data offers rich customer insights, but requires advanced processing
-
MMM heavily depends on structured variables like spend, season, sales
-
MTA mainly uses structured path data, but sentiment data can enhance modeling
📘 Module 2.3: Data Collection Methods (Surveys, Web Logs, CRM, APIs)
🎯 Why is Data Collection Important?
Data collection is the first step in the analytics pipeline. The accuracy, depth, and source of data directly affect:
-
The reliability of models like MMM and MTA
-
The validity of performance reports
-
Your ability to segment, personalize, and predict customer behavior
“Garbage in = Garbage out.”
Bad or incomplete data leads to misleading insights and poor decisions.
🗃️ Primary Data vs Secondary Data
| Type | Description | Example |
|---|---|---|
| Primary | Data collected directly by the business | Surveys, user feedback, in-app tracking |
| Secondary | Data obtained from third-party sources | Nielsen reports, market databases |
🧩 Key Marketing Data Collection Methods
📋 1. Surveys & Questionnaires
Surveys are direct, intentional tools to gather structured and semi-structured data from users.
| Strengths | Limitations |
|---|---|
| Can target specific segments | Biased or dishonest responses |
| Good for NPS, satisfaction, intent | Low response rates if poorly designed |
✅ Tools: SurveyMonkey, Google Forms, Typeform
Use Cases:
-
NPS surveys
-
Post-purchase feedback
-
Market research surveys
-
Persona validation
🌐 2. Website & Mobile App Analytics (Web Logs)
Every visitor leaves behind a digital footprint — stored in the form of web logs or tracking data.
| What’s Tracked | Examples |
|---|---|
| Sessions | Total visits, new vs repeat |
| Behavior | Clicks, scrolls, time on page |
| Events | Add to cart, video views, form fills |
| Sources | From where did the user arrive? |
✅ Tools: Google Analytics 4 (GA4), Hotjar, Mixpanel, Firebase
Use Cases:
-
Funnel tracking
-
Landing page optimization
-
A/B test evaluation
-
User drop-off analysis
🧑💼 3. CRM Systems (Customer Relationship Management)
CRMs store structured customer profile and interaction data, often across sales, support, and marketing.
| Captured Data | Description |
|---|---|
| Customer Info | Name, Email, Company, Industry |
| Engagement | Email opens, call logs, meeting notes |
| Purchase History | Orders, lifetime value, churn status |
✅ Tools: Salesforce, HubSpot, Zoho, Freshworks
Use Cases:
-
Lead scoring & segmentation
-
Targeted email campaigns
-
Personalization at scale
-
Churn prediction
🧪 4. APIs & SDKs (Automated Data Integration)
Application Programming Interfaces (APIs) and Software Development Kits (SDKs) allow automated, real-time data transfer between platforms.
| Source | API Use Example |
|---|---|
| Facebook Ads API | Pull ad spend, clicks, CPM per campaign |
| Google Ads API | Track keyword conversions, ROI |
| Mailchimp API | Fetch open rates, bounce reports |
| Shopify API | Sales, orders, inventory flow |
✅ Languages: Python, R, Postman (for testing)
Use Cases:
-
MMM raw data aggregation
-
MTA log-level conversion tracking
-
Automated dashboarding (Tableau, Power BI)
📸 5. Social Listening & UGC (User-Generated Content)
These tools scrape or collect unstructured data from platforms like Twitter, YouTube, Reddit, or Instagram.
| What’s Tracked | Tools Used |
|---|---|
| Mentions, tags, hashtags | Brandwatch, Sprout Social, Meltwater |
| Sentiment analysis | MonkeyLearn, IBM Watson NLP |
| Influencer impact | HypeAuditor, Upfluence |
Use Cases:
-
Crisis management (negative spikes)
-
Trend detection
-
Competitive benchmarking
-
Brand perception analysis
🧾 6. Transaction Systems (POS, Payment Gateways)
This includes purchase logs, POS system records, and billing platforms that collect structured purchase data.
| What’s Tracked | Example |
|---|---|
| Time of purchase | Timestamped sales |
| Amount spent | Average order value, upsell success |
| SKU-level data | Which items were bought |
✅ Tools: Razorpay, Stripe, PayPal, Zoho Books, Shopify POS
🧠 Data Collection for MMM vs MTA
| Factor | MMM (Marketing Mix Modeling) | MTA (Multi-Touch Attribution) |
|---|---|---|
| Data Granularity | Weekly/monthly aggregated | User-level clickstream |
| Channel Focus | Traditional + Digital | Digital-only (mostly) |
| Time Lag | Captures lag effects (TV → sales after 2 weeks) | Real-time or short windows |
| Tools | ETL + Excel + Python + Ad platforms | Web analytics tools + CRM logs + custom tracking |
📌 Key Takeaways
-
Marketing data comes from multiple sources: surveys, websites, apps, CRMs, APIs
-
Knowing where and how to collect clean, relevant data is critical for analysis
-
MMM uses aggregated campaign/channel data, MTA uses detailed user journeys
-
Tools like Google Analytics, HubSpot, and APIs enable automated and scalable collection
-
Always balance privacy (GDPR/CCPA) with collection needs
📘 Module 2.4: Data Sources in Marketing
🔍 What Are Data Sources?
A data source in marketing refers to any platform, system, or touchpoint where information about customers, campaigns, behaviors, or outcomes is generated and stored.
Marketing data sources are typically categorized based on:
-
Who owns the data (first-party, second-party, third-party)
-
Where it's captured (online, offline, hybrid)
-
How structured it is (structured vs unstructured)
🧠 Importance of Understanding Data Sources
-
Ensures data quality and governance
-
Helps choose the right analytics tools and models
-
Affects attribution logic (where did the conversion come from?)
-
MMM and MTA both depend on properly integrated sources
📂 Types of Data Based on Ownership
| Type | Description | Example |
|---|---|---|
| First-Party | Data you collect directly from your customers | CRM data, website analytics, surveys |
| Second-Party | Someone else's first-party data shared with you (via partnership) | Retailer sharing customer insights |
| Third-Party | Aggregated external data purchased or licensed | Nielsen, Oracle BlueKai, Experian |
🔷 Major Marketing Data Sources
🖥️ 1. Web & App Analytics Tools
These tools capture behavioral data from websites and mobile apps.
| Tool | What It Captures |
|---|---|
| Google Analytics 4 (GA4) | Sessions, bounce rate, funnel flow, user journey |
| Mixpanel / Amplitude | Event-based tracking: signups, button clicks, feature use |
| Firebase Analytics | In-app behavior for mobile apps |
✅ Use in MTA: Tracks user touchpoints for clickstream-level attribution
✅ Use in MMM: Provides traffic data trends over time
💬 2. CRM Systems (Customer Relationship Management)
Stores detailed customer data and all touchpoints across sales, support, and marketing.
| Tool | What It Stores |
|---|---|
| Salesforce | Lead score, contact history, deal status |
| HubSpot | Email opens, blog reads, conversions |
| Zoho CRM | Custom forms, pipeline stages |
✅ Use in MTA: Personal-level tracking of behavior → conversion
✅ Use in MMM: Aggregated contact-based metrics
📧 3. Email Marketing Platforms
Track campaigns, automate sequences, and capture engagement data.
| Tool | Metrics Captured |
|---|---|
| Mailchimp | Open rate, click rate, unsubscribe, A/B test results |
| SendGrid | Delivery status, bounce rate, spam reports |
| MoEngage / CleverTap | In-app message performance, push campaigns |
✅ Useful for lifecycle marketing analysis
✅ Input into both MMM (weekly email performance) and MTA (click path)
📱 4. Ad Platforms (Performance and Paid Media)
Crucial source for marketing spend, impressions, CTR, cost, and revenue attribution.
| Platform | What It Tracks |
|---|---|
| Google Ads | Impressions, CPC, Quality Score, ROAS |
| Meta (Facebook/IG) | CPM, video views, custom audiences |
| LinkedIn Ads | B2B campaign-level metrics |
✅ Core input for MMM models
✅ User-level campaign flow for MTA
🏪 5. E-Commerce & POS Systems
Collect transactional data and customer behavior at checkout.
| Tool | Data Captured |
|---|---|
| Shopify / WooCommerce | SKU sales, cart value, drop-off, product clicks |
| Stripe / Razorpay | Purchase values, frequency, success/failure |
| Retail POS | Sales by store, location, channel |
✅ Core source for dependent variable (sales) in MMM
✅ Used for revenue attribution in MTA
📢 6. Social Media & Listening Tools
Collect unstructured brand engagement and audience insights.
| Platform | Data Type |
|---|---|
| Instagram, X | Likes, comments, mentions |
| Sprinklr / Hootsuite | Scheduled campaigns, sentiment |
| Brandwatch | Competitor tracking, trend reports |
✅ Less used in core MMM but useful for sentiment as an external driver
✅ Adds emotional context to quantitative MTA
📦 7. Third-Party Data Providers
You can augment internal data with external demographic, geographic, or competitive intelligence.
| Provider | Data Offered |
|---|---|
| Nielsen, Kantar | TV ratings, offline media spend |
| Experian | Consumer finance and segmentation |
| Statista / GWI | Global trend data, market benchmarks |
✅ Used in MMM to supplement hard-to-get data
✅ Not directly used in MTA but helps enrich modeling
🧠 Summary Table: Data Sources by Use Case
| Use Case | Key Data Source |
|---|---|
| Campaign Performance | Meta Ads, Google Ads |
| Customer Lifecycle | HubSpot, Salesforce |
| Website Behavior | Google Analytics, Hotjar |
| Attribution Modeling | GA4, CRM, APIs |
| Product Analytics | Mixpanel, Amplitude |
| Sales Forecasting (MMM) | Ad Spend + Sales Logs + CRM |
| Social Sentiment | Twitter + Social Listening Tools |
📌 Key Takeaways
-
Marketing data comes from a blend of owned, partner, and third-party platforms
-
Choose your sources based on your analytics goal (MMM, MTA, or CX analysis)
-
MMM focuses on channel- and region-level aggregated data
-
MTA focuses on user-level journey data with timestamps
-
Know the data format, update frequency, and privacy rules of each source
📘 Module 2.5: Exploratory Data Analysis (EDA) in Marketing
🧠 What is EDA?
Exploratory Data Analysis (EDA) is the process of visually and statistically exploring datasets to understand their structure, patterns, relationships, and anomalies before applying any modeling or machine learning.
Think of EDA as “asking the data questions before trusting it.”
🎯 Goals of EDA
-
Understand distributions, trends, and outliers
-
Detect data quality issues (nulls, duplicates, errors)
-
Identify feature relationships (correlation, causation candidates)
-
Segment your audience or behavior
-
Form hypotheses for deeper analysis
📦 What EDA Looks Like in Marketing
| Task | Marketing Example |
|---|---|
| Missing value detection | Missing campaign spend in January |
| Outlier detection | One campaign with 10x CTR than others |
| Trend analysis | Email open rates decreasing month-over-month |
| Funnel performance | Drop-off at cart or signup step |
| Correlation analysis | Facebook spend vs. conversions over time |
| Customer segmentation | Cluster customers by purchase value and frequency |
🔧 EDA Workflow (Step-by-Step)
🔹 Step 1: Load and Inspect the Data
-
Use Excel, SQL, Python (pandas), or R (tidyverse)
-
Check for:
-
Number of rows and columns
-
Column types (numeric, categorical, datetime)
-
Sample values (e.g.,
.head()in pandas)
-
🔹 Step 2: Clean the Data
-
Handle:
-
Missing values (fill, drop, impute)
-
Duplicates
-
Inconsistent formats (date vs string, lowercase vs UPPERCASE)
-
-
Tools: Python (pandas
isnull(),dropna()), Excel filters
🔹 Step 3: Univariate Analysis
-
Analyze one variable at a time:
-
Numerical: Histogram (e.g., spend per campaign)
-
Categorical: Bar chart (e.g., device type usage)
-
🔹 Step 4: Bivariate Analysis
-
Analyze relationships:
-
Scatter plot: Ad spend vs conversions
-
Box plot: Conversion rate by device
-
Heatmap: Correlation matrix
-
🔹 Step 5: Time Series Checks (if applicable)
-
For MMM: Plot sales vs spend over weeks/months
-
Look for:
-
Seasonality
-
Trends
-
Sudden spikes (campaigns, festivals)
-
🔹 Step 6: Feature Engineering Ideas
-
Create new fields:
-
ROAS = Revenue / Spend
-
Day of week
-
Email Click-to-Open Ratio (CTOR)
-
-
Normalize (if needed) before modeling
📊 Key Charts in EDA for Marketing Analysts
| Chart Type | Used For |
|---|---|
| Histogram | Ad spend distribution, time on site |
| Box Plot | Comparing CTR across channels |
| Line Plot | Weekly revenue trends |
| Heatmap | Correlation between spend, traffic, sales |
| Funnel Plot | Drop-off in customer journey |
| Pie Chart | Campaign budget split by channel |
✅ Tools: Excel, Google Sheets, Python (Matplotlib, Seaborn), R (ggplot2), Tableau
🧪 Real-Life EDA Example: Performance Marketing Campaign
| Column | Sample EDA Insight |
|---|---|
Spend |
One ad had ₹10,000 spend while others were ~₹1,000 |
Conversions |
High CTR campaigns don’t always lead to high sales |
Platform |
Instagram has better engagement; Google better sales |
Date |
Drop in conversions during holiday week |
🔁 EDA in MMM & MTA
| Model Type | EDA Role |
|---|---|
| MMM | - Analyze seasonality and campaign trends |
- Understand adstock/saturation behavior
- Check for multicollinearity across spend channels |
| MTA | - Explore user journey paths
- Check for device/channel drop-offs
- Normalize event sequences for modeling |
⚠️ Common EDA Pitfalls
| Mistake | Consequence |
|---|---|
| Ignoring missing values | Leads to biased or invalid models |
| Not removing outliers | Inflates or distorts model impact |
| Misinterpreting correlation | False assumptions about cause-effect |
| Failing to visualize | Missed pattern or hidden relationships |
📌 Summary
-
EDA is your first diagnostic scan of marketing data
-
It helps uncover trends, clean issues, and shape features
-
MMM and MTA are only as good as the data you explore before modeling
-
Use charts, correlations, and time-series plots to guide strategy
📘 Module 3.1: Descriptive Statistics in Marketing Analytics
🔍 What Are Descriptive Statistics?
Descriptive statistics are numerical and graphical methods used to summarize and describe the basic features of a dataset. They help answer:
“What does the data look like?”
“How are the values distributed?”
“Where is the center, and how spread out is the data?”
Unlike inferential statistics (which draws conclusions), descriptive stats simply describe what is.
🎯 Why Are Descriptive Stats Important in Marketing?
-
Understand campaign performance at a glance
-
Compare audiences, channels, regions
-
Spot patterns, seasonality, and inconsistencies
-
Prepare data for modeling (MMM, MTA, regression)
🧠 Key Descriptive Statistical Concepts
📍 1. Measures of Central Tendency – Where is the data centered?
| Measure | Definition | Example (Ad Spend) |
|---|---|---|
| Mean | Average value | Total spend ÷ number of campaigns |
| Median | Middle value in sorted list | Useful when data is skewed |
| Mode | Most frequently occurring value | Common spend level among ads |
✅ Why it matters:
-
Use mean to track average performance
-
Use median to avoid distortion by outliers
-
Use mode to spot typical behavior patterns
📍 2. Measures of Dispersion – How spread out is the data?
| Measure | Definition | Use in Marketing |
|---|---|---|
| Range | Max - Min | Spending variation across campaigns |
| Standard Deviation (SD) | Avg. deviation from mean | Consistency of campaign performance |
| Variance | Square of SD (used in modeling formulas) | Predictive variability |
| Interquartile Range (IQR) | Spread of the middle 50% of data | Useful for outlier detection |
✅ High SD = Data is volatile
✅ Low SD = More predictable performance
📍 3. Frequency Distribution
A frequency distribution shows how often values occur in ranges or bins.
Example:
-
CTR < 1% → 10 campaigns
-
CTR 1–3% → 20 campaigns
-
CTR > 3% → 5 campaigns
✅ Use histograms or bar plots to visualize frequency
✅ Helps define high-performers vs average vs poor campaigns
📍 4. Percentiles & Quartiles
These divide data into segments for comparison:
-
25th percentile (Q1): Lower quartile
-
50th percentile (Q2): Median
-
75th percentile (Q3): Upper quartile
-
90th percentile: Often used to track top campaign performance
✅ Helps answer: “How good is this result compared to the rest?”
📍 5. Outlier Detection
Outliers are extreme values that deviate significantly from others.
| Technique | Usage |
|---|---|
| Box Plot | Visualize IQR and outliers |
| Z-score | Standard score — values >±3 are flagged |
| Domain knowledge | Know when a spike is genuine (e.g., festival sale) |
✅ Outliers can either be:
-
Valid and insightful (e.g., viral ad)
-
Errors (e.g., data entry issue)
📊 Descriptive Stats in Marketing Examples
| Metric | Descriptive Use Case |
|---|---|
| ROAS | Mean/Median ROAS across channels |
| Email CTR | SD of click-through rate per campaign |
| Campaign Spend | Identify high-spend outliers |
| Website Bounce Rate | Frequency distribution of bounce segments |
| Sales by Region | Compare median sales across geographies |
🛠 Tools for Descriptive Statistics
| Tool | Features |
|---|---|
| Excel | Built-in formulas (=AVERAGE(), etc.) |
| Python (Pandas) | .mean(), .std(), .describe() |
| R (dplyr) | summarise(), sd(), quantile() |
| Tableau/Power BI | Visual summaries and statistical panels |
💡 Descriptive Stats in MMM & MTA
| Model | How Descriptive Stats Are Used |
|---|---|
| MMM | - Pre-model check of spend distribution |
- Weekly trends, SD across channels
- Identifying diminishing return points |
| MTA | - Understand touchpoint frequency
- Session time, conversion lag
- Funnel depth summary before modeling |
⚠️ Cautions When Using Descriptive Stats
| Mistake | Impact |
|---|---|
| Relying only on means | Outliers may distort results |
| Ignoring distribution | Two datasets can have same mean, different shape |
| Not visualizing | Miss patterns or cyclical trends |
📌 Summary
-
Descriptive statistics summarize your marketing data without assumptions
-
Use central tendency and dispersion together for a full view
-
Visualize distributions and outliers before modeling
-
They help you spot opportunities or anomalies in campaign performance
-
In MMM/MTA, they’re the first quality check for modeling inputs
📘 Module 3.2: Inferential Statistics in Marketing Analytics
🧠 What is Inferential Statistics?
Inferential statistics is the process of using sample data to make generalizations or decisions about a larger population. It lets us test hypotheses, estimate relationships, and measure uncertainty.
For marketers, it helps answer:
“Is this campaign really better than the last?”
“Are Facebook leads more likely to convert than Instagram ones?”
🎯 Why Inferential Statistics Matter in Marketing
-
Compare the effectiveness of two channels or campaigns
-
Test if an observed result is statistically significant
-
Make predictions about future customer behavior
-
Validate MMM coefficients or A/B test results
🔑 Core Concepts in Inferential Statistics
📍 1. Population vs Sample
| Term | Description | Example |
|---|---|---|
| Population | The full set of entities you're studying | All users who saw your Diwali ad |
| Sample | A subset of that population used for analysis | 1,000 users from Bengaluru |
✅ In marketing, we rarely analyze entire populations, so we use samples + inference.
📍 2. Parameter vs Statistic
-
Parameter = a true value in the population (unknown)
-
Statistic = a measured value from a sample (known)
We use sample statistics to estimate population parameters.
📍 3. Confidence Intervals (CI)
A confidence interval gives a range of values within which we believe the true population metric lies — with a level of confidence (often 95%).
Example:
"Conversion rate is 3.5% ± 0.6% with 95% confidence"
This means: we’re 95% confident the actual CR is between 2.9% and 4.1%.
📍 4. Hypothesis Testing
Used to test if an assumption or difference is statistically valid.
| Step | Description |
|---|---|
| Null Hypothesis (H₀) | There is no effect or difference |
| Alternative Hypothesis (H₁) | There is a significant effect/difference |
| P-value | Probability of observing the result if H₀ is true |
| Alpha level (α) | Commonly 0.05 (5% threshold for rejecting H₀) |
✅ If p < 0.05 → Reject the null hypothesis → Significant result
📍 5. Types of Tests in Marketing
| Test Type | Use Case Example |
|---|---|
| Z-test | Large samples, known variance — CTR comparison |
| T-test (independent) | Small samples — email open rate in group A vs group B |
| Paired T-test | Same users before/after campaign |
| Chi-square test | Compare categorical outcomes — clicks across platforms |
| ANOVA | Compare 3+ group means — ROAS across multiple channels |
📈 Real-World Marketing Examples
📊 Example 1: Email Campaign Test
| Group A | Group B |
|---|---|
| 5.1% open rate | 6.4% open rate |
| Sample size = 5,000 | Sample size = 5,000 |
You can apply a t-test to check if this difference is significant or due to random variation.
📊 Example 2: Conversion Rate by Channel (Chi-square Test)
You want to check if the conversion rate differs significantly by channel:
| Channel | Conversions | No Conversion |
|---|---|---|
| 130 | 870 | |
| 110 | 890 | |
| Google Ads | 150 | 850 |
Chi-square test checks if the conversion distribution is uniform across groups.
📉 Inference in MMM and MTA
| Model | Role of Inferential Statistics |
|---|---|
| MMM | Validate significance of model coefficients |
(e.g., “Is TV spend significantly impacting sales?”) |
| MTA | Evaluate feature importance using confidence levels
(e.g., “How confidently can we assign credit to Email?”) |
| A/B Tests | Statistical backbone of all split-testing |
⚠️ Common Pitfalls to Avoid
| Mistake | Impact |
|---|---|
| Confusing correlation with causation | May assume a channel is “driving” results when it's just correlated |
| Misusing p-value | Low p-value doesn't always mean high business impact |
| Small sample size | Makes results unstable, even if statistically “significant” |
🛠 Tools for Inferential Statistics
| Tool | Features |
|---|---|
| Python (SciPy, statsmodels) | ttest_ind, ztest, confidence intervals |
| R (t.test, chisq.test) | Easy to apply on campaign datasets |
| Excel (Data Analysis Toolpak) | T-tests, Z-tests |
| Tableau | Statistical summary dashboards |
📌 Summary
-
Inferential stats help you test, predict, and conclude using sample data
-
Core to A/B testing, MMM regression validation, and user behavior modeling
-
Understand confidence intervals, p-values, and hypothesis testing logic
-
Always pair statistics with business sense — statistical ≠ practical impact
📘 Module 3.3: Hypothesis Testing in Marketing Analytics
🧠 What is Hypothesis Testing?
Hypothesis Testing is a statistical method used to test an assumption (hypothesis) about a population based on sample data. It helps marketers decide:
-
Is one campaign truly better than another?
-
Did a change in pricing really increase conversions?
-
Should we allocate more budget to Google or Meta?
In short: “Are the observed differences meaningful or just due to chance?”
🔍 Key Concepts in Hypothesis Testing
1. Null Hypothesis (H₀)
This is the default assumption — that there is no effect or difference.
Example: “There’s no difference in CTR between Email A and Email B.”
2. Alternative Hypothesis (H₁)
This is what we’re trying to prove — that a significant difference or effect exists.
Example: “Email A has a significantly higher CTR than Email B.”
3. P-value
The probability of getting the observed result (or more extreme) if the null hypothesis is true.
A small p-value (usually < 0.05) means the observed result is unlikely under H₀ — so we reject it.
4. Alpha (α)
The threshold of significance, typically set at 0.05 (5%).
If p < α, we reject H₀ and accept H₁.
5. Types of Errors
| Type | Description |
|---|---|
| Type I Error (False Positive) | Rejecting H₀ when it’s actually true (false alarm) |
| Type II Error (False Negative) | Failing to reject H₀ when H₁ is actually true |
🎯 Step-by-Step Hypothesis Testing Process
🔹 Step 1: Define the Hypotheses
Let’s say you're comparing two email subject lines:
-
H₀: Open rate A = Open rate B
-
H₁: Open rate A ≠ Open rate B
🔹 Step 2: Choose Significance Level (α)
-
Standard: 0.05 (5% chance of a false positive)
🔹 Step 3: Select the Right Test
| Situation | Statistical Test |
|---|---|
| Comparing two means (independent) | T-test |
| Paired before/after results | Paired T-test |
| Proportions or rates | Z-test / Chi-square |
| 3 or more group means | ANOVA |
🔹 Step 4: Calculate Test Statistic and P-value
Use Excel, Python, R, or tools like:
-
ttest_indin Python (SciPy) -
T.TESTin Excel -
t.test()in R
🔹 Step 5: Compare P-value to α and Make Decision
-
If p < α → Reject H₀ → Significant difference
-
If p ≥ α → Fail to reject H₀ → No significant difference
📊 Example: A/B Test on Landing Pages
| Variant | Visitors | Conversions | Conversion Rate |
|---|---|---|---|
| Page A | 1000 | 40 | 4% |
| Page B | 1000 | 55 | 5.5% |
Hypotheses:
-
H₀: Conversion Rate A = Conversion Rate B
-
H₁: Conversion Rate A ≠ Conversion Rate B
Run a two-sample Z-test. Suppose you get:
-
p = 0.038
-
α = 0.05
✅ Result: Since p < α → Reject H₀ → Page B performs significantly better.
🧪 Hypothesis Testing in MMM & MTA
| Use Case | Hypotheses Setup |
|---|---|
| MMM Coefficient Significance | H₀: TV Spend Coefficient = 0 |
| H₁: TV Spend Coefficient ≠ 0 |
| MTA Path Importance | H₀: Channel X doesn't affect conversion
| H₁: Channel X significantly contributes |
| Retargeting vs Cold Campaigns | H₀: No difference in ROAS
| H₁: Retargeting has better ROAS |
⚠️ Best Practices and Cautions
| Rule | Why It Matters |
|---|---|
| Always define hypotheses clearly | Prevents misinterpretation |
| Don’t rely solely on p-value | Consider effect size and business impact too |
| Avoid “p-hacking” | Running multiple tests until something becomes significant |
| Ensure good sample size | Small samples increase error risk |
🛠 Tools for Hypothesis Testing
| Tool | Capabilities |
|---|---|
| Excel | T-tests, Z-tests via Analysis ToolPak |
| Python (SciPy) | ttest_ind, ttest_rel, proportions_ztest, chi2_contingency |
| R (stats) | t.test(), chisq.test(), aov() |
| Google Optimize | Built-in A/B testing platform |
📌 Summary
-
Hypothesis testing allows you to validate marketing results using math, not guesswork
-
Always define null and alternative hypotheses before testing
-
Use the right statistical test for your data type (mean vs proportion vs category)
-
P-value < 0.05 generally indicates statistical significance
-
Hypothesis testing is central to A/B testing, MMM, and MTA validation
📘 Module 3.4: Correlation vs Causation in Marketing Analytics
🧠 Why This Topic Matters
Imagine this situation:
"Every time we increase Instagram ads, sales go up. Instagram must be the reason!"
But what if:
-
A holiday sale also happened during that time?
-
Other channels like TV or email were also active?
This is where correlation and causation come into play — and this distinction is at the core of proper marketing attribution and modeling.
🔍 1. What is Correlation?
Correlation is a statistical measure that describes the strength and direction of a relationship between two variables.
It does not imply causation.
🔹 Pearson Correlation Coefficient (r)
Value of r |
Relationship Type |
|---|---|
| 1.0 | Perfect Positive Correlation |
| 0.0 | No Correlation |
| -1.0 | Perfect Negative Correlation |
✅ Example:
-
r = +0.89 between YouTube ad views and sales → Strong correlation
-
r = -0.55 between cart abandonment rate and revenue → Moderate negative correlation
📈 Visualization Example
-
Positive: 📈 As ad spend increases, conversions increase
-
Negative: 📉 As bounce rate increases, revenue decreases
-
No correlation: 🌀 Clicks and newsletter signups fluctuate independently
🔍 2. What is Causation?
Causation means that one variable directly causes the change in another.
If X causes Y, then changing X will predictably change Y.
✅ Example:
-
Running a paid ad campaign leads to an increase in site visits
-
Offering a coupon increases purchases
🛑 But causation is hard to prove. It often requires:
-
Controlled experiments (A/B testing)
-
Time-lagged analysis
-
Elimination of confounding variables
🧪 Correlation vs Causation: Key Differences
| Aspect | Correlation | Causation |
|---|---|---|
| Definition | Relationship or association | One variable directly affects another |
| Directionality | No direction implied | Clear direction of effect |
| Example | Rain and umbrella sales | Ice cream discount → increase in orders |
| Proves Cause? | ❌ No | ✅ Yes (if tested properly) |
| Tested via | Correlation Coefficient, Scatterplots | A/B Testing, MMM, Controlled Experiments |
🛠 In Marketing Context
| Scenario | Is It Correlation or Causation? |
|---|---|
| Facebook spend increases alongside sales | Correlation (unless tested causally) |
| Running a retargeting campaign boosts repeat orders | Causation (if tracked with control group) |
| TV ad runs and foot traffic increases | Correlation unless time-lag and control channels analyzed |
| Email campaign A leads to higher signups than B | Causation (if randomized A/B test used) |
🔬 How MMM & MTA Handle This
🟦 Marketing Mix Modeling (MMM)
-
Uses regression and adstock/saturation functions to estimate causal impact
-
Controls for seasonality, other channels, pricing, etc.
-
Can estimate:
“TV contributes 12% of weekly sales, with diminishing returns.”
✅ MMM is better suited for causation, but only if:
-
The model is well-controlled
-
Lag effects and external factors are accounted for
🟩 Multi-Touch Attribution (MTA)
-
Tracks user-level paths and interactions
-
Correlation-heavy, especially in rules-based models (first/last touch)
-
More advanced MTA (e.g., Shapley values, ML-based) can approximate causality
✅ Use caution when interpreting MTA output as causal — unless you’ve tested via experimentation
🧠 Common Pitfall Examples
| Correlation Claim | Why It Might Be Misleading |
|---|---|
| "TV ads always boost sales" | Was there also a festive season? Price drop? Competitor exit? |
| "Customers who read blogs spend more" | Maybe loyal customers are already blog readers |
| "People who use our app love it" | Survivorship bias — maybe dissatisfied users quit early |
✔️ How to Get Closer to Causation
-
Run A/B Tests
-
Hold back a control group
-
Randomize exposure
-
-
Use Time Series Modeling
-
Check if sales follow spend with a lag
-
Use Granger causality tests
-
-
Control for Confounders
-
Remove effects of seasonality, promos, other channels
-
-
Use advanced attribution
-
MMM with regularization, Bayesian modeling
-
MTA with Markov chains or Shapley values
-
📌 Summary
-
Correlation ≠ Causation — a classic analytics trap
-
Always visualize, measure, and test your assumptions
-
MMM is built to estimate causality, but only if model controls are strong
-
MTA shows association across journeys, but causal claims require validation
-
Experiments and domain knowledge are essential complements to analytics
📘 Module 4.1: Excel Functions for Marketing Analysts
🧠 Why Excel for Marketing Analytics?
Excel remains the most accessible and widely used tool for:
-
Cleaning and transforming marketing data
-
Performing quick calculations on campaign performance
-
Creating dashboards, funnel tables, and pivot charts
-
Running descriptive statistics and early hypothesis tests
Even in MMM and MTA, Excel often serves as the first staging area before modeling begins.
🎯 Most Useful Excel Functions for Analysts
🔹 1. SUM, AVERAGE, COUNT, COUNTA, MIN, MAX
These are foundational functions for basic descriptive stats.
| Function | Description | Example |
|---|---|---|
=SUM(range) |
Adds up all values | =SUM(B2:B100) — Total spend |
=AVERAGE() |
Returns mean value | CTR, ROAS |
=COUNT() |
Number of numeric entries | =COUNT(C2:C100) |
=COUNTA() |
Number of non-empty cells | =COUNTA(D2:D100) |
=MAX()/MIN() |
Highest/lowest in a range | Best vs worst campaign ROAS |
🔹 2. IF, IFS, AND, OR
For conditional logic and segmentation.
| Function | Example Use |
|---|---|
=IF(A2>500, "High", "Low") |
Classify campaigns by budget |
=IF(AND(B2>3,C2<2), "OK", "Fail") |
Campaign must meet multiple conditions |
=IFS() |
Multiple condition checks without nesting |
🔹 3. VLOOKUP, XLOOKUP, INDEX-MATCH
Used to merge tables or look up data across sheets — vital for joining campaign-level data with source files.
| Function | Use Case |
|---|---|
=VLOOKUP(ID, Table, Col, FALSE) |
Match Customer ID with spend data |
=INDEX(Table, MATCH(value, Col, 0)) |
More flexible alternative |
=XLOOKUP() |
Newer, more powerful version of VLOOKUP |
🔹 4. TEXT, LEFT, RIGHT, MID, CONCAT, TEXTJOIN
Used for data cleaning, parsing UTM codes, channel names, etc.
| Use | Example |
|---|---|
=LEFT(A2, 5) |
Extract first 5 letters |
=RIGHT(B2, 4) |
Get last 4 digits from campaign ID |
=MID(C2, 6, 3) |
Get middle part of string |
=CONCAT(A2, " - ", B2) |
Join strings with a dash |
=TEXT(D2, "0.00%") |
Format conversion rate nicely |
🔹 5. LEN, TRIM, CLEAN, PROPER
Perfect for cleaning messy input data, especially in CRM exports or ad manager dumps.
| Function | What It Does |
|---|---|
=LEN(A2) |
Counts characters |
=TRIM() |
Removes leading/trailing spaces |
=CLEAN() |
Removes non-printable characters |
=PROPER() |
Capitalizes first letter of each word |
🔹 6. RANK, PERCENTRANK, QUARTILE, NTILE (via formulas)
For ranking campaigns, finding top performers, and performance banding.
| Function | Use Case |
|---|---|
=RANK.EQ(A2, Range) |
Rank campaigns by ROAS |
=PERCENTRANK() |
Percentile performance tier |
=QUARTILE() |
Place campaigns into quartiles (Q1–Q4) |
🔹 7. SUMIF, COUNTIF, AVERAGEIF (+ *IFS versions)
Used for segmented analysis (e.g., by channel, region, status).
| Function Example | What It Does |
|---|---|
=SUMIF(Channel, "Facebook", Spend) |
Total spend on Facebook |
=COUNTIF(Status, "Completed") |
Number of completed campaigns |
=AVERAGEIFS(ROAS, Channel, "Email", Type, "Promotional") |
Avg ROAS by segment |
🔹 8. NOW(), TODAY(), DATE(), YEAR(), MONTH()
For date filtering, time period grouping, and comparisons.
| Example Use | Description |
|---|---|
=TODAY()-A2 |
Days since campaign started |
=MONTH(D2) |
Extract campaign month |
=YEAR(D2)=2023 |
Filter only current year |
🔹 9. Pivot Tables & Slicers
✅ Drag-and-drop interface to:
-
Summarize spend by region, campaign, or channel
-
Show conversion rate by funnel stage
-
Add filters and interactive slicers
Great for:
-
Ad hoc reporting
-
Client-facing dashboards
-
MMM data summaries (weekly spend by channel)
🔹 10. Charts & Visualizations
| Chart Type | Used For |
|---|---|
| Line Chart | Weekly trend of conversions/spend |
| Bar Chart | ROAS by channel |
| Pie Chart | Campaign spend split |
| Combo Chart | Spend vs Revenue |
| Funnel Chart | Website journey steps |
💡 Excel in MMM/MTA Prep
| Use Case in MMM/MTA | Excel Function You’d Use |
|---|---|
| Weekly spend summarization | SUMIFS, Pivot Table |
| Lagged impact calculation | OFFSET(), LAG() (custom) |
| Normalization for modeling | =Z.SCORE(), custom mean/SD |
| Campaign tagging | LEFT(), MID(), TEXT() |
📌 Summary
-
Excel remains a versatile, essential tool for early-stage marketing analysis
-
Mastering functions like
VLOOKUP,SUMIFS,TEXT, andRANKwill save hours -
Pivot Tables + Formulas + Visuals = Quick Dashboards
-
Excel is often the launchpad for deeper modeling in Python, R, or BI tools
📘 Module 4.2: Pivot Tables & Dashboards for Marketing Analytics
🧠 Why Use Pivot Tables?
A Pivot Table allows you to summarize, group, and analyze large datasets quickly and dynamically. For marketing analytics, this means:
-
Summarizing campaign performance by channel, region, device, etc.
-
Comparing KPIs like spend, conversions, ROAS, CTR
-
Creating dynamic reports without writing formulas
-
Building the backend for a marketing dashboard
📊 Key Pivot Table Concepts
| Concept | Description |
|---|---|
| Rows | The category you want to group by (e.g., Channel) |
| Columns | Optional — use to compare categories side-by-side |
| Values | What you want to calculate (e.g., SUM of Spend) |
| Filters | Add conditions like date range or campaign type |
| Slicers | Visual buttons to filter your pivot interactively |
🎯 Typical Marketing Use Cases
| Task | Pivot Table Use |
|---|---|
| Analyze performance by channel | Rows = Channel, Values = SUM(Spend), SUM(Revenue) |
| Compare ROAS by region | Rows = Region, Values = Revenue / Spend |
| Weekly trend analysis | Rows = Week, Values = Conversions |
| Email campaign A/B performance | Rows = Subject Line, Values = Open/Click Rates |
| Device split of website traffic | Rows = Device, Values = Sessions |
🛠 Step-by-Step: Create a Pivot Table in Excel
-
Select your raw data table
-
Go to
Insert→Pivot Table -
Choose to place it on a new worksheet
-
Drag fields into:
-
Rows (e.g., Campaign Name)
-
Columns (e.g., Channel or Region)
-
Values (e.g., Spend, Conversions, ROAS)
-
Filters (e.g., Date Range, Campaign Status)
-
✅ Excel will auto-summarize based on the value types
✅ You can right-click to show as % of Total, change aggregation type (SUM, AVERAGE, COUNT)
💡 Pro Tips
-
Use Calculated Fields to add custom metrics like ROAS = Revenue / Spend
-
Use Group by Date to analyze by week, month, or quarter
-
Enable Show Values As → % of Grand Total to get share of spend/sales
-
Format numbers with
%, currency, or conditional formatting
🎛️ Creating Dashboards in Excel
A dashboard is a visual interface built with charts, pivot tables, slicers, and KPI indicators to track performance.
🔹 Core Dashboard Elements for Marketing
| Component | Example |
|---|---|
| Pivot Table | Spend by channel, conversion rate by campaign |
| Pivot Chart | Line chart for trends, bar chart for comparison |
| Slicers | Channel, Region, Date, Campaign Type |
| KPI Cards | Total Spend, Total Sales, Avg ROAS |
| Filters | Interactive control to drill into segments |
✅ Combine 2–3 Pivot Charts + 1–2 KPI blocks
✅ Use named ranges, cell links, and formatting to create polished dashboards
📈 Example Dashboard View
-
Top Section:
-
Total Conversions
-
Avg ROAS
-
Bounce Rate
-
-
Middle Section:
-
Bar chart: ROAS by Channel
-
Line chart: Spend vs Sales (Weekly)
-
-
Bottom Section:
-
Table with campaigns + slicers to filter by Region/Platform
-
💼 Real-World Use Case
| Scenario | Dashboard Element |
|---|---|
| You manage 20 paid campaigns across 4 regions | Pivot chart with ROAS by region/campaign |
| Your manager wants a monthly report | Filter pivot table by Month, export to PDF |
| You're preparing MMM input | Pivot by Week, Channel, Spend |
🧠 Summary
-
Pivot Tables are your go-to tool for quick, powerful summaries
-
Combine with charts, slicers, and formatting for impactful dashboards
-
Great for MMM model inputs, MTA validation, or marketing performance tracking
-
Build once → reuse and refresh as new data arrives.
📘 Module 4.3: SQL Basics — SELECT, WHERE, GROUP BY for Marketing Analysts
🧠 Why Learn SQL for Marketing Analytics?
-
Most marketing data lives in databases (MySQL, PostgreSQL, BigQuery, Redshift, Snowflake)
-
SQL lets you query, clean, and segment raw data efficiently
-
Critical for generating input tables for MMM, customer segmentation, funnel analysis, and MTA datasets
SQL helps answer:
“How much did we spend by week and channel?”
“Which campaigns drove the most conversions in Q2?”
“What’s the ROAS per region?”
🔑 Core SQL Commands in This Module
🔹 1. SELECT
The SELECT statement retrieves data from one or more columns in a table.
Syntax:
SELECT column1, column2, ...
FROM table_name;
Example:
SELECT campaign_name, spend, conversions
FROM marketing_campaigns;
📌 Use Case: Fetch specific columns (e.g., spend and revenue) to prepare for ROAS calculation.
🔹 2. WHERE
The WHERE clause filters rows based on specified conditions.
Syntax:
SELECT column1, column2
FROM table_name
WHERE condition;
Example 1: Filter campaigns from Google Ads:
SELECT campaign_name, channel, spend
FROM marketing_campaigns
WHERE channel = 'Google';
Example 2: Filter only high-spend campaigns:
WHERE spend > 10000;
Example 3: Multiple conditions:
WHERE channel = 'Facebook' AND conversions > 50;
🔹 3. GROUP BY
GROUP BY aggregates data based on unique values in one or more columns — ideal for summarizing metrics like total spend per channel.
Syntax:
SELECT column1, AGG_FUNCTION(column2)
FROM table_name
GROUP BY column1;
Common aggregation functions:
-
SUM() -
COUNT() -
AVG() -
MAX() -
MIN()
Example: Total spend and conversions per channel:
SELECT channel, SUM(spend) AS total_spend, SUM(conversions) AS total_conversions
FROM marketing_campaigns
GROUP BY channel;
Example: Weekly sales summary
SELECT DATE_TRUNC('week', campaign_date) AS week_start, SUM(revenue)
FROM marketing_campaigns
GROUP BY week_start;
📌 You can also combine with WHERE:
SELECT region, SUM(revenue)
FROM sales_data
WHERE campaign_type = 'Email'
GROUP BY region;
🧪 Real-World Marketing Examples
| Objective | SQL Query Pattern |
|---|---|
| Total ROAS by channel | SELECT channel, SUM(revenue)/SUM(spend) |
| Conversion rate for last month | WHERE date BETWEEN ... + SUM() |
| Number of campaigns by region | GROUP BY region + COUNT() |
| Filter failed campaigns | WHERE status = 'Failed' |
🔧 Sample Table: marketing_campaigns
| campaign_id | campaign_name | channel | spend | conversions | revenue | campaign_date |
|---|---|---|---|---|---|---|
| 101 | New Year Sale | 5000 | 50 | 12000 | 2024-12-29 | |
| 102 | Diwali Push | 8000 | 80 | 20000 | 2024-11-02 |
🔄 Combining All: A Full Example
SELECT
channel,
COUNT(*) AS total_campaigns,
SUM(spend) AS total_spend,
SUM(revenue) AS total_revenue,
ROUND(SUM(revenue)/SUM(spend), 2) AS roas
FROM marketing_campaigns
WHERE campaign_date >= '2024-01-01'
GROUP BY channel;
✅ This query gives you:
-
Number of campaigns per channel
-
Total spend and revenue
-
ROAS (Return on Ad Spend) per channel
-
Filters for 2024 campaigns
🧠 Summary
| SQL Concept | What It Does |
|---|---|
SELECT |
Pick specific columns |
WHERE |
Filter records based on conditions |
GROUP BY |
Summarize data by categories (channel, region) |
| Aggregates | SUM(), AVG(), COUNT() for KPIs |
✅ These are the core building blocks for:
-
MMM data prep (weekly spend, grouped summaries)
-
MTA data breakdown (events per user/channel)
-
Campaign reporting dashboards
📘 Module 4.4: Advanced SQL for Segmentation & Funnel Analysis
🧠 Why This Matters
In real-world marketing:
-
You don’t just want total users — you want “new users in Bangalore who visited 3 times but never converted.”
-
You don’t just want conversion rate — you want to build a funnel like:
Visited Website → Added to Cart → Purchased
SQL gives you the tools to filter, group, and rank data so you can analyze complex marketing questions at scale.
🔑 Key Concepts Covered
-
Conditional
CASE WHEN -
Segmentation with
GROUP BY -
Funnels using
JOIN,WITH, andRANK() -
Customer cohorts, behavior flags, and event steps
🔹 1. Using CASE WHEN for Segmentation
The CASE WHEN clause allows custom grouping and segmentation inside queries.
Example: Segment users based on spend:
SELECT
customer_id,
spend,
CASE
WHEN spend < 500 THEN 'Low'
WHEN spend BETWEEN 500 AND 2000 THEN 'Medium'
ELSE 'High'
END AS spend_segment
FROM customers;
✅ Output: Adds a new column spend_segment with category labels
📊 Use Case: Segmenting by device type
SELECT
device_type,
COUNT(*) AS user_count,
CASE
WHEN device_type = 'mobile' THEN 'Mobile'
ELSE 'Desktop/Web'
END AS device_segment
FROM user_sessions
GROUP BY device_segment;
🔹 2. Funnel Analysis with Joins & Steps
Funnels track how many users progress through sequential stages.
| Funnel Stage | Event Name |
|---|---|
| 1. Site Visit | page_view |
| 2. Product View | product_view |
| 3. Add to Cart | add_to_cart |
| 4. Purchase | purchase |
🛠 Sample Table: user_events
| user_id | event_name | event_time |
|---|---|---|
| 101 | page_view | 2024-11-01 10:00 |
| 101 | product_view | 2024-11-01 10:05 |
| 101 | add_to_cart | 2024-11-01 10:06 |
| 101 | purchase | 2024-11-01 10:08 |
Step-by-step Funnel Query
WITH steps AS (
SELECT user_id,
MAX(CASE WHEN event_name = 'page_view' THEN 1 ELSE 0 END) AS step_1,
MAX(CASE WHEN event_name = 'product_view' THEN 1 ELSE 0 END) AS step_2,
MAX(CASE WHEN event_name = 'add_to_cart' THEN 1 ELSE 0 END) AS step_3,
MAX(CASE WHEN event_name = 'purchase' THEN 1 ELSE 0 END) AS step_4
FROM user_events
GROUP BY user_id
)
SELECT
COUNT(*) AS users_started,
SUM(step_2) AS viewed_product,
SUM(step_3) AS added_to_cart,
SUM(step_4) AS purchased,
ROUND(100.0 * SUM(step_4) / COUNT(*), 2) AS funnel_conversion_rate
FROM steps;
✅ Output: Funnel stage drop-offs + overall conversion rate
🔹 3. Cohort Segmentation (by signup or behavior)
Group users by their first touch date, channel, region, or custom event.
SELECT
DATE_TRUNC('month', signup_date) AS signup_month,
COUNT(*) AS new_users
FROM users
GROUP BY signup_month
ORDER BY signup_month;
Advanced Cohort: Retention Analysis
WITH first_sessions AS (
SELECT user_id, MIN(session_date) AS signup_date
FROM sessions
GROUP BY user_id
)
SELECT
f.signup_date,
s.session_date,
COUNT(DISTINCT s.user_id) AS retained_users
FROM first_sessions f
JOIN sessions s ON f.user_id = s.user_id
WHERE s.session_date > f.signup_date
GROUP BY f.signup_date, s.session_date;
✅ Output: Retention trends by cohort month
🔹 4. Ranking Users or Campaigns
Use RANK() or DENSE_RANK() to sort and find top performers.
SELECT *,
RANK() OVER (PARTITION BY region ORDER BY revenue DESC) AS revenue_rank
FROM campaigns;
✅ Use Case: Find top 3 campaigns per region by revenue
📊 Marketing Examples You Can Solve with This
| Question | SQL Approach |
|---|---|
| How many users converted after viewing a product? | WITH + CASE funnel steps |
| What % of users added to cart but didn’t purchase? | Funnel with drop-off rate logic |
| Who are our top 10 customers by spend? | ORDER BY spend DESC LIMIT 10 |
| What is weekly ROAS by region and segment? | GROUP BY week, region, segment |
🧠 Summary
| Skill | Use Case |
|---|---|
CASE WHEN |
Create dynamic segments |
GROUP BY |
Aggregate metrics by segment, region, campaign |
WITH CTEs |
Funnel and cohort staging |
RANK() |
Find top customers or campaigns |
| Funnels via events | Track user journey and calculate conversion |
📘 Module 5.1: Data Wrangling with pandas (Python) and dplyr (R)
🧠 What is Data Wrangling?
Data wrangling (also known as data munging) is the process of cleaning, transforming, and organizing raw data into a format suitable for analysis.
"Wrangling" means taming messy data — fixing nulls, renaming columns, joining tables, reshaping layouts, and extracting relevant features.
🔧 Tools of Choice
| Language | Library | Usage |
|---|---|---|
| Python | pandas |
Ideal for scripting and automation |
| R | dplyr |
Ideal for statistical pipelines and dashboards |
Both are widely used in marketing analytics, and interchangeable for many operations.
📦 Sample Dataset: marketing_campaigns.csv
| campaign_id | channel | spend | conversions | revenue | campaign_date |
|---|---|---|---|---|---|
| 101 | 5000 | 50 | 12000 | 2024-12-29 | |
| 102 | 8000 | 80 | 20000 | 2024-11-02 |
🐍 In Python (pandas)
1. Loading Data
import pandas as pd
df = pd.read_csv("marketing_campaigns.csv")
2. View Structure
df.head()
df.info()
df.describe()
3. Rename Columns
df.rename(columns={'campaign_date': 'date'}, inplace=True)
4. Filter Rows
df[df['channel'] == 'Google']
df[df['spend'] > 5000]
5. Add New Columns
df['ROAS'] = df['revenue'] / df['spend']
6. Group & Aggregate
df.groupby('channel')[['spend', 'revenue']].sum()
df.groupby('channel')['ROAS'].mean()
7. Datetime Handling
df['date'] = pd.to_datetime(df['date'])
df['month'] = df['date'].dt.month
8. Missing Values
df.isnull().sum()
df.fillna(0, inplace=True)
9. Sort, Rank
df.sort_values(by='ROAS', ascending=False)
df['rank'] = df['ROAS'].rank(method='dense', ascending=False)
🧮 In R (dplyr)
1. Load Data
library(dplyr)
df <- read.csv("marketing_campaigns.csv")
2. View Summary
glimpse(df)
summary(df)
3. Rename Columns
df <- rename(df, date = campaign_date)
4. Filter Rows
df %>% filter(channel == "Google", spend > 5000)
5. Create New Column
df <- df %>% mutate(ROAS = revenue / spend)
6. Group & Summarize
df %>%
group_by(channel) %>%
summarise(
total_spend = sum(spend),
avg_roas = mean(ROAS)
)
7. Working with Dates
library(lubridate)
df$date <- ymd(df$date)
df <- df %>% mutate(month = month(date))
8. Missing Values
colSums(is.na(df))
df[is.na(df)] <- 0
📊 Real-World Marketing Wrangling Examples
| Objective | Functionality Used |
|---|---|
| Calculate ROAS | mutate() in R or df['ROAS'] = ... in Python |
| Aggregate weekly revenue | group_by(date) + summarise() |
| Filter high-performing campaigns | filter(ROAS > 2) |
| Join spend and conversion datasets | merge() in pandas / left_join() in R |
🧠 Summary
| Action | pandas (Python) | dplyr (R) |
|---|---|---|
| Load Data | pd.read_csv() |
read.csv() |
| Filter | df[df[‘col’]==val] |
filter() |
| Group & Aggregate | groupby() + .sum() |
group_by() + summarise() |
| Add Column | df['new'] = |
mutate() |
| Handle Dates | pd.to_datetime() |
ymd(), month() |
📘 Module 5.2: Visualizations with Plotly & ggplot2 for Marketing Dashboards
🧠 Why Data Visualization?
Data visualization helps you tell a compelling story with data — turning raw numbers into patterns, trends, and outliers that are easy to understand and act upon.
In marketing: “What’s performing well?” “Where’s the drop-off?” “What’s the ROI trend over time?”
🧰 Tools Covered
| Language | Library | Best For |
|---|---|---|
| Python | Plotly |
Interactive visualizations (web apps, dashboards) |
| R | ggplot2 |
Publication-quality static charts with grammar of graphics |
🐍 Visualizing with Plotly (Python)
1. Install & Import
pip install plotly
import plotly.express as px
📊 Example 1: ROAS by Channel (Bar Chart)
fig = px.bar(df, x='channel', y='ROAS', color='channel', title='ROAS by Channel')
fig.show()
📈 Example 2: Weekly Spend & Revenue (Line Chart)
df['week'] = df['date'].dt.to_period('W').astype(str)
fig = px.line(df, x='week', y='spend', title='Weekly Spend Trend', markers=True)
fig.show()
🧭 Example 3: Campaign Funnel (Funnel Chart)
fig = px.funnel(
x=[10000, 7000, 3000, 1500],
y=["Page Views", "Product Views", "Cart Adds", "Purchases"],
title="Marketing Funnel"
)
fig.show()
🧱 Example 4: ROAS Distribution (Box Plot)
fig = px.box(df, x='channel', y='ROAS', title='ROAS Distribution by Channel')
fig.show()
✅ Highly interactive → Hover, zoom, click
📐 Visualizing with ggplot2 (R)
1. Load ggplot2
library(ggplot2)
📊 Example 1: Bar Chart of ROAS by Channel
ggplot(df, aes(x = channel, y = ROAS, fill = channel)) +
geom_bar(stat = "identity") +
theme_minimal() +
labs(title = "ROAS by Channel")
📈 Example 2: Line Chart – Weekly Spend
ggplot(df, aes(x = date, y = spend)) +
geom_line(color = "blue") +
geom_point() +
labs(title = "Weekly Spend Trend") +
theme_light()
📦 Example 3: Boxplot – ROAS Distribution
ggplot(df, aes(x = channel, y = ROAS)) +
geom_boxplot() +
labs(title = "ROAS Distribution by Channel") +
theme_classic()
📉 Example 4: Funnel Chart (approx. with bar width)
funnel <- data.frame(
step = c("Visited", "Viewed", "Cart", "Purchased"),
users = c(10000, 7000, 3000, 1500)
)
ggplot(funnel, aes(x = step, y = users)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() +
labs(title = "Marketing Funnel")
📊 Ideal Visuals for Marketing Analytics
| Chart Type | Use Case |
|---|---|
| Line Chart | Trend of spend, conversions, CTR over time |
| Bar Chart | ROAS by region/channel |
| Funnel Chart | Stage-wise drop-offs (visit → view → buy) |
| Box Plot | Variation in performance across channels |
| Heatmap | Correlation of KPIs (ROAS, CTR, Bounce) |
| Pie Chart (sparingly) | Budget allocation visualization |
📌 Summary
| Skill | Python (Plotly) | R (ggplot2) |
|---|---|---|
| Trend Analysis | px.line() |
geom_line() |
| Group Comparison | px.bar() / px.box() |
geom_bar() / geom_boxplot() |
| Funnels | px.funnel() |
Horizontal bar approximation |
| Interactive Dash | Plotly Dash / Streamlit integration | R Shiny or static reporting |
✅ Visuals are often fed into dashboards, reports, or Jupyter notebooks before decision-making.
📘 Module 5.3: Regression Analysis for Marketing
🧠 Why Regression Matters in Marketing
Regression analysis allows us to understand and quantify:
“How much impact does advertising spend have on sales?”
“If we increase TV budget by 10%, what’s the expected change in revenue?”
“Which marketing channels truly drive performance?”
It is the core engine behind Marketing Mix Modeling (MMM) and is used to:
-
Attribute sales to different marketing efforts
-
Estimate ROI and marginal returns
-
Predict future performance
🧪 What is Regression?
Regression is a statistical method for modeling the relationship between:
-
A dependent variable (e.g., Sales, Conversions)
-
One or more independent variables (e.g., Spend on TV, Google Ads, Seasonality)
🔹 Types of Regression
| Type | Use Case |
|---|---|
| Linear Regression | Modeling sales as a function of spend |
| Multiple Regression | Use many inputs (e.g., TV, Radio, Season) |
| Logistic Regression | Predicting probability (e.g., will convert or not) |
| Polynomial | For non-linear effects like diminishing returns |
✍️ Regression Equation
Simple Linear Regression:
Where:
-
Y= Sales (dependent variable) -
X= TV Spend (independent variable) -
β₀= Intercept -
β₁= Slope (change in Y for each unit of X) -
ε= Error term
Multiple Regression:
e.g., Sales = β₀ + β₁ * TV + β₂ * Digital + β₃ * Seasonality + ε
🧮 Key Concepts to Understand
| Concept | Meaning |
|---|---|
| Coefficient (β) | Shows impact of each variable on the output |
| R² (R-squared) | % of variation in Y explained by the model (0–1 scale) |
| p-value | Tells if the coefficient is statistically significant |
| Multicollinearity | When two X variables are too correlated |
| Heteroskedasticity | Variance of error terms changes across data |
🐍 Regression in Python (using statsmodels)
import pandas as pd
import statsmodels.api as sm
# Load data
df = pd.read_csv('marketing_campaigns.csv')
# Independent vars and Dependent var
X = df[['tv_spend', 'google_spend', 'season_index']]
y = df['sales']
# Add constant to X
X = sm.add_constant(X)
# Fit model
model = sm.OLS(y, X).fit()
# View summary
print(model.summary())
✅ Outputs:
-
Coefficients (impact size)
-
R² (model fit)
-
p-values (significance)
📐 Regression in R
df <- read.csv("marketing_campaigns.csv")
model <- lm(sales ~ tv_spend + google_spend + season_index, data = df)
summary(model)
✅ Same: coefficients, R², p-values
🔎 Interpreting the Output
| Metric | Interpretation |
|---|---|
| Intercept | Sales expected when all spends are 0 |
| TV Coef. | Additional sales from ₹1 more on TV |
| p-value < 0.05 | Coefficient is statistically significant |
| R² = 0.85 | 85% of sales variation explained by ad spend inputs |
🧠 Common Pitfalls
| Mistake | Solution |
|---|---|
| Using raw spends | Use transformed data (log, lag, adstock) |
| Ignoring multicollinearity | Check VIF, remove correlated features |
| Assuming linearity always | Add square terms or use polynomial regression |
| Ignoring time dependency | Use time series regression or lags |
🔁 Marketing Use Cases
| Use Case | How Regression Helps |
|---|---|
| Marketing Mix Modeling | Estimate impact of each channel |
| ROI estimation | Find marginal returns on ad spend |
| Budget allocation | Predict sales from reallocated spend |
| Seasonality control | Add dummy variables for holidays/seasons |
| Price elasticity | Add price as a predictor to model |
✅ Practice Task
Given a dataset with:
-
Weekly spend on TV, Facebook, Google
-
Revenue, conversions, season_index
Try:
-
Build a multiple regression model: Revenue ~ TV + FB + Google + Season
-
Interpret coefficients and p-values
-
Check R² score
-
Predict next week’s revenue from a new media plan
📘 Module 5.4: Time Series Basics for Marketing Analytics
🧠 Why Time Series Matters in Marketing
Time series analysis helps us analyze and forecast performance over time, such as:
-
Weekly sales or revenue trends
-
Seasonal spikes in demand (festivals, holidays, etc.)
-
Campaign lag effects
-
Forecasting future performance
-
Preparing inputs for Marketing Mix Modeling (MMM) and Prophet models
🧾 What is a Time Series?
A time series is a sequence of data points collected over time at regular intervals.
| Example: Weekly Revenue Data |
| Date | Revenue |
|---|---|
| 2024-01-01 | ₹12,000 |
| 2024-01-08 | ₹14,500 |
| 2024-01-15 | ₹13,900 |
🧩 Key Characteristics of Time Series
| Concept | Description |
|---|---|
| Trend | Long-term movement (upward/downward) |
| Seasonality | Repeating short-term cycles (weekly, monthly, yearly) |
| Cyclicality | Irregular fluctuations not tied to calendar cycles |
| Noise | Random variation or residual component |
| Stationarity | Constant mean and variance over time |
| Lag/Shift | How past values influence future ones (e.g. 1-week lag) |
📌 Time Series Components Decomposition
Any time series can be expressed as:
Or in multiplicative form (if variation grows with time):
🛠 Time Series in Python (pandas, statsmodels)
1. Load and Prepare
import pandas as pd
df = pd.read_csv("weekly_sales.csv")
df['date'] = pd.to_datetime(df['date'])
df.set_index('date', inplace=True)
2. Visualize Time Series
import matplotlib.pyplot as plt
df['sales'].plot(figsize=(12, 4), title="Weekly Sales")
plt.show()
3. Decompose Series
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(df['sales'], model='additive', period=52)
result.plot()
plt.show()
✅ Output: Trend, Seasonal, Residual plots
4. Check for Stationarity
from statsmodels.tsa.stattools import adfuller
result = adfuller(df['sales'])
print(f"ADF Statistic: {result[0]}")
print(f"p-value: {result[1]}")
📌 If p-value < 0.05 → series is stationary (good for modeling)
5. Lag Features for MMM/MTA
df['sales_lag1'] = df['sales'].shift(1)
df['sales_rolling'] = df['sales'].rolling(window=4).mean()
✅ Create lag variables for memory effect or rolling averages
📐 Time Series in R
df <- read.csv("weekly_sales.csv")
df$date <- as.Date(df$date)
library(ggplot2)
ggplot(df, aes(x = date, y = sales)) + geom_line()
Decompose
ts_data <- ts(df$sales, frequency = 52)
decomposed <- decompose(ts_data)
plot(decomposed)
ADF Test for Stationarity
library(tseries)
adf.test(ts_data)
📊 Marketing Use Cases
| Use Case | Time Series Role |
|---|---|
| Forecasting next month’s revenue | Identify trend & seasonality |
| Media spend impact over time | Use lags of spend variables |
| Holiday promotion planning | Leverage seasonal spikes |
| MMM: Weekly sales vs ad variables | Use time-aligned, lag-adjusted input series |
| Adstock modeling | Time decay + lag structure |
🔁 Time Series Terminology Recap
| Term | Definition |
|---|---|
| Lag | Value from previous time step |
| Rolling Mean | Moving average over a window |
| Adstock | Lagged carryover effect of ad spend |
| Stationarity | No trend or seasonality, constant variance over time |
✅ Practice Task
-
Load weekly sales data
-
Plot and decompose time series
-
Add a 1-week lag and 4-week moving average column
-
Perform ADF test to check for stationarity
-
Interpret trend and seasonal components
📘 Module 6.1: What is Marketing Mix Modeling (MMM)?
🧠 Why MMM Matters
Marketing Mix Modeling helps answer critical questions like:
-
What’s the ROI of each marketing channel?
-
How much of sales can be attributed to paid vs organic channels?
-
How do price, promotions, seasonality, and ad spend drive performance?
✅ It uses statistical modeling (usually regression-based) on historical data to quantify the impact of marketing inputs on business outcomes (e.g., revenue, sales).
📈 MMM Model Structure
MMM is typically built as a multiple linear regression model:
Where:
-
TV, Digital, Promotions: Independent variables (marketing inputs)
-
β coefficients: Estimated contribution of each factor
-
ε: Error term (unexplained variation)
🎯 Inputs for MMM
| Type | Variables |
|---|---|
| Marketing | TV spend, digital spend, search ads, email campaigns |
| External | Seasonality, holidays, economic indicators |
| Brand | Promotions, price changes |
| Time | Lagged effects, trends, carryovers |
🧪 Assumptions of MMM
-
Linear or transformed relationships between inputs and outcomes
-
No perfect multicollinearity among variables
-
Historical patterns continue in future (for forecasting)
-
Data at consistent time intervals (weekly/monthly)
🔁 Preprocessing for MMM
1. Log or Square-root Transformation
Reduces skewness and stabilizes variance:
df['log_sales'] = np.log(df['sales'])
2. Adstock Transformation
To capture carryover effect of media spend:
def adstock_transform(series, decay):
result = [series[0]]
for i in range(1, len(series)):
result.append(series[i] + decay * result[i-1])
return result
df['tv_adstock'] = adstock_transform(df['tv_spend'], decay=0.5)
🔍 Feature Engineering for MMM
-
Lag Variables: e.g., 1-week lag of digital spend
-
Rolling Averages: e.g., 4-week moving average
-
Seasonality Dummies: e.g., holiday, month
-
Event Flags: e.g., new product launch, festive weeks
🛠 Simple MMM in Python (Using statsmodels)
import statsmodels.api as sm
X = df[['tv_adstock', 'digital_spend', 'promotion']]
X = sm.add_constant(X)
y = df['sales']
model = sm.OLS(y, X).fit()
print(model.summary())
✅ Coefficients show incremental impact of each variable on sales.
📊 Interpreting Coefficients
| Coefficient | Meaning |
|---|---|
| β₁ = 0.6 | Every ₹1,000 on TV gives ~₹600 extra sales (assuming no other variable changes) |
| β₂ = 1.2 | Digital marketing is more efficient in this case |
| β₃ = 0.9 | Promotions have strong direct impact |
📌 Limitations of MMM
-
Relies on historical data — can’t capture sudden changes
-
Hard to measure causality directly (correlation ≠ causation)
-
Not real-time — best used for strategic decisions, not daily ops
💡 When to Use MMM
| Situation | Use MMM? |
|---|---|
| Strategic planning (quarterly/yearly) | ✅ Yes |
| Tactical execution (real-time) | ❌ Use MTA or dashboards |
| Budget allocation across channels | ✅ Yes |
| ROI reporting to management | ✅ Yes |
✅ Practice Task
-
Load weekly sales and spend data.
-
Apply adstock transformation on TV and Digital spends.
-
Build a linear regression model to explain sales.
-
Interpret the contribution of each variable.
-
Calculate ROI:
📘 Module 6.2: History and Use Cases of MMM
🕰️ A Brief History of Marketing Mix Modeling (MMM)
| Period | Milestone |
|---|---|
| 1960s–70s | Pioneered by econometrics teams in CPG firms (e.g., P&G, Unilever). Used statistical methods to measure TV and print ad effects. |
| 1980s–90s | Adoption expanded across retail, automotive, and pharma. Modeling became more sophisticated with software tools like SAS, SPSS. |
| 2000s | Rise of digital marketing introduced new channels. MMM started integrating web metrics, but struggled with granularity. |
| 2010s | Attribution wars began: MMM vs MTA (Multi-Touch Attribution). Big data and cloud computing allowed faster MMM builds. |
| 2020s+ | MMM resurged due to privacy regulations (GDPR, iOS14) and cookie deprecation. Became a privacy-safe, media-mix planning method again. Open-source MMM tools (e.g., Robyn, LightweightMMM) gained popularity. |
🧠 Core Philosophy of MMM
-
It is top-down: Starts with aggregate (weekly/monthly) sales/revenue data.
-
Built on econometric modeling principles.
-
Answers the question: “What would happen to business outcomes if we increased or decreased spend on X channel?”
💼 Use Cases of MMM in Marketing
| Use Case | Description |
|---|---|
| Channel ROI Analysis | Measure how much incremental sales/revenue are driven by each channel (TV, digital, print, etc.). |
| Budget Allocation | Reallocate budget towards channels with higher ROI or marginal returns. |
| Campaign Effectiveness | Compare performance of different campaigns (pre-post impact, duration, geography). |
| Forecasting & Scenario Planning | Simulate different spend scenarios to plan future budgets and expected outcomes. |
| Promotion Planning | Measure impact of in-store or e-commerce promotions on short-term and long-term sales. |
| Product Launch Strategy | Evaluate effectiveness of launch spends across media types. |
| Brand Equity Impact | Estimate how brand-building spends (e.g., TV, sponsorship) contribute to long-term equity metrics. |
| Retail & Regional Strategy | Customize MMM by region or store clusters to optimize localized strategy. |
🎯 MMM vs MTA (Multi-Touch Attribution)
| Dimension | MMM | MTA |
|---|---|---|
| Data Level | Aggregate (weekly/monthly) | User-level (cookies, device IDs) |
| Channels | All (online & offline) | Mostly online |
| Granularity | Coarse (weekly/monthly) | Fine (real-time/user-level) |
| Privacy-friendly | ✅ Yes | ❌ Limited (cookie-dependent) |
| Strategic vs Tactical | Strategic | Tactical |
| Forecasting Capability | ✅ Strong | ❌ Limited |
| Handling Offline Channels | ✅ Yes | ❌ No |
🔄 Real-World Examples
| Brand | How MMM Helped |
|---|---|
| Coca-Cola | Used MMM to optimize TV vs digital budget split across regions |
| Spotify | Used MMM for top-down ROI estimation when user-level data was limited |
| Nestlé | Integrated MMM and MTA to unify online + offline attribution |
| D2C Brands | Used lightweight MMM (e.g., Robyn) to plan seasonal ad campaigns and promotions |
📌 MMM Is Ideal When...
-
You want to understand long-term brand effects
-
You need offline + online measurement (TV, print, digital)
-
Privacy limitations restrict user tracking (post-cookie world)
-
You operate at a national, regional, or store-level
🧠 Summary Recap
-
MMM is an old but evolving method in marketing analytics.
-
Great for high-level, budget-level decision making.
-
Robust for privacy-compliant measurement.
-
Complements MTA or dashboards—not a replacement.
-
Widely used in CPG, retail, finance, healthcare, and digital-first sectors today.
✅ Practice Task
-
List 3 scenarios in your business (real or imaginary) where MMM would be ideal.
-
Research one real brand and explain how it could use MMM to improve campaign strategy.
-
Think about your available data sources: Can you run an MMM model?
📘 Module 6.3: Marketing Channels and Media Spend in MMM
🧠 Why Understand Channels and Spend?
In MMM, media spend is one of the core input drivers. Accurately tracking and transforming spend data across channels is essential for understanding which channels drive business outcomes, and how to allocate budgets efficiently.
📡 Types of Marketing Channels in MMM
| Channel Type | Examples | Characteristics |
|---|---|---|
| Traditional (Offline) | TV, Radio, Print, Outdoor | High reach, brand-focused, long-term impact |
| Digital (Online) | Paid search, Display ads, YouTube, Meta ads, Influencer, Programmatic | Performance-driven, measurable, short-term impact |
| Owned Media | Email campaigns, Website, Mobile App, CRM messages | No direct cost per impression, measurable via logs |
| Earned Media | Word of mouth, PR, social shares | Not paid, hard to quantify directly |
| Trade Promotions | In-store discounts, bundling, coupons | Often short-term, but high sales lift |
| Brand Activities | Sponsorships, Events, Packaging | Long-term brand equity builder |
💸 Common Media Spend Variables in MMM
| Variable | Description |
|---|---|
tv_spend |
₹ spent on TV advertising per week |
digital_spend |
Sum of online channels (can be broken down by platform) |
search_spend |
₹ spent on Google/Bing paid search |
display_spend |
₹ spent on display/banner ads |
video_spend |
YouTube, OTT video ad spends |
email_sent |
Number of emails sent (cost ≈ internal resources) |
promo_discount |
% discount offered during promotion |
🔁 Weekly or Monthly Aggregation
MMM works best with time-aggregated data. Spend variables should match the granularity of your dependent variable (e.g., sales or leads).
df = df.resample('W').sum() # Aggregate to weekly
🧪 Transformations of Spend Data
Raw spend is often non-linear with business response. You’ll need to apply:
1️⃣ Adstock Transformation
To simulate carryover or memory effect of ad spend:
-
λ (lambda) = decay rate between 0 and 1 (e.g., 0.4–0.9)
def adstock_transform(x, decay):
result = [x[0]]
for i in range(1, len(x)):
result.append(x[i] + decay * result[i-1])
return result
df['tv_adstock'] = adstock_transform(df['tv_spend'], decay=0.6)
2️⃣ Saturation / Diminishing Returns
Most media has diminishing impact after a certain level of spend:
import numpy as np
df['search_saturation'] = np.log1p(df['search_spend'])
Alternative: Hill function or power transformation.
📊 Media Spend Input Example (Weekly)
| Week | TV Spend | Digital Spend | Search Spend | Promo Discount |
|---|---|---|---|---|
| 2024-01-01 | ₹100K | ₹80K | ₹25K | 5% |
| 2024-01-08 | ₹120K | ₹90K | ₹30K | 10% |
| 2024-01-15 | ₹110K | ₹85K | ₹20K | 0% |
You will apply lagging, adstock, or saturation based on campaign type.
🧠 Channel Selection Tips for MMM
-
Include channels with consistent spend and variation
-
Don’t include channels that don’t vary (regression won’t detect effect)
-
Align spend data with campaign dates and sales lag
-
Use media plans or agency data when internal data is missing
🎯 Spend Mapping by Funnel Stage
| Funnel Stage | Channels |
|---|---|
| Awareness | TV, YouTube, Display, Outdoor |
| Consideration | Paid search, Social, Influencer |
| Conversion | Email, CRM, Promotions |
| Retention | App Push, SMS, Loyalty Offers |
Different stages may show different lag and adstock behaviors.
✅ Practice Task
-
Create a sample weekly spend dataset with 3–5 channels
-
Apply
adstockandlogtransformations -
Plot raw vs transformed variables
-
Add them to a regression model and interpret coefficients
📘 Module 6.4: Building a Simple MMM Using Linear Regression
🧠 Objective
Build a basic Marketing Mix Model (MMM) using linear regression to estimate how different media spends contribute to sales.
📦 What You Need
-
Weekly or monthly sales data
-
Time-matched media spend data (TV, digital, search, etc.)
-
Optional: Promotion flags, seasonality, or holiday indicators
🛠 Step-by-Step: MMM in Python
🔹 Step 1: Load and Prepare the Data
import pandas as pd
df = pd.read_csv("weekly_marketing_data.csv")
df['date'] = pd.to_datetime(df['date'])
df.set_index('date', inplace=True)
df = df.sort_index()
Ensure your data is time-aligned and in weekly format.
🔹 Step 2: Apply Adstock and Saturation
import numpy as np
# Adstock transformation
def adstock(series, decay):
result = [series.iloc[0]]
for i in range(1, len(series)):
result.append(series.iloc[i] + decay * result[i - 1])
return result
df['tv_adstock'] = adstock(df['tv_spend'], decay=0.6)
df['digital_adstock'] = adstock(df['digital_spend'], decay=0.4)
# Saturation (log)
df['search_saturation'] = np.log1p(df['search_spend'])
🔹 Step 3: Feature Engineering
Add holiday flags, promotions, or trend variables if available:
df['week_number'] = df.index.isocalendar().week
df['promo_flag'] = (df['promo_discount'] > 0).astype(int)
🔹 Step 4: Define the Model
from statsmodels.api import OLS, add_constant
X = df[['tv_adstock', 'digital_adstock', 'search_saturation', 'promo_flag']]
X = add_constant(X)
y = df['sales']
model = OLS(y, X).fit()
print(model.summary())
✅ Output Interpretation
| Term | Meaning |
|---|---|
coef |
The estimated impact of a 1-unit change in the input variable |
p-value |
If < 0.05 → variable is statistically significant |
R-squared |
% of variance in sales explained by the model (higher is better) |
Adj. R-squared |
Adjusted for number of variables; more reliable for multiple predictors |
📈 Visualizing Predictions vs Actuals
import matplotlib.pyplot as plt
df['predicted_sales'] = model.predict(X)
df[['sales', 'predicted_sales']].plot(figsize=(12, 5))
plt.title("Actual vs Predicted Sales")
plt.show()
📊 Interpreting ROI from MMM
You can calculate the ROI of each channel like this:
For example:
print("TV ROI:", model.params['tv_adstock'])
✅ ROI here is interpreted as incremental sales per ₹1 spent on that channel (after transformation).
🔁 Optional: Residual Diagnostics
Check whether the model fits well and residuals are random (white noise).
residuals = model.resid
plt.plot(residuals)
plt.title("Residuals Over Time")
plt.axhline(0, linestyle='--', color='black')
plt.show()
📌 Summary
-
Built a working MMM model using linear regression
-
Applied adstock and log transformations
-
Analyzed coefficient significance, model fit, and ROI
-
Visualized actual vs predicted sales
✅ Practice Task
-
Use your own data or create a mock dataset with sales and 3 spend variables
-
Build your own linear regression model
-
Try different adstock decay values (0.3 to 0.8) and compare model accuracy
-
Interpret each variable’s contribution to sales
📘 Module 6.5: Challenges in MMM – Adstock & Diminishing Returns
🧠 Why This Matters
In real-world marketing, the impact of spend is not immediate, nor is it proportional to the amount spent:
-
Ads don’t instantly convert sales — they have memory effects.
-
More spend doesn't always mean more sales — there's a point of saturation.
MMM must account for these using:
-
Adstock (carryover effects)
-
Diminishing Returns (non-linear response)
🔁 1. Adstock – Modeling Carryover
📌 What Is It?
Adstock captures how the effect of a marketing activity persists over time.
Example: A TV ad shown today may influence sales for the next 2–3 weeks.
📉 Adstock Formula
Where:
-
(decay rate) ∈ [0, 1]
-
Higher → longer-lasting impact
🛠 Implement Adstock in Python
def adstock(series, decay):
result = [series.iloc[0]]
for i in range(1, len(series)):
result.append(series.iloc[i] + decay * result[i-1])
return result
Try tuning decay values like 0.3, 0.6, 0.9 to observe different lag strengths.
🔍 Challenge: How to Choose the Decay Rate?
| Approach | Description |
|---|---|
| Manual Testing | Try multiple values (0.3–0.9) and compare model performance |
| Grid Search | Automate decay tuning using regression R² or AIC as criteria |
| Bayesian Optimization | Used in tools like Meta’s Robyn for advanced tuning |
| Domain Knowledge | Use typical decay: TV (0.6–0.9), Digital (0.3–0.6), Search (0.1–0.3) |
📉 2. Diminishing Returns – Modeling Saturation
📌 What Is It?
Spending more doesn’t always generate proportionally more response.
₹10K digital spend may drive 100 leads
₹20K may not drive 200 leads — it might only drive 150
🎯 Common Transformations
| Type | Formula | Use When |
|---|---|---|
| Log | Most common, smooth curve | |
| S-curve (Hill Function) | More flexible, controls shape of saturation | |
| Square root | Simpler, less aggressive than log |
📊 Log Transformation Example in Python
import numpy as np
df['search_saturation'] = np.log1p(df['search_spend'])
✅ Benefit: Easy to interpret, avoids overfitting
🚫 Risk: May underfit channels with sharp saturation
🔧 Hill Function (Advanced)
def hill_transform(x, hill_coef=1.0, ec=1.0):
return (x ** hill_coef) / (x ** hill_coef + ec ** hill_coef)
Where:
-
hill_coefcontrols curve steepness -
ecis the spend level at 50% saturation
Used in advanced MMMs (like Meta’s Robyn).
❗ Challenges in Practice
| Challenge | Description | Solution |
|---|---|---|
| Selecting decay | Requires trial/error | Grid search or Robyn |
| Choosing saturation form | Depends on channel behavior | Compare log vs Hill visually |
| Combining adstock + saturation | Order matters | Usually: adstock → then transform |
| Overfitting | Too many parameters | Limit channels, cross-validation |
| Collinearity | Media channels overlap | Use variance inflation factor (VIF) analysis |
✅ Best Practices
-
Start with log + adstock for each media channel
-
Use different decay rates per channel
-
Plot response curves for intuition
-
Keep model parsimonious (fewer inputs > better explainability)
-
Use cross-validation or holdout testing for robustness
✅ Practice Task
-
Apply both log and adstock to media spend variables
-
Plot raw spend vs transformed spend
-
Build separate models:
-
One with raw spend
-
One with adstock only
-
One with adstock + log
Compare their R² and coefficients
-
📘 Module 7.1: What is Attribution?
🧠 Why Attribution Matters
Attribution answers a fundamental marketing question:
“Which touchpoints or channels contributed to a conversion or sale—and how much?”
In an omnichannel world, a user might interact with multiple marketing efforts before converting. Attribution helps allocate credit fairly to those interactions.
🎯 Definition
Attribution is the process of assigning credit or value to each marketing touchpoint that contributed to a desired outcome (e.g., purchase, sign-up, lead).
💡 Real-Life Example
A user’s journey:
-
Sees a YouTube ad
-
Searches on Google
-
Clicks a Facebook ad
-
Receives a promo email
-
Visits the website and buys
🤔 Which of these gets the credit for the sale?
That’s what attribution modeling tries to solve.
🔄 Attribution vs MMM
| Attribute | Attribution | MMM |
|---|---|---|
| Level | User-level | Aggregate (weekly/monthly) |
| Use Case | Tactical (optimize keywords, ads) | Strategic (optimize budgets) |
| Data Needs | Clickstream, cookies, UTM | Sales + media spend |
| Real-Time? | Often yes | No |
| Handles Offline? | Rarely | Yes |
✅ Attribution is bottom-up and event-based
✅ MMM is top-down and spend-based
💡 Together, they form a full-funnel measurement strategy
🧩 Types of Attribution Data
| Data Type | Examples |
|---|---|
| Clickstream | Web clicks, app events |
| Campaign metadata | UTM tags, ad IDs, platforms |
| Conversion event | Purchase, form fill, app install |
| User identifiers | Cookies, device IDs, hashed emails |
🔍 Common Conversion Events
| Type | Metric |
|---|---|
| E-commerce | Purchase amount |
| SaaS | Sign-up, demo request |
| Lead Gen | Form submit |
| App | Install, subscription |
📌 Why Attribution is Hard
-
Multiple devices and browsers (cross-device tracking)
-
Users may clear cookies or block trackers
-
Offline interactions like store visits or TV impressions are hard to link
-
Data privacy laws (GDPR, iOS 14) limit tracking
-
Walled gardens like Meta, Google, Amazon don’t share cross-platform data
🎯 When to Use Attribution Modeling
Use Attribution if:
✅ You want to know which ad/campaign/platform works best
✅ You manage digital performance campaigns (Google Ads, Meta, Email)
✅ You care about real-time optimization
✅ You want to compare touchpoint effectiveness
✅ Practice Task
-
Think of 3 touchpoints you interacted with before making your last online purchase
-
Map out the journey
-
How would you assign credit across them?
📘 Module 7.2: Rules-Based Attribution Models
🎯 First-Touch, Last-Touch, Linear, and More
🧠 What Are Rules-Based Models?
Rules-based attribution models assign credit to marketing touchpoints using predefined logic. They’re simple to implement and often used as a baseline for comparison.
They don’t require machine learning—just a logical rule.
📊 Common Rules-Based Models
| Model | Logic | Ideal When |
|---|---|---|
| First-Touch | 100% credit to the first interaction | When upper funnel awareness matters |
| Last-Touch | 100% credit to the last interaction before conversion | When last-mile conversions are key |
| Linear | Equal credit to all touchpoints in the journey | Balanced view across the funnel |
| Time Decay | More credit to recent touchpoints | For short sales cycles or urgency-based offers |
| U-Shaped | 40% to first + 40% to last + rest shared among middle | Emphasizes entry and closing efforts |
| W-Shaped | 30% each to first, lead creation, and last; rest distributed | For B2B with long funnel & lead nurturing |
| Custom Rules | Based on business logic (e.g., 50% digital, 50% offline) | When attribution needs align with strategy |
📘 1. First-Touch Attribution
-
📌 All credit to the first touchpoint
-
🧠 Good for evaluating brand awareness channels
User Journey: Facebook → Google Search → Website → Purchase
Credit: 100% Facebook
📘 2. Last-Touch Attribution
-
📌 All credit to the last click before conversion
-
🔍 Common default in Google Ads
User Journey: Instagram → Search Ad → Email → Purchase
Credit: 100% Email
📘 3. Linear Attribution
-
📌 Equal weight to every touchpoint
User Journey: Facebook → Search → Email → Purchase
Credit: 33.3% each
-
🧠 Good for multi-touch journeys where every step matters
📘 4. Time Decay Attribution
-
📌 More recent touches get more credit
-
⏱️ Older touches decay over time (often exponential decay)
User Journey: Day 1 (FB) → Day 3 (Google) → Day 5 (Email)
Credit: 10% FB, 30% Google, 60% Email
Useful for urgency-driven products or retargeting-focused campaigns
📘 5. U-Shaped (Position-Based)
-
📌 40% to first + 40% to last + 20% split between others
Journey: YouTube → Google → Email → Direct
Credit: YouTube 40%, Direct 40%, Google & Email 10% each
-
🧠 Highlights discovery and closing touchpoints
📘 6. W-Shaped Attribution
-
📌 30% to first touch, lead conversion, and last touch
-
Rest split across middle steps
Often used in B2B and SaaS to track awareness, MQL, and deal close
📦 Summary Table
| Model | First | Middle | Last | Best For |
|---|---|---|---|---|
| First-Touch | ✅ | ❌ | ❌ | Awareness |
| Last-Touch | ❌ | ❌ | ✅ | Conversions |
| Linear | ✅ | ✅ | ✅ | Balanced journeys |
| Time Decay | ⚠️ | ✅ | ✅ | Quick sales |
| U-Shaped | ✅ | ⚠️ | ✅ | Multi-step sales |
| W-Shaped | ✅ | ✅ | ✅ | Long B2B journeys |
🛠️ Visualizing with Python (Optional Bonus)
import matplotlib.pyplot as plt
labels = ['First', 'Middle', 'Last']
linear = [33, 33, 33]
u_shaped = [40, 20, 40]
w_shaped = [30, 30, 30]
plt.bar(labels, linear, label='Linear')
plt.bar(labels, u_shaped, bottom=linear, label='U-Shaped')
plt.bar(labels, w_shaped, bottom=[sum(x) for x in zip(linear, u_shaped)], label='W-Shaped')
plt.legend()
plt.title("Attribution Credit Comparison")
plt.show()
⚠️ Limitations of Rules-Based Models
| Issue | Description |
|---|---|
| No context-awareness | Doesn’t learn patterns from actual conversion behavior |
| Oversimplified | Real journeys are complex with device-switching, long gaps |
| Ignores interaction types | Clicking an ad ≠ opening an email ≠ organic search |
| Static | Same weights regardless of customer, channel, or campaign |
✅ Practice Task
-
Take a sample user journey with 4 steps (e.g., Meta → Search → Email → Direct)
-
Assign attribution using:
-
First-Touch
-
Last-Touch
-
Linear
-
U-Shaped
-
-
Compare outcomes and see how credit distribution changes
📘 Module 7.3: Introduction to Multi-Touch Attribution (MTA)
🧠 What is Multi-Touch Attribution (MTA)?
Multi-Touch Attribution (MTA) is a data-driven approach that assigns fractional credit to each touchpoint in a user’s journey based on its actual contribution to the final conversion.
Unlike rules-based models, MTA uses user-level data and algorithms/statistics to learn patterns and infer attribution.
🚀 Why MTA Matters
-
Customers interact with multiple channels before converting
-
Rules-based models are static and arbitrary
-
MTA provides granular, personalized attribution for each user journey
-
Helps optimize digital marketing spend in real time
📦 MTA vs Rules-Based Attribution
| Feature | Rules-Based | MTA |
|---|---|---|
| Credit Assignment | Fixed logic (e.g. last-touch) | Learned from data |
| Data Level | Journey-level | User-level, timestamped |
| Personalization | ❌ Same for all | ✅ Journey-specific |
| Adaptability | ❌ | ✅ Learns over time |
| Accuracy | Medium | High (with good data) |
| Tech Requirements | Low | High (tracking, modeling, engineering) |
🔎 MTA Workflow: Step-by-Step
1️⃣ Data Collection
-
Clickstream data (web/app events)
-
UTM parameters, campaign IDs, timestamps
-
Conversion events (purchase, signup)
2️⃣ Path Construction
-
Map each user journey: all touchpoints leading to conversion (or not)
User A: Meta Ad → Google → Email → Purchase
User B: YouTube → Direct → No Purchase
3️⃣ Feature Engineering
-
Encode touches, durations, recency, frequency
-
Mark converting vs non-converting journeys (binary target)
4️⃣ Modeling
-
Use ML or statistical techniques to assign weights:
-
Logistic Regression
-
Markov Chains
-
Shapley Value
-
Tree-based Models (XGBoost, Random Forest)
-
5️⃣ Attribution Output
-
Compute marginal contribution of each channel or touchpoint
-
Aggregate results by channel/platform/device
📘 Example: Logistic Regression for MTA
Each journey is a row; features are binary (1 if user saw/touched that channel)
| Meta | Search | Display | Conversion | |
|---|---|---|---|---|
| 1 | 1 | 1 | 0 | ✅ |
| 0 | 1 | 0 | 1 | ❌ |
| 1 | 0 | 1 | 1 | ✅ |
-
Run logistic regression:
Coefficients → how much each channel contributes to the likelihood of conversion
🧠 Advanced Techniques in MTA
| Method | Description |
|---|---|
| Markov Chain Models | Calculates removal effect of each touchpoint |
| Shapley Values | Game-theory-based fair credit distribution |
| Uplift Modeling | Measures causal lift of touchpoints (vs control) |
| Path Modeling (LSTM) | Sequence-aware deep learning models |
| Bayesian MTA | Models uncertainty & probabilistic contributions |
📌 Challenges with MTA
| Challenge | Description |
|---|---|
| Tracking limitations | Cookie loss, iOS privacy, device fragmentation |
| Attribution bias | Over/underestimation due to untracked channels (TV, offline) |
| Walled gardens | Data silos between platforms (Meta, Google, etc.) |
| Causal inference | Correlation ≠ causation; hard to detect true lift |
| Data volume & quality | Requires high-quality, large-scale, timestamped data |
✅ Best Use Cases for MTA
-
Optimizing performance marketing (Google Ads, Meta, Programmatic)
-
Testing channel mix on the fly
-
Informing bid strategies and creative performance
-
Feeding real-time dashboards for campaign managers
✅ Practice Task
-
Sketch a 3-user journey table with 3 channels (e.g., Meta, Search, Email)
-
Assign conversion flag (1 or 0)
-
Try to estimate weights manually based on frequency of occurrence
-
Think: Which channel appears most in converting journeys?
📘 Module 7.4: MTA vs MMM – Key Differences and Use Cases
🧠 Why This Matters
Both MMM (Marketing Mix Modeling) and MTA (Multi-Touch Attribution) help measure marketing effectiveness — but they’re fundamentally different in:
-
Granularity
-
Data requirements
-
Use cases
-
Modeling techniques
Understanding both helps marketers build a hybrid, full-funnel measurement strategy.
🔍 Side-by-Side Comparison: MMM vs MTA
| Feature | Marketing Mix Modeling (MMM) | Multi-Touch Attribution (MTA) |
|---|---|---|
| Data Granularity | Aggregate (weekly/monthly) | User-level (event/clickstream) |
| Data Type | Sales, spend, macro variables | User journeys, campaign touchpoints |
| Channels Covered | Online + Offline (TV, radio, print, etc.) | Mostly digital (online-only) |
| Privacy Compliance | ✅ High (no user tracking) | ⚠️ Low (relies on user IDs, cookies) |
| Modeling Type | Econometrics (regression) | Statistical or machine learning |
| Lag/Decay Modeling | ✅ Adstock, saturation curves | ⚠️ Harder to model memory |
| Use Case | Budgeting, forecasting, strategic planning | Campaign-level optimization |
| Output | ROI by channel over time | Contribution by touchpoint or platform |
| Data Volume Needed | Medium (months/years) | High (millions of rows) |
| Real-Time? | ❌ No | ✅ Yes (if infrastructure exists) |
| Offline Data | ✅ Fully supported | ❌ Difficult to integrate |
| Time Horizon | Long-term | Short-term, near real-time |
| Examples | TV vs Digital ROI, Brand lift | Google vs Meta vs Email contribution |
🧠 When to Use MMM
Use MMM when:
✅ You want channel ROI and budget optimization
✅ You have offline media (TV, print, in-store promotions)
✅ Privacy limitations block tracking
✅ You care about long-term effects, seasonality, trends
✅ You want to simulate different spend scenarios
💡 Ideal for: CPG, Retail, Pharma, BFSI, E-comm at scale
🧠 When to Use MTA
Use MTA when:
✅ You run digital campaigns with detailed clickstream data
✅ You want to optimize in real time
✅ You need to evaluate specific platforms, creatives, or audience segments
✅ You want to understand the micro journey of users
💡 Ideal for: D2C brands, SaaS, digital-first businesses, app marketers
💡 Hybrid Strategy = MMM + MTA
| Combined Use | Description |
|---|---|
| MMM for strategy | Budget split across TV, Meta, Search, Print |
| MTA for tactics | Optimize within channels (e.g., Meta carousel vs video) |
| MMM explains offline | Handles non-trackable touchpoints |
| MTA explains behavior | Captures detailed journey steps |
| MMM calibrates MTA | Corrects MTA bias from missing data |
| Together | Full-funnel visibility: Awareness to Conversion |
📊 Visualization: Funnel Focus
Awareness → Consideration → Conversion
[MMM Ideal Zone] [Both] [MTA Ideal Zone]
✅ Quick Recap
| Question | MMM | MTA |
|---|---|---|
| Can it model TV ads? | ✅ | ❌ |
| Can it optimize Google vs Meta? | ⚠️ Limited | ✅ |
| Is it privacy-compliant? | ✅ | ⚠️ Not always |
| Does it show journey paths? | ❌ | ✅ |
| Is it strategic or tactical? | Strategic | Tactical |
✅ Practice Task
-
List 3 marketing problems you face (or imagine)
-
For each, decide whether MMM, MTA, or both would be most suitable
-
Justify your answer based on data, goal, and time horizon
📘 Module 8.1: Adstock Transformation Theory
🧠 What Is Adstock?
Adstock is a mathematical technique used in Marketing Mix Modeling (MMM) to capture the lagged (carryover) effect of advertising over time.
📢 Just because you spend on ads this week doesn’t mean all the impact shows up this week. Some of it spills into next week, and the next...
Adstock helps model this delayed and decaying effect of media.
💡 Real-Life Analogy
Think of advertising like perfume:
-
🧴 You spray it once (media spend)
-
👃 The smell lingers for some time (carryover effect)
-
⏱️ Over time, the effect fades away (decay)
🔁 Adstock Formula
There are two popular forms: Geometric (most common) and Weibull (advanced)
1️⃣ Geometric (Recursive) Adstock
Where:
-
is the decay rate
-
is the media spend at time t
-
is the transformed variable with memory
📘 Key Parameter: Decay Rate (λ)
| λ Value | Interpretation |
|---|---|
| 0.0 | No memory (effect only this week) |
| 0.5 | Half of last week’s effect carries over |
| 0.9 | Strong memory, long carryover |
🔁 Example Calculation
Assume tv_spend = [100, 0, 0, 0] and decay λ = 0.5
| Week | Spend | Adstock |
|---|---|---|
| 1 | 100 | 100 |
| 2 | 0 | 0 + 0.5 × 100 = 50 |
| 3 | 0 | 0 + 0.5 × 50 = 25 |
| 4 | 0 | 0 + 0.5 × 25 = 12.5 |
Total effect of a single ₹100 spend lasts multiple weeks
🧰 Why Use Adstock in MMM?
| Purpose | Explanation |
|---|---|
| 📈 Lag effect | Models delayed impact of media on sales |
| 🔁 Memory | Reflects how long ads stay in customers’ minds |
| 📉 Diminishing influence | Each week’s effect fades over time |
| ✅ Realistic | Aligns with how consumers respond to media in practice |
🧪 Python Code: Adstock Function
def adstock(series, decay):
result = [series.iloc[0]]
for i in range(1, len(series)):
result.append(series.iloc[i] + decay * result[i - 1])
return result
Usage:
df['tv_adstock'] = adstock(df['tv_spend'], decay=0.6)
✅ Try different values of decay to find the best fit in your model.
🔬 Choosing Decay Rate (λ)
| Method | Description |
|---|---|
| Trial & Error | Try multiple λ values (0.1 to 0.9) and compare model R² |
| Grid Search | Automate tuning using metrics like RMSE or AIC |
| Bayesian Optimization | Used in advanced tools like Facebook Robyn |
| Media Knowledge | Use domain-informed estimates (TV = 0.7–0.9, Digital = 0.3–0.6) |
🆚 Adstock vs Lag Features
| Technique | Use Case |
|---|---|
| Adstock | Long-term, decaying memory |
| Lag Variables | Discrete delays (e.g., 1-week lag, 2-week lag) |
| ✅ Combine Both | Adstock captures carryover, lag captures delay |
✅ Summary
-
Adstock models how media effects persist over time
-
Controlled by decay rate λ
-
Helps build realistic MMMs with time-aware media impact
-
Choose λ using data or domain knowledge
✅ Practice Task
-
Create a weekly spend vector:
[100, 0, 0, 0, 0] -
Apply adstock with λ = 0.3, 0.6, and 0.9
-
Plot each to see how decay rate changes memory effect
📘 Module 8.2: Saturation / Diminishing Returns Using the Hill Function
🧠 Why This Matters
In real-world marketing:
Spending more money on ads doesn’t always mean proportionally more sales.
After a point, the effect plateaus — this is known as diminishing returns or saturation.
The Hill Function is a powerful mathematical tool used to model this non-linear relationship in MMM.
📉 Diminishing Returns: Concept
Let’s say you spend on digital ads:
-
₹10K → 100 conversions
-
₹20K → 170 conversions
-
₹30K → 210 conversions
The first ₹10K gave +100, but the last ₹10K only gave +40. That’s diminishing return.
📐 Saturation Curve Visualized
Sales ↑
|
1| ------------
| /
| /
| /
|_______/__________________ Spend →
-
Initial spends give strong returns
-
After a point → plateaus
-
The Hill function fits this curve
⚙️ Hill Function Formula
Where:
-
: media spend (after adstock)
-
: curve shape / steepness
-
: inflection point (50% saturation spend)
🔍 Intuition
| Parameter | Effect |
|---|---|
| α (alpha) | Steepness — higher → sharper drop-off |
| θ (theta) | Spend level at which half-max effect is achieved |
🧪 Python Implementation
def hill_function(x, alpha=1.0, theta=1.0):
return (x**alpha) / (x**alpha + theta**alpha)
📊 Example Plot
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 100, 200)
for alpha, theta in [(1, 20), (2, 50), (3, 80)]:
y = hill_function(x, alpha=alpha, theta=theta)
plt.plot(x, y, label=f"α={alpha}, θ={theta}")
plt.title("Hill Function - Saturation Curves")
plt.xlabel("Media Spend")
plt.ylabel("Effect")
plt.legend()
plt.grid()
plt.show()
📊 Why Use Hill Function in MMM?
| Benefit | Explanation |
|---|---|
| ✅ Models real-world diminishing return | Captures "plateau" of spend effectiveness |
| ✅ More flexible than log | Adjustable curve shape |
| ✅ Non-linear fit improves ROI estimation | Reflects reality better |
| ✅ Helps simulate budget optimizations | Find most efficient spend range |
💡 Combine with Adstock
In MMM, you often apply:
Spend → Adstock → Hill Function → Regress on Sales
Why?
-
Adstock = carryover effect
-
Hill = diminishing return
✅ Together: memory + saturation
📐 Hill vs Log Transformation
| Aspect | Hill Function | Log Transformation |
|---|---|---|
| Shape | S-curve | Concave curve |
| Customization | ✅ (via α, θ) | ❌ (fixed) |
| Accuracy | High | Medium |
| Simplicity | Complex | Simple |
| Common Use | Advanced MMM | Quick baselines |
✅ Practice Task
-
Take a numpy array of spend values from 0 to 100
-
Apply
hill_function(x, alpha=2, theta=50) -
Plot the result
-
Try changing α and θ values to see how the curve changes
🧠 Summary
-
Hill function captures saturation effects in media
-
Helps ensure MMM doesn’t overestimate high spend channels
-
Should be used after Adstock for realism
-
Parameters α and θ control curve behavior
📘 Module 8.3: Lag Effects in Marketing
🧠 Why Lag Effects Matter
In marketing, the impact of a campaign doesn't always show up immediately:
A user might see an ad today… but convert next week or next month.
These time delays between exposure and conversion are called lag effects — and properly accounting for them can dramatically improve your MMM or attribution model.
🔁 What Are Lag Effects?
Lag is the delay between the input (media spend or campaign) and its measurable impact (e.g., sales, leads, traffic).
| Input Week | Media Spend | Sales Spike |
|---|---|---|
| Week 1 | ₹50,000 (TV) | - |
| Week 2 | ₹50,000 | ↑ |
| Week 3 | ₹50,000 | ↑↑ |
✅ Some channels like TV, radio, and influencer campaigns often have longer lag than digital ads.
🎯 Why Use Lag in MMM?
-
Capture delayed conversions
-
Account for campaign awareness build-up
-
Avoid misattribution to wrong time periods
-
Improve model accuracy and interpretability
📦 Types of Lag Modeling Techniques
| Technique | Description | Use Case |
|---|---|---|
| Lag Variables | Manually shift features back by N weeks | Basic modeling |
| Adstock Transformation | Built-in memory decay (cumulative lag effect) | Smooth long tail |
| Cross-Correlation | Detect most effective lag via stats | Find best lags |
| Distributed Lag Models | Model impact over multiple lags | Econometrics-heavy |
| Impulse Response Function | Estimate how impact unfolds over time | For dynamic regressions |
🛠 Creating Lag Features in Python
df['tv_lag1'] = df['tv_spend'].shift(1)
df['tv_lag2'] = df['tv_spend'].shift(2)
df['search_lag1'] = df['search_spend'].shift(1)
✅ Use .shift(n) to create N-week lag features
⚠️ Be sure to drop or impute missing rows after lagging.
📊 Visualization: Lagged Correlation
import pandas as pd
import matplotlib.pyplot as plt
for lag in range(1, 6):
df[f'tv_lag{lag}'] = df['tv_spend'].shift(lag)
corr = df['sales'].corr(df[f'tv_lag{lag}'])
print(f'Lag {lag} correlation with sales: {corr:.2f}')
Choose the lag with highest correlation for modeling.
📌 Lag vs Adstock
| Feature | Lag | Adstock |
|---|---|---|
| Type | Discrete | Continuous |
| Memory | No | Yes (decay-based) |
| Use Case | Capture delay | Capture carryover |
| Format | Manual .shift() |
Recursive function |
| Combine? | ✅ Often used together |
🎯 When to Use Lag Features
| Scenario | Use Lags? |
|---|---|
| TV or OOH with delayed response | ✅ Yes |
| Email click → instant visit | ❌ No |
| Brand campaign (awareness building) | ✅ Yes |
| Performance marketing | Maybe (depends on data) |
✅ Practice Task
-
Take a weekly TV spend and sales dataset
-
Create lag features:
tv_lag1,tv_lag2,tv_lag3 -
Calculate correlation between each lag and sales
-
Use the highest-correlated lag in your regression model
🧠 Summary
-
Lag = delay between marketing effort and its impact
-
Modeled via
.shift(), adstock, or statistical methods -
Helps align cause (media) and effect (sales)
-
Improves MMM timing accuracy
📘 Module 8.4: Channel Interactions in Marketing Mix Modeling
🧠 Why This Matters
In the real world, marketing channels don’t operate in silos.
A TV ad might boost search activity.
Email campaigns might increase direct traffic.
Social ads might drive brand awareness, which affects organic traffic.
These cross-channel synergies are called channel interactions.
If ignored, your model might:
-
Underestimate combined impact
-
Double-count or misattribute influence
-
Miss strategic media effects
🔗 What Are Channel Interactions?
Channel interaction refers to when the impact of one channel is influenced or amplified by the presence of another.
🔄 Example:
| Channel A | Channel B | Conversion Impact |
|---|---|---|
| High | Low | Moderate |
| Low | High | Moderate |
| High | High | 🚀 Strong (synergy!) |
The combined effect is greater than the sum of parts → this is a positive interaction.
📘 Types of Interactions
| Interaction Type | Description | Example |
|---|---|---|
| Complementary | Channel A boosts Channel B | TV → Google search lift |
| Competitive | Channels cannibalize each other | Search ads vs. organic |
| Sequential | One channel primes, the other converts | Video view → Email signup |
🔬 How to Model Interactions in MMM
1️⃣ Interaction Terms in Regression
Just like in standard regression, you can multiply variables to represent their interaction:
🛠 Python Example
df['tv_search_interaction'] = df['tv_adstock'] * df['search_adstock']
Include this in your regression model:
X = df[['tv_adstock', 'search_adstock', 'tv_search_interaction']]
y = df['sales']
2️⃣ Interaction with Hill Transformation
Apply Hill functions before creating interaction terms to capture saturation:
df['tv_saturated'] = hill_function(df['tv_adstock'], alpha=2, theta=50)
df['search_saturated'] = hill_function(df['search_adstock'], alpha=2, theta=30)
df['tv_search_interaction'] = df['tv_saturated'] * df['search_saturated']
✅ Helps prevent overfitting from large outliers
📈 Interpreting Interaction Terms
| Coefficient | Interpretation |
|---|---|
| Positive β | Channels amplify each other |
| Negative β | Channels cannibalize each other |
| Near zero | No interaction |
💡 Interactions make your model non-linear, even if regression is linear!
⚠️ Caution: Don’t Overdo It
| Tip | Reason |
|---|---|
| Start small | Too many interaction terms → overfitting |
| Use domain knowledge | Only combine relevant channels (e.g., TV × Search, not Email × Print) |
| Watch VIF | High collinearity due to interactions |
✅ Practice Task
-
Choose two related channels: e.g.,
tv_adstockandsearch_adstock -
Create an interaction variable
-
Fit regression model with and without interaction
-
Compare R² and interpret the interaction coefficient
🧠 Summary
-
Channel interactions reflect real-world synergy (or competition)
-
Modeled via product of channel variables in regression
-
Can reveal hidden boosts or cannibalization
-
Should be used judiciously, guided by data + domain intuition
📘 Module 8.5: Model Regularization in MMM – Ridge & Lasso Regression
🧠 Why Regularization Matters in MMM
In Marketing Mix Modeling, we often deal with:
-
Many input variables (media, lags, interactions, transformations)
-
Correlated features (e.g., TV and Digital might move together)
-
Noisy or sparse data
Without regularization, your model may overfit the training data and fail to generalize to unseen periods.
✅ Regularization adds penalty terms to prevent the model from relying too heavily on any single variable.
🧮 Ridge vs Lasso: The Basics
| Regularization | Description | Penalty | Best For |
|---|---|---|---|
| Ridge (L2) | Shrinks coefficients | Sum of squares: | Handling multicollinearity |
| Lasso (L1) | Shrinks and selects features | Sum of absolutes: ( \lambda \sum | \beta |
| ElasticNet | Combo of both | L1 + L2 | Balanced shrinkage + selection |
📘 Regression Formulas
➤ Ridge Regression
➤ Lasso Regression
-
λ (lambda) is the regularization strength
-
Higher λ → more penalty → smaller coefficients
🛠️ When to Use Each in MMM
| Situation | Use |
|---|---|
| Media channels are correlated (e.g., TV & Radio) | Ridge |
| You want to remove low-impact variables | Lasso |
| You want both shrinkage + feature selection | ElasticNet |
| You're building a robust, generalizable MMM | Always use one of them! ✅ |
🧪 Python Implementation
from sklearn.linear_model import Ridge, Lasso
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
# Assume X = feature matrix, y = sales
ridge = make_pipeline(StandardScaler(), Ridge(alpha=10))
lasso = make_pipeline(StandardScaler(), Lasso(alpha=0.5))
ridge_score = cross_val_score(ridge, X, y, cv=5, scoring='r2').mean()
lasso_score = cross_val_score(lasso, X, y, cv=5, scoring='r2').mean()
print(f"Ridge R²: {ridge_score:.3f}")
print(f"Lasso R²: {lasso_score:.3f}")
📊 Visualizing Regularization Effect (Bonus)
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import Lasso
alphas = np.linspace(0.01, 10, 100)
coefs = []
for a in alphas:
lasso = Lasso(alpha=a)
lasso.fit(X, y)
coefs.append(lasso.coef_)
plt.plot(alphas, coefs)
plt.title("Lasso Coefficients Shrinkage")
plt.xlabel("Lambda (alpha)")
plt.ylabel("Coefficient Values")
plt.grid()
plt.show()
✅ This shows how increasing lambda shrinks features to zero — powerful for variable selection!
🔁 Regularization + MMM: Full Picture
In a real MMM pipeline, you usually:
1. Transform: Adstock + Hill + Lag + Interactions
2. Regularize: Ridge or Lasso to reduce overfitting
3. Evaluate: R², MAPE, AIC/BIC
4. Interpret: Media contribution, ROI, budget optimization
✅ Practice Task
-
Build a Ridge and Lasso regression on your MMM dataset
-
Compare which channels get shrunk or zeroed out
-
Try tuning
alphafrom 0.1 to 100 and observe performance (cross-validated R²)
🧠 Summary
-
Regularization is essential in real-world MMM
-
Ridge is great for multicollinearity; Lasso for feature reduction
-
Helps avoid overfitting and improve model generalization
-
Tune λ (alpha) to control penalty strength
📘 Module 8.6: Bayesian MMM with PyMC3 / RStan
🧠 Why Use Bayesian Methods in MMM?
Traditional MMM (OLS, Ridge, Lasso) gives point estimates for each coefficient (e.g., TV = 0.25 ROI).
But Bayesian MMM gives a full distribution — so you know how uncertain your ROI really is.
🎯 Instead of “TV ROI is 1.2”, you get “TV ROI is 1.2 ± 0.3 (95% confidence)”
⚖️ Benefits of Bayesian MMM
| Benefit | Description |
|---|---|
| ✅ Uncertainty Quantification | Shows confidence intervals for each channel |
| ✅ Prior Knowledge Inclusion | Use expert beliefs or historical data as priors |
| ✅ Posterior Distribution | Helps simulate future performance scenarios |
| ✅ Regularization built-in | Shrinkage happens naturally via priors |
| ✅ Robust to outliers | Priors act as guardrails |
🧮 Bayesian Regression Basics
Bayesian linear regression expresses uncertainty as probability distributions:
But instead of fixed β values, we assume:
Where:
-
: prior mean (belief)
-
: prior variance (uncertainty)
You update beliefs using data → posterior distribution
🛠️ PyMC3: Minimal Bayesian MMM (Python)
▶️ Step-by-Step:
import pymc3 as pm
import numpy as np
# Example: X = adstocked spends, y = sales
with pm.Model() as model:
# Priors
intercept = pm.Normal('intercept', mu=0, sigma=1)
beta_tv = pm.Normal('beta_tv', mu=0, sigma=1)
beta_search = pm.Normal('beta_search', mu=0, sigma=1)
sigma = pm.HalfNormal('sigma', sigma=1)
# Linear model
mu = intercept + beta_tv * X['tv'] + beta_search * X['search']
# Likelihood
y_obs = pm.Normal('y_obs', mu=mu, sigma=sigma, observed=y)
# Posterior sampling
trace = pm.sample(2000, tune=1000, target_accept=0.9)
✅ Use pm.plot_trace(trace) to see distributions of ROI for each channel
✅ Use pm.summary(trace) for mean, std dev, HPD intervals (Bayesian CI)
📊 Interpretation of Posterior Distributions
| Term | Interpretation |
|---|---|
| Mean of β | Expected ROI/contribution |
| Std. Dev. | Variability across samples |
| HPD (95%) | Most credible range (Bayesian CI) |
| Trace Plot | Shows convergence (Markov Chain samples) |
📦 What About RStan?
If you're in R:
library(rstan)
model_code <- "
data {
int<lower=0> N;
vector[N] tv;
vector[N] search;
vector[N] y;
}
parameters {
real alpha;
real beta_tv;
real beta_search;
real<lower=0> sigma;
}
model {
y ~ normal(alpha + beta_tv * tv + beta_search * search, sigma);
}
"
Compile + fit:
fit <- stan(model_code = model_code, data = list(N=n, tv=tv, search=search, y=y), iter=2000, chains=4)
print(fit)
🧠 Bayesian Priors in MMM
| Channel | Prior Mean | Std Dev | Reason |
|---|---|---|---|
| TV | 0.1 | 0.05 | TV typically has long-term ROI |
| Search | 0.3 | 0.1 | High-converting channel |
| Display | 0.05 | 0.03 | Low-impact historically |
✅ Priors encode historical expectations
✅ You can use uninformative priors if you're unsure
🔁 Common Extensions
| Feature | How it's done |
|---|---|
| Adstock | Precompute or model recursively in PyMC3 |
| Hill/Saturation | Apply transformation before modeling |
| Interactions | Include multiplicative terms in formula |
| Hierarchical MMM | Use random effects across geographies or brands |
| Seasonality | Add Fourier terms or dummy variables |
✅ Practice Task
-
Pick 2–3 adstocked + saturated media variables
-
Build a PyMC3 model using Normal priors
-
Run sampling and plot ROI posteriors
-
Report mean, std, and 95% interval for each media channel
🧠 Summary
-
Bayesian MMM models ROI with uncertainty, not just point estimates
-
PyMC3 and RStan are powerful for this, especially with MCMC sampling
-
You get credible intervals, not just coefficients
-
Ideal for strategic MMM in uncertain, sparse, or volatile environments
-
Requires a bit more compute + setup but gives rich insight
📘 Module 9.1: Data Preparation for MMM
🧠 Why Data Preparation is Critical
Marketing Mix Modeling is only as good as the quality and structure of your input data.
📉 Garbage in = Garbage out
You need to aggregate, clean, transform, align, and enrich your dataset to make it MMM-ready.
🧾 Required Data for MMM
🔹 1. Dependent Variable (Target)
The metric you want to explain or predict (e.g., sales, conversions, revenue)
| Date | Revenue |
|---|---|
| 2024-01-01 | ₹120,000 |
| 2024-01-08 | ₹135,000 |
🔹 2. Independent Variables (Media Inputs)
Weekly media spends by channel:
| Date | TV | Radio | ||
|---|---|---|---|---|
| 2024-01-01 | 50,000 | 10,000 | 12,000 | 5,000 |
🔹 3. Control Variables (Non-Media)
| Feature Type | Examples |
|---|---|
| Seasonality | Week number, holiday dummies |
| Macro Trends | Inflation, weather, GDP |
| Promotions | Discount flag, coupons |
| Competitor Activity | Share of voice, media pressure |
📦 Key Data Requirements
| Requirement | Detail |
|---|---|
| Frequency | Weekly (preferred), or monthly |
| Time Period | At least 1.5 – 2 years (for seasonality) |
| Granularity | Aggregate (per region if using hierarchy) |
| Consistency | No missing weeks, nulls, or duplicates |
🧰 Data Cleaning Checklist
| Task | Purpose |
|---|---|
| 🧹 Fill missing values | Use interpolation or 0s for media |
| 📆 Ensure time alignment | Align all features on the same date index |
| 🧪 Normalize or scale features | Optional for OLS, required for Ridge/Lasso |
| ❌ Remove outliers | Use IQR or z-score, especially for sales spikes |
| 📊 Aggregate to weekly level | Sum (media spend), Average (CPC, CTR), Last (discount) |
🛠️ Python Example: Weekly Aggregation
df['date'] = pd.to_datetime(df['date'])
df.set_index('date', inplace=True)
weekly_df = df.resample('W').agg({
'revenue': 'sum',
'tv_spend': 'sum',
'google_spend': 'sum',
'discount_flag': 'last'
})
🧠 Feature Engineering Tips
| Technique | Why Use |
|---|---|
| Lag Features | Model delayed effects |
| Adstock Transform | Memory effect of media |
| Saturation Curve (Hill) | Diminishing returns |
| Interaction Terms | Cross-channel influence |
| Holiday Dummies | Account for spikes |
| Trend Variable | Capture long-term drift |
🔁 Example: Add Week Number & Holiday Flag
df['week_num'] = df.index.isocalendar().week
df['is_holiday'] = df['date'].isin(holiday_list).astype(int)
📈 Final Feature Table: MMM-Ready Format
| Date | Revenue | TV | Promo | Holiday | Trend | ... | |
|---|---|---|---|---|---|---|---|
| 2024-01-01 | ₹120,000 | 50K | 10K | 0 | 1 | 1 | ... |
| 2024-01-08 | ₹135,000 | 60K | 12K | 1 | 0 | 2 | ... |
✅ Practice Task
-
Take raw daily sales + media spend data
-
Aggregate to weekly level
-
Add features: week number, holidays, lags, adstocked media
-
Check for nulls, missing weeks, or duplicates
-
Export clean dataset for modeling
🧠 Summary
-
Clean, complete, and time-aligned data is essential
-
Prepare target + media + control variables
-
Use weekly frequency and include at least 1.5 years
-
Engineer features for lags, seasonality, and interactions
📘 Module 9.2: Model Calibration & Validation in MMM
🧠 Why Calibration & Validation Matter
It’s not enough to build a model that fits the past — it should also generalize to future decisions.
In MMM, you want to:
-
Calibrate your model to historical data
-
Validate its predictions hold up on unseen weeks
-
Trust the ROI and contribution estimates for planning
🧮 Model Calibration
Calibration = fitting your model to historical data so it reflects reality.
Inputs: Media + control variables
Output: Predicted sales or revenue
🛠 Steps for Model Calibration
-
Prepare clean, engineered data (from 9.1)
-
Apply transformations:
-
✅ Adstock
-
✅ Hill/Saturation
-
✅ Lag features
-
-
Split data into:
-
Train set (e.g., 70–80%)
-
Test set (e.g., last 20–30% of time)
-
🧪 Model Fit Metrics
| Metric | Meaning | Good Value |
|---|---|---|
| R² (Coefficient of Determination) | % of variance explained | > 0.7 |
| MAPE (Mean Absolute % Error) | % prediction error | < 15% |
| RMSE | Average magnitude of error | Lower = better |
| AIC/BIC | Model selection criteria | Lower = better |
📊 Python Example: Model Evaluation
from sklearn.metrics import r2_score, mean_absolute_percentage_error
y_train_pred = model.predict(X_train)
y_test_pred = model.predict(X_test)
print("Train R²:", r2_score(y_train, y_train_pred))
print("Test R²:", r2_score(y_test, y_test_pred))
print("Test MAPE:", mean_absolute_percentage_error(y_test, y_test_pred) * 100)
🔍 Visual Validation
📈 1. Predicted vs Actual Sales (Time Series Plot)
import matplotlib.pyplot as plt
plt.plot(df.index, df['sales'], label='Actual')
plt.plot(df.index, model.predict(X), label='Predicted')
plt.title("Actual vs Predicted Sales")
plt.legend()
plt.show()
📉 2. Residual Plot
residuals = y - model.predict(X)
plt.scatter(y, residuals)
plt.axhline(0, color='red')
plt.title("Residual Plot")
plt.show()
✅ No patterns = good model
❌ Systematic errors = missing variable or poor spec
📦 Cross-Validation for MMM
MMM is time-dependent, so use Time Series Cross-Validation instead of random splits.
from sklearn.model_selection import TimeSeriesSplit
tscv = TimeSeriesSplit(n_splits=5)
for train_idx, test_idx in tscv.split(X):
model.fit(X[train_idx], y[train_idx])
preds = model.predict(X[test_idx])
print("Fold MAPE:", mean_absolute_percentage_error(y[test_idx], preds))
🧠 Calibration Best Practices
| Tip | Why |
|---|---|
| Use at least 1.5 years of data | Capture seasonality |
| Add holiday, promo flags | Explain spikes |
| Check for overfitting (high train, low test R²) | Prevent false confidence |
| Use domain sense checks | e.g., TV ROI ~ 1.2–1.5, Display ROI ~ 0.2–0.5 |
| Avoid using future data in lagged features | Maintain causality |
📈 Model Validation Summary Table
| Metric | Train | Test |
|---|---|---|
| R² | 0.86 | 0.78 |
| MAPE | 8.2% | 11.3% |
| RMSE | 12,000 | 14,500 |
✅ Model is well-calibrated and generalizes well
✅ Practice Task
-
Fit a Ridge or Bayesian MMM model on your dataset
-
Split into train/test based on time
-
Evaluate R², MAPE, and plot residuals
-
Try adjusting adstock decay or Hill parameters to improve test performance
🧠 Summary
-
Calibration = fitting model to past data
-
Validation = ensuring it works on unseen time periods
-
Use R², MAPE, RMSE and residual plots for evaluation
-
Prefer time-based cross-validation
-
Always validate interpretability + performance
📘 Module 9.3: Forecasting & Budget Allocation using MMM
🧠 Why This Matters
Once your Marketing Mix Model is trained and validated, the next big questions are:
-
🤔 "What will happen if I increase spend on a channel?"
-
💰 "How should I allocate my next quarter's budget to maximize ROI?"
This module covers how to use MMM for forward-looking strategy:
✅ Forecasting sales
✅ Simulating media spend scenarios
✅ Optimizing future budget allocation
📈 1. Forecasting Sales using the Model
Assuming your MMM is built as:
Where = Adstock + Hill transformation
▶️ Step-by-Step
-
Prepare future media spend plan
-
Apply same adstock + saturation transformations
-
Feed into model to predict sales
🛠 Python Forecasting Example
# Assume future_df has 'tv', 'search', 'facebook' spends
future_df['tv_adstock'] = apply_adstock(future_df['tv'], decay=0.5)
future_df['tv_saturated'] = hill_function(future_df['tv_adstock'], alpha=2, theta=100)
# Predict using model
future_sales = model.predict(future_df[model_features])
✅ Use for scenario simulation:
-
What if we increase TV spend by 10%?
-
What if we shift budget from Facebook to Search?
📊 2. Media ROI & Contribution
Once you have fitted model coefficients and predicted sales:
➤ ROI Formula
➤ Contribution Formula
Helps understand which channel drives most value
📘 Example Output Table
| Channel | Spend | ROI | Contribution (%) |
|---|---|---|---|
| TV | ₹50L | 1.3 | 32% |
| Search | ₹30L | 2.0 | 28% |
| ₹20L | 0.7 | 12% |
✅ Use these insights to optimize future allocation
🧮 3. Budget Optimization (Media Mix Optimization)
Given a fixed budget, how should we distribute it to maximize predicted sales?
This is a constrained optimization problem.
📦 Objective Function
Maximize:
Subject to:
And:
Where = Adstock + Hill transformation
🛠 Budget Optimization in Python (Scipy)
from scipy.optimize import minimize
def objective(x):
tv, search, fb = x
tv_eff = hill_function(apply_adstock(tv), alpha=2, theta=100)
search_eff = hill_function(apply_adstock(search), alpha=2, theta=50)
fb_eff = hill_function(apply_adstock(fb), alpha=2, theta=70)
return -(beta_tv * tv_eff + beta_search * search_eff + beta_fb * fb_eff)
# Constraint: Total budget = ₹1 Cr
constraints = [{'type': 'eq', 'fun': lambda x: sum(x) - 100}]
# Bounds per channel
bounds = [(10, 60), (10, 50), (10, 40)]
# Initial guess
x0 = [33.3, 33.3, 33.3]
result = minimize(objective, x0, bounds=bounds, constraints=constraints)
print("Optimized Spend:", result.x)
✅ This gives optimal spend allocation across channels
📉 Advanced: Probabilistic Budget Planning (Bayesian MMM)
If using Bayesian MMM:
-
Simulate ROI from posterior distributions
-
Run thousands of spend scenarios
-
Get distribution of outcomes (e.g., 80% chance of hitting ₹10Cr sales)
Use Monte Carlo Simulations for this.
✅ Practice Task
-
Prepare 3 future spend plans (baseline, aggressive, cutback)
-
Predict future sales using MMM for each
-
Calculate ROI and contribution for each channel
-
Run optimization to reallocate next quarter’s ₹X budget
🧠 Summary
-
Use MMM to forecast future sales under different spend plans
-
Use model coefficients to calculate ROI and contribution
-
Solve constrained optimization to maximize impact of budget
-
Forecasting + Optimization = Data-driven media planning
📘 Module 9.4: MMM with Facebook Robyn (Open Source)
🧠 What is Facebook Robyn?
Robyn is an open-source automated, end-to-end MMM framework developed by Meta’s marketing science team.
It’s designed to:
-
Automate media modeling
-
Handle non-linearity (saturation, adstock)
-
Apply Bayesian ridge regression
-
Perform hyperparameter tuning
-
Enable multi-objective optimization
✅ Used by companies worldwide to run industrial-scale MMM pipelines.
🚀 Key Features of Robyn
| Feature | Description |
|---|---|
| 📦 Bayesian Ridge Regression | Regularized modeling with uncertainty |
| 📉 Adstock & Saturation | Automatically modeled (geometric, Weibull) |
| 🧪 Hyperparameter Tuning | Uses Nevergrad (Meta’s optimization library) |
| 📊 Multi-objective Optimization | Optimizes for R², MAPE, Decomp R² |
| 📈 Budget Simulation | Forecasting & allocation built-in |
| 🖥️ Dashboard-ready Output | JSON & plots for reporting |
⚙️ Robyn Requirements
| Setup | Details |
|---|---|
| Language | R (Robyn is R-based) |
| Interface | Command line or RStudio |
| Backend | R packages + Nevergrad (Python) |
| Input | Media + non-media variables, weekly data (min ~2 years) |
✅ Works best with R 4.1+
✅ You can use Python alongside for preprocessing
📂 Step-by-Step Workflow
1️⃣ Install Robyn
# In R
install.packages("remotes")
remotes::install_github("facebookexperimental/Robyn/R")
# Python backend setup (Only once)
# pip install nevergrad
2️⃣ Prepare Input Data
Columns needed:
| Variable | Format | Example |
|---|---|---|
| date | YYYY-MM-DD | 2022-01-01 |
| dependent_var | Numeric | sales, revenue |
| media variables | Numeric | tv, facebook, search, etc. |
| context variables | Holidays, CPI, etc. | dummy or numeric |
Minimum: 2+ years of weekly data
3️⃣ Define Model Parameters
library(Robyn)
robyn_object <- robyn_init(
dt_input = input_data,
dt_holidays = holidays_data,
adstock = "geometric", # or "weibull"
saturation = TRUE,
cores = 4
)
4️⃣ Run Hyperparameter Optimization
robyn_outputs <- robyn_run(
robyn_object = robyn_object,
trials = 1000, # higher = better tuning
iterations = 200
)
⏳ Robyn automatically tunes:
-
Adstock decay
-
Saturation curve (Hill function)
-
Regularization strength
-
Model performance (MAPE, R², Decomp R²)
5️⃣ Review & Select Best Model
robyn_outputs$exported_models # View top-performing runs
robyn_best_model <- robyn_outputs$exported_models[[1]]
📊 Robyn provides:
-
Model summary
-
Decomposition (media contribution)
-
ROI estimates
-
Plots (response curves, model fit, etc.)
6️⃣ Simulate & Allocate Budget
robyn_response <- robyn_response(
robyn_object = robyn_object,
scenario = "max_response",
total_budget = 1000000,
channel_constr_low = c(tv=0.1, fb=0.1, search=0.1),
channel_constr_up = c(tv=0.5, fb=0.5, search=0.5)
)
✅ Robyn outputs optimal spend distribution across channels
📊 Robyn Output Samples
| Channel | ROI | Contribution (%) |
|---|---|---|
| TV | 1.5 | 35% |
| Search | 2.1 | 29% |
| 0.9 | 15% |
📈 Plus plots for:
-
Response curves (saturation)
-
Adstock decay patterns
-
Weekly predicted vs actual sales
-
Budget optimization heatmaps
🧠 Robyn’s Best Practices
| Tip | Note |
|---|---|
| Minimum 100 weeks data | For stability |
| Remove zeros in dependent variable | Robyn needs continuity |
| Preprocess outliers & holidays | Or it may skew contributions |
| Include seasonality variables | Week of year, month, etc. |
Use "dryrun = TRUE" first |
To validate structure before full run |
✅ Practice Task
-
Collect ~2 years of weekly sales + media data
-
Prepare dataset with
date,dependent_var, and media spends -
Run
robyn_init()androbyn_run() -
Review top model and export ROI, contributions
-
Simulate future spend plan using
robyn_response()
🧠 Summary
-
Robyn is a powerful, production-grade MMM engine
-
Handles automated transformations, Bayesian regularization, and optimization
-
Requires clean, aligned weekly data
-
Provides full reporting + forecasting pipeline
-
Can save weeks of manual modeling time
📘 Module 9.5: MMM Reporting Dashboards
🧠 Why Dashboards Matter
MMM results are often technical and complex — but decision-makers want clarity, actionable insights, and visual summaries.
A good MMM dashboard helps:
-
Visualize ROI, contribution, and response curves
-
Compare media performance over time
-
Simulate budget scenarios
-
Support marketing, finance, and CXO-level decisions
📊 Dashboards make your MMM work visible, credible, and actionable.
🎯 Key Metrics to Visualize
| Metric | Description |
|---|---|
| 📈 Predicted vs Actual Sales | Model fit over time |
| 🧮 Media Contribution | % of sales driven by each channel |
| 💰 ROI by Channel | Return on investment per ₹1 spent |
| 🌀 Saturation Curves | Response curves for each media |
| 🧪 Budget Scenarios | Future spend → predicted sales |
| 📅 Time-Series Trends | Spend vs. sales by channel |
🛠️ Dashboard Tools You Can Use
| Tool | Use Case | Pros |
|---|---|---|
| Power BI | Enterprise-level MMM dashboards | Easy integration, slicers, custom visuals |
| Tableau | Interactive, visual-first MMM reports | Drag-and-drop, polished UI |
| Streamlit (Python) | Python-based MMM apps | Highly customizable, open source |
| Shiny (R) | For Robyn-based dashboards | Native R integration |
| Looker Studio | Lightweight dashboards | Easy sharing, Google-friendly |
💡 Example: Power BI MMM Dashboard Layout
📊 Page 1: Executive Summary
-
Total media spend
-
Total revenue explained
-
Channel-wise ROI & contribution bar chart
-
Pie chart of sales attribution
📈 Page 2: Time Series
-
Line chart: Actual vs Predicted Sales (weekly)
-
Media spend overlay on sales
💹 Page 3: ROI & Response Curves
-
ROI by channel
-
Saturation (Hill) curve visual per channel
-
Adstock decay visualization
🧪 Page 4: Budget Planner
-
User inputs total budget
-
Visualized optimized channel-wise budget
-
Expected revenue uplift
📦 Python/Streamlit: Quick MMM Dashboard Sample
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
st.title("MMM Dashboard")
# Load model outputs
df = pd.read_csv("model_results.csv")
st.subheader("Media ROI")
st.bar_chart(df.set_index("channel")["roi"])
st.subheader("Actual vs Predicted Sales")
plt.plot(df['date'], df['actual_sales'], label='Actual')
plt.plot(df['date'], df['predicted_sales'], label='Predicted')
plt.legend()
st.pyplot(plt)
st.subheader("Media Contribution (%)")
st.dataframe(df[['channel', 'contribution_pct']])
✅ Use inputs and sliders for interactive budget planning
🧠 Tips for Effective MMM Dashboards
| Tip | Why It Matters |
|---|---|
| Keep it visual | Execs won’t read raw tables |
| Add filters (regions, channels) | Enables slice & dice |
| Include benchmarks (e.g., ROI > 1) | Shows what’s “good” |
| Use tooltips and footnotes | Explain complex metrics like adstock or elasticity |
| Automate monthly refresh | Keep it alive and useful |
📘 Module 10.1: Logistic Regression for Conversion Prediction
🧠 Why Logistic Regression?
In marketing, many outcomes are binary:
-
Did the user convert? (Yes/No)
-
Did they click the ad?
-
Did a lead turn into a customer?
Logistic Regression is a classification algorithm that models the probability of such outcomes.
🔍 Use Case: Predicting Conversions from Campaign Data
Goal: Predict whether a user will convert based on campaign features.
📦 Sample Dataset Columns:
| Feature | Description |
|---|---|
age |
Age of the user |
gender |
Male/Female |
campaign_source |
Email, Facebook, Google, etc. |
pages_viewed |
Number of pages visited |
time_spent |
Time spent on site (in mins) |
converted |
1 = Yes, 0 = No |
🧠 Logistic Regression Basics
-
Outputs probabilities
-
Can apply threshold (e.g. 0.5) to classify as 0 or 1
🛠 Step-by-Step in Python (Scikit-learn)
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
# Load data
df = pd.read_csv("campaign_data.csv")
# Preprocess
df = pd.get_dummies(df, drop_first=True) # One-hot encode categorical vars
# Split features/target
X = df.drop("converted", axis=1)
y = df["converted"]
# Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
# Fit model
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
# Predict
y_pred = model.predict(X_test)
# Evaluate
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))
📈 Key Evaluation Metrics
| Metric | Meaning |
|---|---|
| Accuracy | % of total correct predictions |
| Precision | % of predicted positives that were correct |
| Recall (Sensitivity) | % of actual positives correctly predicted |
| F1 Score | Balance of Precision & Recall |
📊 Interpreting Coefficients
coeff_df = pd.DataFrame({
'Feature': X.columns,
'Coefficient': model.coef_[0]
})
print(coeff_df.sort_values(by="Coefficient", ascending=False))
| Feature | Coefficient | Interpretation |
|---|---|---|
pages_viewed |
+0.67 | Higher pages viewed ↑ chance of conversion |
gender_Male |
-0.34 | Males less likely to convert |
campaign_source_Google |
+0.21 | Google campaign users more likely to convert |
✅ Positive = more likely to convert
❌ Negative = less likely
🧪 Optional: Predict Probabilities
y_proba = model.predict_proba(X_test)[:, 1]
df_results = pd.DataFrame({"actual": y_test, "predicted_proba": y_proba})
Can use ROC curve, AUC for model performance (advanced)
📘 Module 10.2: Markov Chains for Attribution Modeling
🧠 Why Markov Chains?
Traditional rule-based attribution models (like First-Touch or Last-Touch) are too simplistic and don't account for multiple touchpoints or channel drop-offs.
✅ Markov Chains use transition probabilities to model how users move through channels before converting.
It helps you answer:
-
Which channels are most influential in the conversion path?
-
What happens to conversions if we remove a channel?
-
What’s the removal effect (credit) for each channel?
🔗 Core Idea of Markov Chains in Attribution
Markov Chains model the user journey as a chain of states:
Start → Facebook → Email → Direct → Conversion
Each channel is a state, and movement from one channel to another is a transition.
⚙️ Key Components
| Component | Description |
|---|---|
| States | Marketing touchpoints (e.g., Facebook, Email, Paid Search) |
| Transitions | Movement from one touchpoint to the next |
| Conversion | Final state that ends the path |
| Null (Drop-off) | Exit without conversion |
🧮 Example Transitions
| From → To | Count |
|---|---|
| Start → Facebook | 100 |
| Facebook → Email | 70 |
| Email → Conversion | 60 |
| Facebook → Drop-off | 30 |
📊 Step-by-Step Workflow
1️⃣ Prepare the Path Data
Each row is a complete user path ending in either conversion or null.
| User | Path | Conversion |
|---|---|---|
| 001 | Facebook > Email > Direct | 1 |
| 002 | Search > Facebook | 0 |
| 003 | Email > Direct | 1 |
2️⃣ Build Transition Matrix
Calculate probability of moving from one channel to another.
from collections import defaultdict
# Simple illustration (you can use libraries like `markov-model-attribution`)
transition_counts = defaultdict(int)
paths = [
["start", "Facebook", "Email", "Direct", "conversion"],
["start", "Search", "Facebook", "dropoff"],
]
# Count transitions
for path in paths:
for i in range(len(path) - 1):
transition_counts[(path[i], path[i + 1])] += 1
# Compute transition probabilities
transition_matrix = defaultdict(dict)
for (src, dst), count in transition_counts.items():
total = sum(c for (s, _), c in transition_counts.items() if s == src)
transition_matrix[src][dst] = count / total
3️⃣ Simulate Conversion Removal Effect
For each channel:
-
Remove it from all paths
-
Recalculate how many conversions are lost
-
That difference = channel’s contribution
✅ This is called the removal effect attribution model.
📦 Libraries You Can Use
Python:
-
markov-model-attribution(by Parul Pandey)
R:
-
ChannelAttributionpackage
# R Example
library(ChannelAttribution)
result <- markov_model(
Data = my_data,
var_path = "path",
var_conv = "converted",
out_more = TRUE
)
head(result$result)
📈 Output Example
| Channel | Removal Effect (Conversions Lost) | Attribution (%) |
|---|---|---|
| 450 | 30% | |
| 300 | 20% | |
| Direct | 250 | 16.7% |
| Search | 200 | 13.3% |
✅ Channels that break the conversion chain most often have higher attribution.
📊 Visualizing Attribution
Use Sankey diagrams or bar plots to visualize flow and credit:
-
Transition flows between channels
-
Attribution scores for each channel
You can use:
-
Plotly, Matplotlib, or Power BI/Tableau
-
SankeyMATIC for quick Sankey diagrams
📘 Module 10.3: Shapley Value Attribution
🧠 Why Shapley Value?
Shapley values come from cooperative game theory and provide a fair way to allocate credit based on each player's contribution to the outcome.
In marketing, players = channels
Outcome = conversion
🔍 It fairly distributes credit to each touchpoint by considering all possible combinations of channels.
📊 Traditional Models vs Shapley Attribution
| Model | Credit Logic |
|---|---|
| First-Touch | 100% to first channel |
| Last-Touch | 100% to last channel |
| Linear | Equal credit to all channels |
| Shapley ✅ | Average marginal contribution of each channel across all paths |
🎮 Game Theory Analogy
Imagine 3 players (channels): A, B, C
Let’s say:
-
A alone → 0 conversions
-
A+B → 3 conversions
-
A+B+C → 5 conversions
Shapley Value considers all permutations (ABC, BAC, CBA...) and calculates the marginal contribution of each channel to each possible subset.
🧮 Formula (Simplified)
For a channel :
Where:
-
: subset of players without channel
-
: conversions achieved by subset
-
: total number of channels
📦 Implementation: Python
📁 Sample Data: Paths and Conversion
paths = [
(['Facebook', 'Email'], 1),
(['Facebook', 'Email', 'Search'], 1),
(['Email', 'Direct'], 0),
(['Search'], 1),
]
🛠 Using shapley or channel-attribution Python Package
from channel_attribution import shapley
df = pd.DataFrame({
'path': ['Facebook > Email', 'Facebook > Email > Search', 'Email > Direct', 'Search'],
'conv': [1, 1, 0, 1]
})
result = shapley(df, var_path='path', var_conv='conv')
print(result)
📘 Sample Output:
| Channel | Shapley Value | Attribution (%) |
|---|---|---|
| 0.85 | 28% | |
| 1.15 | 38% | |
| Search | 1.00 | 33% |
✅ Values are additive, fair, and reflect true marginal impact
❌ But can be computationally expensive (2ⁿ complexity)
🔢 Benefits of Shapley Attribution
| Advantage | Description |
|---|---|
| ✅ Fairness | Based on contribution across all permutations |
| ✅ Handles multichannel journeys | Captures synergy effects |
| ✅ Grounded in theory | From Nobel-winning game theory |
| ❌ Slow for many channels | Needs approximations or sampling for 10+ channels |
📊 Visualizing Shapley Attribution
Use:
-
Bar charts for credit distribution
-
Stacked contributions over time
-
Waterfall charts for marginal lift
📘 Module 10.4: Gradient Boosting Trees (XGBoost) for Multi-Touch Attribution
🧠 Why Use XGBoost for Attribution?
Traditional attribution (rules or Shapley) assumes we know the outcome and credit distribution logic.
But in many cases:
✅ We want a predictive model to learn which combinations of touchpoints cause conversion.
Gradient Boosting Trees, especially XGBoost, are ideal because:
-
Capture nonlinear relationships
-
Handle interaction effects between channels
-
Give feature importance (which channel drives conversion)
-
Are robust to missing values and categorical variables
🔍 Use Case: Predicting Conversion from Marketing Touchpoints
Goal: Use past user journeys to train a model that predicts whether a user will convert.
📦 Example Data Format
| user_id | search | direct | days_since_first_click | converted | ||
|---|---|---|---|---|---|---|
| U001 | 1 | 0 | 1 | 1 | 2 | 1 |
| U002 | 0 | 1 | 1 | 0 | 1 | 0 |
| U003 | 1 | 1 | 0 | 1 | 4 | 1 |
-
Touchpoints encoded as binary indicators (or counts)
-
Other engineered features: time lags, frequency, order
-
Target:
converted(0 or 1)
🔢 Why XGBoost?
| Feature | Benefit |
|---|---|
| Ensemble learning | Combines weak learners for strong predictions |
| Handles nonlinearity | Captures diminishing returns, synergy |
| Built-in regularization | Avoids overfitting |
| Scalable | Handles large attribution datasets |
| Feature importance | Helps interpret which channels matter most |
🛠 Python Code: XGBoost for MTA
import pandas as pd
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, roc_auc_score
# Load and preprocess data
df = pd.read_csv("mta_data.csv")
X = df.drop(columns=["user_id", "converted"])
y = df["converted"]
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, test_size=0.2, random_state=42)
# Train model
model = xgb.XGBClassifier(
n_estimators=100,
learning_rate=0.1,
max_depth=5,
use_label_encoder=False,
eval_metric='logloss'
)
model.fit(X_train, y_train)
# Predict
y_pred = model.predict(X_test)
y_proba = model.predict_proba(X_test)[:, 1]
print(classification_report(y_test, y_pred))
print("ROC AUC:", roc_auc_score(y_test, y_proba))
📈 Feature Importance: Interpreting Attribution
import matplotlib.pyplot as plt
xgb.plot_importance(model, importance_type='gain', height=0.6)
plt.title("Channel Attribution (Feature Importance by Gain)")
plt.show()
| Channel | Importance Score | Interpretation |
|---|---|---|
search |
0.40 | Most impactful |
facebook |
0.25 | Next important |
email |
0.18 | Moderate impact |
direct |
0.10 | Lower role |
✅ These scores represent how much each feature contributed to reducing error, not direct credit %
🔁 Optional: SHAP for Deeper Attribution
Use SHAP values to understand individual-level impact:
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)
✅ SHAP offers local + global attribution for each user and each feature
🧠 Best Practices for XGBoost in MTA
| Tip | Why |
|---|---|
| One-hot encode categorical features | Trees need them to split on |
| Normalize/standardize numeric features | Improves convergence |
| Engineer meaningful features | E.g., sequence order, recency, counts |
| Avoid data leakage | No post-conversion info in predictors |
| Use AUC, Precision-Recall | Better than just accuracy for imbalanced data |
📘 Module 10.5: Deep Learning-Based MTA Models
🧠 Why Deep Learning for Attribution?
Deep Learning models (like RNNs, CNNs, Transformers) are powerful for MTA because they can:
-
Capture complex nonlinear interactions
-
Learn temporal sequences in customer journeys
-
Handle variable-length sequences
-
Provide personalized, probabilistic attributions
✅ Especially useful when touchpoints are sequential (e.g., Email → Facebook → Search → Conversion)
🔍 Real-World Use Case
Predict conversion likelihood and attribute importance to touchpoints in order-sensitive journeys.
🛠 Common Deep Learning Architectures Used
| Model | Purpose | Notes |
|---|---|---|
| RNN / LSTM / GRU | Model sequences of touchpoints | Handles time-series well |
| CNN | Capture local patterns | Use on encoded sequences |
| Attention / Transformer | Learn long-term dependencies | State-of-the-art for MTA |
| DeepSets | Order-invariant MTA | Good when sequence order doesn’t matter |
| Deep Attribution Models (e.g. DNAMTA) | End-to-end learning of touchpoint importance | Uses embeddings + attention |
🧱 Sample Model Pipeline
Step-by-Step:
-
Input: Sequences of touchpoints per user
-
Embed channels (e.g., Facebook = [0.1, 0.4, ...])
-
Process through LSTM or Transformer
-
Output:
-
Conversion probability
-
Touchpoint attribution scores (via attention/gradients)
-
📦 Example Data Format
| user_id | journey | converted |
|---|---|---|
| U001 | ["facebook", "email", "direct"] | 1 |
| U002 | ["search", "facebook"] | 0 |
| U003 | ["email", "facebook", "search"] | 1 |
🛠 Code: Sequence-Based LSTM MTA in Keras
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Embedding, LSTM, Dense, GlobalAveragePooling1D
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Sample journeys
journeys = [["facebook", "email", "direct"], ["search", "facebook"], ["email", "search", "facebook"]]
converted = [1, 0, 1]
# Tokenize
tokenizer = Tokenizer()
tokenizer.fit_on_texts(journeys)
X = tokenizer.texts_to_sequences(journeys)
X = pad_sequences(X, maxlen=5, padding='post') # max sequence length
y = tf.convert_to_tensor(converted)
# Model
inp = Input(shape=(5,))
x = Embedding(input_dim=len(tokenizer.word_index)+1, output_dim=8)(inp)
x = LSTM(16, return_sequences=False)(x)
out = Dense(1, activation='sigmoid')(x)
model = Model(inputs=inp, outputs=out)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(X, y, epochs=10)
🧠 Attribution via Attention Layer (Advanced)
Add an Attention layer after LSTM to get weights for each step → interpret which touchpoints mattered most in a given sequence.
# Custom Attention Layer (simplified)
attention = tf.keras.layers.Attention()([x, x])
Or use Grad-CAM, Integrated Gradients, or SHAP on the trained model to interpret attribution.
📊 Output
| User | Conversion Prob | Top Contributing Touchpoint |
|---|---|---|
| U001 | 0.84 | |
| U002 | 0.25 | Search |
| U003 | 0.91 |
✅ Gives probabilistic and contextual attribution
✅ Personalized per user, per journey
📦 Libraries & Tools
-
Keras / TensorFlow / PyTorch – model building
-
Captum (PyTorch) – model interpretation
-
SHAP / Integrated Gradients – feature importance
-
DNAMTA – Deep Neural Net MTA model with embeddings and attention
-
Transformers (HuggingFace) – for sequence-aware modeling (e.g., BERT for logs)
🧠 Best Practices
| Tip | Why |
|---|---|
| Encode touchpoints as embeddings | Captures semantic similarity |
| Use LSTM/GRU for time-sensitive paths | Preserves order |
| Apply dropout, batch norm | Regularization for better generalization |
| Visualize attention weights | Helps build trust in attribution |
| Use large datasets | Deep learning needs scale |
📘 Module 11.1: Probabilistic vs Deterministic Matching
🧠 Why Identity Matching Matters in Marketing Analytics?
Before you can analyze user behavior, you need to link disparate data points to the same individual or household across channels, devices, or sessions.
This is called Identity Resolution — and it’s the backbone of reliable attribution, personalization, and targeting.
🧩 Two Main Approaches
| Type | Description | Example |
|---|---|---|
| ✅ Deterministic Matching | Linking based on exact, known identifiers | Email ID, login, customer ID |
| 🤖 Probabilistic Matching | Linking based on similarity, patterns, or behavior | Device fingerprint, IP, time, browser |
📘 1. Deterministic Matching
🔐 Definition:
Matching based on known, exact identifiers that are unique and persistent.
✅ Pros:
-
High accuracy
-
Transparent (easy to audit)
-
Great for logged-in users or CRM systems
❌ Cons:
-
Limited reach (only for known users)
-
Can’t match cross-device unless user is logged in
🧾 Examples:
-
Email → CRM
-
Login ID → Purchase history
-
Loyalty card → Store purchases
🤖 2. Probabilistic Matching
🧠 Definition:
Uses machine learning or statistical models to infer identity by matching patterns across sessions/devices.
How it works:
It calculates a probability score that two or more profiles belong to the same user based on:
-
IP address
-
Device type
-
Geolocation
-
Time of activity
-
Behavior patterns (pages viewed, click patterns)
✅ Pros:
-
Wider reach (includes anonymous users)
-
Enables cross-device matching (even if user is not logged in)
❌ Cons:
-
Not 100% accurate (requires confidence threshold)
-
Hard to audit/explain
-
May be blocked by privacy regulations (e.g. GDPR)
⚖️ Comparison Table
| Aspect | Deterministic | Probabilistic |
|---|---|---|
| Accuracy | ✅ Very High | Moderate (70–90%) |
| Scale | Limited | ✅ Large-scale |
| Use Case | CRM campaigns | Cross-device attribution |
| Auditability | High | Low |
| Data Needed | Login, email, phone | IP, behavior, device |
| Privacy Risk | Low | High (needs consent or anonymization) |
🧪 Hybrid Matching
Many enterprise systems now use hybrid approaches:
Use deterministic where possible, fall back to probabilistic when no exact ID is found.
Example:
-
Match user with email → deterministic
-
If email missing, check IP + behavior pattern → probabilistic
💼 Real-World Applications
| Use Case | Matching Approach |
|---|---|
| Email campaign retargeting | Deterministic |
| Cross-device ad measurement | Probabilistic |
| Attribution modeling (MTA) | Both |
| Identity graph construction | Hybrid |
| Customer 360 platforms | Probabilistic + deterministic |
📘 Module 11.2: Cookie & Pixel Tracking
🧠 Why It Matters
Cookies and tracking pixels are foundational to digital marketing analytics — they enable:
-
Tracking user behavior across sessions
-
Attributing conversions to campaigns
-
Retargeting users with ads
-
Building user profiles and journey paths
Without them, multi-touch attribution (MTA), retargeting, and personalization wouldn’t exist.
🍪 What is a Cookie?
A cookie is a small piece of data stored by the browser on the user’s device.
📦 Types of Cookies:
| Type | Purpose | Example |
|---|---|---|
| 1st-party cookie | Set by the website the user is visiting | example.com sets a login token |
| 3rd-party cookie | Set by a domain other than the visited site | Ad networks like doubleclick.net track users |
| Session cookie | Temporary, deleted after session | Tracks login during one visit |
| Persistent cookie | Stored long-term | Tracks user preferences or IDs for months |
✅ Cookie Use Cases in Marketing
-
Identify repeat users
-
Track conversion journeys
-
Store UTM/source tags
-
Frequency capping on ads
-
A/B testing users over time
-
Retargeting audiences
📷 What is a Tracking Pixel?
A pixel is a 1×1 transparent image embedded in a webpage or email that fires when loaded, sending info to a server.
It's a signal that user viewed a page or email.
💡 Common Names:
-
Pixel tag
-
Web beacon
-
Image tag
-
Conversion tag
🧱 How It Works:
<img src="https://tracker.example.com/pixel.gif?user_id=123&event=visit" width="1" height="1" />
When the page loads:
-
Pixel is requested
-
Server logs the request (who, what, when)
-
Optional: response sets a cookie on the browser
🔗 Combining Cookies & Pixels
Pixels + cookies = full event tracking:
| Component | Role |
|---|---|
| Pixel | Fires event and sends metadata |
| Cookie | Stores user/session ID for tracking continuity |
✅ Together, they link multiple visits or actions to the same user
✅ Used in tools like Google Analytics, Facebook Pixel, LinkedIn Insight Tag, Hotjar
🔒 Privacy & Limitations
| Challenge | Impact |
|---|---|
| Ad blockers | Block pixel requests or cookie drops |
| Incognito mode | Deletes cookies after session |
| iOS Safari ITP / Firefox ETP | Blocks 3rd-party cookies |
| GDPR/CCPA compliance | Requires user opt-in, cookie banners |
| Chrome phasing out 3rd-party cookies | Will break cross-site tracking (by ~2025) |
🔄 Alternatives to Cookies/Pixels
| Option | Description |
|---|---|
| First-party data | CRM logins, email, consented tracking |
| Server-side tracking | Events sent directly from server (not browser) |
| Device fingerprinting | Uses browser/device metadata to infer user ID (increasingly restricted) |
| Google’s Privacy Sandbox (Topics API) | Interest-based targeting without cookies |
| Facebook Conversion API (CAPI) | Server-to-server event tracking with fallback to pixels |
🛠 Common Tracking Platforms
| Platform | Tech Used |
|---|---|
| Google Ads / GA4 | gtag.js, cookies, pixels |
| Facebook Ads | Pixel + Conversion API |
| LinkedIn Insight Tag | JS + pixel |
| Hotjar / Mixpanel | JS, cookies |
| RudderStack / Segment | Unified event tracking via cookies & server-side routes |
📘 Module 11.3: Customer Data Platforms (CDPs)
🧠 What is a CDP?
A Customer Data Platform (CDP) is a software system that:
✅ Collects, unifies, and activates customer data from multiple sources into a single customer view (SCV).
It provides real-time segmentation, identity resolution, and audience activation for marketing, analytics, and personalization.
🧱 CDP Architecture Overview
+------------------+
| Website/App |
| CRM System |
| POS Data |
| Social Media |
+--------+---------+
|
[Data Ingestion Layer]
↓
+-----------------------------+
| Identity Resolution Engine |
| Profile Unification |
+-----------------------------+
↓
+---------------------+
| Customer 360 Profile|
+---------------------+
↓
[Audience Segmentation]
↓
+------------------------------+
| Activation (Ads, Email, SMS) |
+------------------------------+
🧩 Key Components of a CDP
| Layer | Function |
|---|---|
| Data Ingestion | Collects structured and unstructured data (web, CRM, mobile, etc.) |
| Identity Resolution | Matches and unifies data to individual users (via deterministic & probabilistic matching) |
| Profile Management | Builds a persistent customer profile with behavioral, demographic, and transactional data |
| Audience Segmentation | Real-time rule-based or predictive segmentation |
| Activation | Sends audiences to external tools (Facebook, Google, email platforms) |
| Analytics & Reporting | Built-in dashboards or integrations for marketing analytics tools |
🔌 Data Sources a CDP Connects
| Source | Examples |
|---|---|
| Website/App | Browsing behavior, clicks, events |
| CRM | Leads, contacts, sales data |
| Email/Push | Open, click, unsubscribe data |
| Ads | Google, Meta, LinkedIn impressions and spend |
| Offline | POS transactions, call center data |
| 3rd-party | DMP, loyalty data, enrichment APIs |
🔄 CDP vs DMP vs CRM vs Data Warehouse
| Feature | CDP | DMP | CRM | Data Warehouse |
|---|---|---|---|---|
| Focus | Individual customer profiles | Anonymous audiences | Sales & service | Raw data storage |
| Data type | PII, behavioral, transactional | Cookies, IDs | Lead/contact data | All |
| Real-time | ✅ Yes | ❌ No | ❌ Often no | ❌ No |
| Use for Activation | ✅ Yes | ✅ Yes | ❌ No | ❌ No |
| Retention | Long-term | Short-term | Medium | Long-term |
| Who uses | Marketers, analysts | Advertisers | Sales, CX | Engineers, analysts |
💼 CDP Use Cases in Marketing Analytics
| Use Case | Description |
|---|---|
| Unified Customer View | Combine email + site + CRM data into one profile |
| Segmentation & Personalization | Real-time dynamic user segments for targeted campaigns |
| Lookalike Modeling | Build seed audiences and push to Facebook/Google Ads |
| Attribution | Track cross-channel journeys for MTA |
| MMM Enrichment | CDPs provide clean spend, conversion, and user behavior data |
| Suppression Lists | Exclude converted users from future ad campaigns |
🌐 Popular CDPs
| CDP Platform | Notes |
|---|---|
| Segment (Twilio) | Developer-friendly, rich integrations |
| Tealium | Enterprise-grade, strong on privacy |
| Salesforce CDP (Marketing Cloud) | Tightly integrated with Salesforce CRM |
| mParticle | Mobile-first, great for app data |
| Adobe Real-Time CDP | Best-in-class identity graphs |
| RudderStack (Open Source) | Lightweight alternative to Segment |
📊 CDP in Marketing Analytics Stack
[Raw Data Sources]
↓
[CDP: Segment / Tealium / Adobe]
↓
[Data Warehouse or ML Pipeline]
↓
[Attribution Models / MMM / Personalization Engines]
↓
[BI Dashboards, Activation Channels]
📘 Module 11.4: Cross-Device Attribution
🧠 Why Cross-Device Attribution Matters?
Today’s users switch between devices constantly:
-
Search on mobile
-
Research on tablet
-
Convert on desktop
❌ Traditional attribution sees these as 3 separate users
✅ Cross-device attribution connects them as one journey
🔎 What Is Cross-Device Attribution?
It’s the process of identifying the same user across multiple devices and attributing their conversion accurately.
Instead of:
Mobile → Tablet → Desktop → Conversion (counted as 3 users)
We model it as:
User X: Mobile → Tablet → Desktop → Conversion (1 user journey)
🧩 Key Use Cases
| Use Case | Description |
|---|---|
| Accurate conversion credit | Prevents overcounting/undercounting channels |
| Budget allocation | Understand which device initiates vs. converts |
| Personalization | Serve right message based on current device |
| Retargeting | Continue user journey across platforms |
📦 Cross-Device Identity Graphs
A device graph maps multiple devices to a single user ID.
| Device ID | Cookie | Login ID | Linked Profile | |
|---|---|---|---|---|
| A1B2C3 | ✅ | ✅ | ❌ | ❌ |
| X9Y8Z7 | ✅ | ✅ | ✅ | ✅ |
✅ Once matched, these devices are linked under one unified user profile
🛠 Matching Methods
| Approach | Description | Accuracy | Use Case |
|---|---|---|---|
| Deterministic | Login-based matching (email, user ID) | ✅ High | CRM systems, apps |
| Probabilistic | Match by IP, location, behavior | Medium | Ad networks, analytics |
| Hybrid | Combine both | ✅ Best of both | CDPs, major platforms |
🔒 Example (Deterministic):
User logs into:
📱 Mobile app → Email ID matched
💻 Website → Same email → match confirmed
✅ Exact match = high confidence
🤖 Example (Probabilistic):
Same IP + location + browser fingerprint + purchase pattern
→ 85% chance it's the same user
✅ Useful when no login is available
🧠 How Cross-Device Data Impacts Attribution Models
| Model | Impact |
|---|---|
| MMM | Improves accuracy of reach and response by channel |
| MTA | Ensures full user path is visible across platforms |
| Shapley / Markov | Better path representation → fairer credit |
| Uplift Modeling | Understand treatment/control effects across devices |
📊 Cross-Device Reporting Metrics
| Metric | Description |
|---|---|
| Device Paths | Sequence of devices used before conversion |
| Cross-Device Conversions | Conversions from multi-device journeys |
| Device Assist | Which device initiated journey vs. closed |
| Overlap Rate | % of users seen on more than 1 device |
| Device Attribution Share | Credit breakdown by device (mobile vs. desktop) |
🔧 Tools for Cross-Device Attribution
| Tool/Platform | Support |
|---|---|
| Google Ads & GA4 | Uses Google Sign-in for deterministic match |
| Meta (Facebook) | Cross-device pixel + login graph |
| CDPs (Segment, Adobe) | Identity resolution + device graphs |
| Ad Servers (DV360, Trade Desk) | Probabilistic device graphs |
| GA4 Explorations | Cross-platform path analysis |
🔒 Privacy & Compliance
Cross-device tracking must follow:
-
GDPR / CCPA / Apple ATT guidelines
-
Explicit consent for device linking
-
First-party login recommended
-
Transparency in how device data is used
Great! Now you're entering Module 12, where we focus on building the data backbone that powers all your marketing analytics: the ETL pipelines.
📘 Module 12.1: ETL Pipelines for Marketing Data
🧠 Why ETL Pipelines Matter in Marketing?
Marketing teams today work with scattered data sources:
-
Ad platforms (Meta, Google Ads, LinkedIn)
-
Web/app analytics (GA4, Mixpanel, Firebase)
-
CRM systems (Salesforce, HubSpot)
-
Email tools (Mailchimp, Klaviyo)
-
Offline data (POS, call center)
✅ An ETL (Extract, Transform, Load) pipeline brings all this data together for unified analysis and attribution.
⚙️ What is ETL?
| Step | Description |
|---|---|
| Extract | Pull data from source systems (APIs, databases, flat files) |
| Transform | Clean, format, enrich, join, and standardize |
| Load | Push into a destination like data warehouse, CDP, or BI tool |
🧱 ETL Pipeline Structure for Marketing Analytics
+--------------------+
| Ad Platforms | → Facebook, Google Ads, LinkedIn
+--------------------+
| Web Analytics | → GA4, Mixpanel, Firebase
+--------------------+
| CRM / Email / POS | → Salesforce, HubSpot, Klaviyo, Retail POS
+--------------------+
↓
[Extract Layer]
↓
[Transform Layer]
- Clean, map channels
- Parse UTM params
- Join across IDs
↓
[Load Layer]
→ Data Warehouse (BigQuery, Redshift, Snowflake)
→ Dashboard Tool (Tableau, Power BI, Looker)
📦 Common Marketing Data Sources & Formats
| Source | Data Type | Method | Format |
|---|---|---|---|
| Facebook Ads | Campaigns, spend, impressions | API | JSON |
| Google Analytics 4 | Events, users, sessions | GA4 API / BigQuery export | JSON/Parquet |
| CRM | Customer records, leads, deals | API / SQL / CSV | CSV/SQL |
| Email tools | Opens, clicks, unsubscribes | API | JSON |
| Offline | Store transactions, calls | CSV / Manual Upload | CSV |
🛠 Sample ETL Tools (No-Code to Pro-Code)
| Tool | Type | Notes |
|---|---|---|
| Fivetran / Stitch | No-code | Connect 100+ sources to BigQuery, Redshift |
| Airbyte (Open Source) | Hybrid | Modular, flexible |
| Google Cloud Composer | Code | Built on Apache Airflow |
| Apache NiFi / Airflow | Code-heavy | Enterprise data orchestration |
| RudderStack | Dev-friendly | Focus on marketing & analytics |
| dbt (Data Build Tool) | SQL-based | Popular for transformation layer |
🛠 Python-Based Mini ETL Example
Extract from Facebook Ads
import requests
url = 'https://graph.facebook.com/v16.0/act_123456/insights'
params = {
'access_token': 'your_token',
'fields': 'campaign_name,impressions,clicks,spend',
'level': 'campaign',
'time_range': {'since': '2024-07-01', 'until': '2024-07-07'}
}
response = requests.get(url, params=params)
data = response.json()['data']
Transform
import pandas as pd
df = pd.DataFrame(data)
df['spend'] = df['spend'].astype(float)
df['CTR'] = df['clicks'].astype(int) / df['impressions'].astype(int)
Load to BigQuery (example)
from google.cloud import bigquery
client = bigquery.Client()
client.load_table_from_dataframe(df, 'project.dataset.marketing_data').result()
🧩 Common Transformations in Marketing ETL
| Task | Example |
|---|---|
| Normalize campaign names | Facebook vs Google naming conventions |
| Map UTM parameters | UTM medium → channel grouping |
| De-duplicate events | GA4 or CRM duplicate records |
| Join with CRM IDs | Match Google Analytics user to CRM contact |
| Create derived metrics | CTR, ROAS, CPM, CAC |
| Time standardization | Convert to UTC / local time |
📊 Where to Load the Data?
| Destination | Use Case |
|---|---|
| Data warehouse (Snowflake, BigQuery) | Long-term storage, SQL-based analysis |
| Dashboard (Looker, Tableau, Power BI) | Visual reporting for stakeholders |
| ML platform (Vertex AI, SageMaker) | Model training |
| CDP (Segment, mParticle) | Audience segmentation & activation |
Perfect! Let’s now break down an important architectural concept in marketing analytics — the difference between Data Lakes and Data Warehouses, and when to use which.
📘 Module 12.2: Data Lakes vs Data Warehouses in Marketing
🧠 Why This Matters in Marketing Analytics
As a marketing analyst or data engineer, you’re handling massive volumes of data:
-
Structured (campaign reports, CRM tables)
-
Semi-structured (JSON from APIs)
-
Unstructured (emails, images, logs)
✅ Choosing between a Data Lake and a Data Warehouse depends on:
Data types
Processing needs
Analytics use cases
Cost and performance
🧱 What is a Data Lake?
A Data Lake is a large, centralized repository that stores raw, unstructured, semi-structured, or structured data at any scale.
| Feature | Description |
|---|---|
| ✅ Schema-on-read | Structure is applied after loading |
| ✅ Supports all data types | JSON, Parquet, CSV, media, logs |
| ✅ Low cost | Often stored in cloud object storage (e.g., Amazon S3, Azure Blob, GCS) |
| ❌ Slower query performance | Needs transformation before analysis |
🔧 Example Use Cases in Marketing:
-
Store all ad log files from DSPs
-
Retain raw clickstream data for reprocessing
-
Archive historical campaign data
-
Feed data science experiments or model training
🧱 What is a Data Warehouse?
A Data Warehouse is a high-performance system optimized for structured, analytical queries on curated data.
| Feature | Description |
|---|---|
| ✅ Schema-on-write | Data is cleaned and structured before storing |
| ✅ Fast SQL queries | Optimized for BI tools and dashboards |
| ✅ Supports integrations | Works with Tableau, Power BI, Looker |
| ❌ More expensive per GB | Higher compute/storage costs than lakes |
🔧 Example Use Cases in Marketing:
-
Create weekly ROAS dashboards
-
Segment users based on multi-channel behavior
-
Run attribution models
-
Feed MMM dashboards
⚖️ Data Lake vs Data Warehouse – Side-by-Side
| Feature | Data Lake | Data Warehouse |
|---|---|---|
| Data type | All types (raw) | Structured/tabular |
| Schema | On-read | On-write |
| Cost | ✅ Low | ❌ Higher |
| Query speed | Slower | ✅ Fast |
| Use case | Storage, ML, raw ingestion | BI, reporting, dashboards |
| Tools | AWS S3, GCP GCS, Azure Blob | BigQuery, Snowflake, Redshift |
| Flexibility | ✅ High | Medium |
| Governance | Needs more control | Built-in structure |
🔁 When to Use Each?
| Scenario | Recommended |
|---|---|
| Store raw JSON from Facebook API | Data Lake |
| Build Looker dashboard for weekly KPIs | Data Warehouse |
| Retain 3 years of raw campaign logs | Data Lake |
| Run MMM & attribution queries weekly | Data Warehouse |
| Feed ML models with historical browsing logs | Data Lake |
| Join clean CRM, spend, and conversion tables | Data Warehouse |
🧪 Hybrid: Lakehouse Architecture (Best of Both)
Many modern companies adopt a Lakehouse model:
✅ Store everything in a lake, but query like a warehouse
| Tech | Description |
|---|---|
| Delta Lake (Databricks) | Combines lake storage with ACID tables |
| Apache Iceberg | Table format for large-scale data lakes |
| Google BigLake | Unifies BigQuery + GCS |
| Snowflake on S3 | Snowflake queries data from your lake |
| Athena / Presto / Starburst | Query data lakes directly using SQL |
🧠 Summary
| Concept | Data Lake | Data Warehouse |
|---|---|---|
| Schema | On-read | On-write |
| Performance | Lower | High |
| Cost | ✅ Low | ❌ Higher |
| Usage | Store raw data | BI, analytics |
| Marketing Use | Raw logs, clickstream | Dashboards, MMM, MTA |
| Tools | S3, GCS, Azure Blob | BigQuery, Snowflake, Redshift |
Great! Let’s explore one of the most powerful tools for automating and orchestrating your marketing data pipelines: Apache Airflow.
📘 Module 12.3: Airflow for Scheduling Marketing Data Pipelines
🧠 Why Airflow?
Marketing analytics pipelines need to:
-
Fetch data daily from Facebook, Google Ads, GA4, etc.
-
Transform it (clean, normalize, enrich)
-
Load into data warehouse or dashboard tool
-
Run attribution models or MMM weekly
✅ Apache Airflow lets you schedule, monitor, and orchestrate all of these in a modular, fail-safe way.
⚙️ What is Apache Airflow?
Airflow is a workflow orchestration tool for programmatically authoring, scheduling, and monitoring data pipelines.
It uses DAGs (Directed Acyclic Graphs) to define workflows as a series of tasks with dependencies.
📐 DAG (Directed Acyclic Graph)
Think of a DAG as a flowchart of your data tasks.
Example: Marketing Spend ETL DAG
[Start]
|
[Extract from Facebook Ads API]
↓
[Transform & Clean Data]
↓
[Load to BigQuery]
↓
[Send Success Notification]
🔧 Key Concepts
| Term | Description |
|---|---|
| DAG | A pipeline; defined in Python |
| Task | One step (e.g., fetch Facebook data) |
| Operator | Prebuilt function (e.g., PythonOperator, BashOperator, HttpOperator) |
| Schedule Interval | When the DAG should run (e.g., daily at 9am) |
| Airflow Web UI | Monitor runs, failures, retries visually |
🛠 Sample Marketing DAG
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
def fetch_facebook_ads():
# Call Facebook Graph API and save data
pass
def transform_data():
# Clean/standardize campaign naming
pass
def load_to_bigquery():
# Upload to data warehouse
pass
with DAG('daily_facebook_etl',
schedule_interval='@daily',
start_date=datetime(2024, 1, 1),
catchup=False) as dag:
extract = PythonOperator(task_id='extract_fb_ads', python_callable=fetch_facebook_ads)
transform = PythonOperator(task_id='transform_data', python_callable=transform_data)
load = PythonOperator(task_id='load_bq', python_callable=load_to_bigquery)
extract >> transform >> load
✅ This DAG will run daily and perform end-to-end ETL.
💼 Marketing Use Cases with Airflow
| Use Case | Description |
|---|---|
| Automated Ad Reporting | Pull daily data from Meta, Google Ads |
| ETL for MMM/MTA Models | Schedule MMM pipeline every Monday |
| Attribution Model Retraining | Retrain & deploy every 2 weeks |
| Campaign Spend Monitoring | Alert if spend > budget |
| Email Performance Analysis | Pull open/click data from Klaviyo |
🧩 Common Operators
| Operator | Purpose |
|---|---|
| PythonOperator | Run any Python function |
| BashOperator | Run shell commands |
| HttpOperator | Call external APIs (e.g., ad platforms) |
| EmailOperator | Send alerts |
| BigQueryOperator | Run SQL on BigQuery |
| BranchPythonOperator | Logic-based task branching |
| DummyOperator | Placeholder for structuring DAG |
🧠 Benefits for Marketing Teams
| Benefit | Why it matters |
|---|---|
| ✅ Automation | No more manual campaign data pulls |
| ✅ Monitoring | Alerts if Facebook API fails |
| ✅ Scalability | Add multiple sources as DAGs grow |
| ✅ Modular | Reuse functions across brands or regions |
| ✅ Cost Efficiency | Time-based loads vs constant polling |
📊 Airflow Alternatives
| Tool | Notes |
|---|---|
| Prefect | Simpler, modern orchestration |
| Dagster | Data-aware pipelines |
| Google Cloud Composer | Managed Airflow on GCP |
| Astronomer | Cloud Airflow with dev tools |
| Luigi / Argo / Kubeflow | Other orchestration options (more dev-heavy) |
Awesome, Sanjay! Now let’s dive into Google BigQuery — a marketing analyst’s best friend when it comes to working with large datasets, fast queries, and flexible storage.
📘 Module 12.4: Google BigQuery for Marketing Teams
🧠 Why BigQuery for Marketing?
Marketing data is:
-
Huge (millions of rows from ad clicks, GA4 events)
-
Heterogeneous (from Facebook, Google Ads, CRM, etc.)
-
Time-based (daily, hourly, sessional)
✅ BigQuery handles all of this effortlessly, without infrastructure management.
🚀 What is BigQuery?
BigQuery is Google Cloud’s serverless, scalable data warehouse.
| Feature | Description |
|---|---|
| Serverless | No infrastructure to manage |
| SQL-based | Familiar interface for analysts |
| Highly scalable | Handles petabytes of data |
| Pay-per-query | Cost-efficient (pay only for data scanned) |
| Easy integrations | GA4, Google Ads, Sheets, Looker |
🧱 Common Marketing Data in BigQuery
| Source | Example Table | Schema |
|---|---|---|
| GA4 | ga4.events_* |
event_name, session_id, page_title, timestamp |
| Google Ads | google_ads.customer_performance |
campaign_id, impressions, clicks, spend |
| Facebook Ads | meta.ads_performance |
ad_id, reach, cpm, conversions |
| CRM | crm.contacts |
email, lead_source, score |
| Attribution | mta.paths |
user_id, touchpoints, conversion_date |
💻 How It Works: Querying GA4 Data in BigQuery
-- Count events by campaign
SELECT
traffic_source.name AS campaign,
COUNT(event_name) AS total_events
FROM
`project.dataset.ga4_events_*`
WHERE
event_name = 'purchase'
AND _TABLE_SUFFIX BETWEEN '20240701' AND '20240707'
GROUP BY campaign
ORDER BY total_events DESC
✅ Use * wildcard tables and _TABLE_SUFFIX to query partitioned GA4 data!
🛠️ Use Cases for Marketing Teams
| Use Case | BigQuery Role |
|---|---|
| Weekly campaign performance | Query all ad sources, join on date |
| ROAS dashboard | Calculate revenue/spend by campaign |
| Attribution | Join multi-touch paths with conversions |
| Audience segmentation | Create behavioral clusters with SQL |
| MMM/MTA inputs | Feed clean, joined tables into model scripts |
| Email retargeting | Export user list to Google Sheets/CDP |
📊 Connecting BigQuery to BI Tools
| Tool | Integration |
|---|---|
| Looker / Looker Studio | Native, real-time connection |
| Tableau | Connects via BigQuery SQL |
| Power BI | Works with ODBC/GCP connectors |
| Sheets | =QUERY_BIGQUERY() via Connected Sheets |
🧩 BigQuery Features Marketing Analysts Love
| Feature | Use Case |
|---|---|
| ✅ Partitioned tables | Speed up date-based campaign queries |
| ✅ Federated queries | Query CSVs/Sheets directly in GCS |
| ✅ Views | Save reusable queries like “Top Campaigns” |
| ✅ Scheduled queries | Automate daily updates (e.g., ROAS table) |
| ✅ Machine Learning | Use CREATE MODEL for logistic regression in SQL |
| ✅ Export to GCS/CDP | Move cleaned data to Meta CAPI or Segment |
💰 Cost Optimization Tips
| Strategy | Benefit |
|---|---|
Use LIMIT |
Test queries on small data before full run |
| Use partitions & clustering | Speeds up time-based queries |
| Select only needed columns | Avoid scanning wide tables |
| Preview data scanned | Watch the “Data processed” info in UI |
| Scheduled jobs off-peak | Save on on-demand pricing |
Excellent! You're now stepping into visual storytelling — where raw marketing data is transformed into insightful dashboards using tools like Power BI and Tableau.
📘 Module 13.1: Power BI / Tableau Dashboards for Marketing Analytics
🧠 Why Dashboards Matter in Marketing?
Marketing leaders need:
-
A real-time view of campaign performance
-
Visibility into conversion funnels, spend, and ROI
-
Ability to compare channels and optimize budgets
✅ Dashboards bring data to life — turning spreadsheets into actionable visuals.
🛠️ Power BI vs Tableau: Quick Comparison
| Feature | Power BI | Tableau |
|---|---|---|
| Integration | Deep with Microsoft ecosystem | Strong with Salesforce, cloud APIs |
| Pricing | ✅ More affordable | ❌ Higher enterprise pricing |
| Learning Curve | ✅ Beginner-friendly | ❌ Steeper for advanced features |
| Custom Visuals | Good, with Power BI visuals | Great, with high interactivity |
| Performance | Good for medium data sizes | Better for large, complex visuals |
| Cloud Support | Power BI Service (SaaS) | Tableau Online, Tableau Server |
📊 Common Marketing Dashboards You Should Build
| Dashboard Type | Key KPIs / Charts |
|---|---|
| Campaign Performance | Impressions, Clicks, CTR, CPC, ROAS |
| Attribution Overview | Conversion paths, assisted conversions |
| MMM/MTA Output | Spend vs. predicted revenue, ROI curves |
| Funnel Analysis | Visits → Add to Cart → Purchase drop-offs |
| Email / CRM Analytics | Opens, Clicks, Conversions, Unsubscribes |
| Budget Pacing Tracker | Daily spend vs. planned budget (burn rate) |
🧩 Sample Power BI Marketing Dashboard Layout
-------------------------------------------------
| 📆 Date Selector | Channel Filter | Country 🌍 |
-------------------------------------------------
| Line Chart: Weekly Spend & Revenue |
| Bar Chart: ROAS by Channel |
| Funnel Chart: Website → Product View → Order |
| Table: Top Campaigns with CTR, CPC, Spend |
| Card: Conversion Rate | CPA | Budget Left |
-------------------------------------------------
📐 Sample Tableau Funnel Dashboard (e-commerce)
-
Page 1: Funnel
-
Step 1: Website Visit
-
Step 2: Product View
-
Step 3: Add to Cart
-
Step 4: Checkout
-
Step 5: Purchase
-
-
Page 2: Campaign Impact
-
Filters: Source, Medium, Country
-
Line chart: Spend vs Revenue
-
Heatmap: ROI by Region
-
🔄 Common Data Sources for Dashboards
| Source | Data Type | Integration |
|---|---|---|
| BigQuery / Redshift | Processed ETL data | ✅ Native |
| GA4 | Web & conversion data | ✅ via API |
| Facebook Ads | Campaign metrics | ✅ via API / ETL |
| HubSpot / Salesforce | Leads, contacts, pipeline | ✅ via connectors |
| CSV/Excel | Manual campaign logs or mappings | ✅ Drag-drop |
🎨 Visuals to Use in Marketing Analytics
| Visual Type | Best For |
|---|---|
| Line Chart | Time series (spend, impressions, revenue) |
| Bar Chart | Channel performance comparison |
| Funnel | Conversion journey visualization |
| Map | Geo-based performance (CPC by region) |
| Stacked Area | Share of spend across time |
| Table + KPIs | Detailed breakdown + snapshot metrics |
🧠 Design Tips
✅ Use filters for Channel, Region, and Time Range
✅ Highlight anomalies with conditional formatting
✅ Add tooltips for deep-dive explanations
✅ Use dynamic text (e.g., “Revenue grew by +15% vs last week”)
✅ Stick to 2–3 color palettes for clarity
Absolutely! Let’s now go deeper into the most essential Marketing KPIs you should be tracking and visualizing in your dashboards — these form the backbone of data-driven marketing decisions.
📘 Module 13.2: Marketing KPIs to Track
🧠 Why KPIs Matter
Key Performance Indicators (KPIs) help measure success of marketing campaigns and channels, and guide decisions around:
-
Budget allocation
-
Channel optimization
-
Conversion efficiency
-
Customer journey effectiveness
✅ The right KPIs align marketing teams with business goals.
🧩 Core Marketing KPI Categories
| Category | Focus Area |
|---|---|
| Awareness | Reach, Impressions, Engagement |
| Acquisition | Clicks, Leads, Traffic |
| Conversion | Purchases, Signups, Conversions |
| Efficiency | CPA, ROAS, CAC, LTV |
| Retention | Repeat rate, Churn, Loyalty |
| Attribution | Assisted conversions, Touchpoints |
| Revenue Impact | Sales generated, Contribution to pipeline |
📊 Common Marketing KPIs (with Formulas)
| KPI | Description | Formula |
|---|---|---|
| Impressions | Total times ad/content was displayed | — |
| Clicks | Total clicks on ad or CTA | — |
| CTR (Click-Through Rate) | How often people click | (Clicks / Impressions) × 100 |
| Conversions | Desired actions (purchases, signups) | — |
| CVR (Conversion Rate) | How many clicks led to conversions | (Conversions / Clicks) × 100 |
| CPA (Cost per Acquisition) | Cost to get a customer | Spend / Conversions |
| ROAS (Return on Ad Spend) | Revenue per ₹1 spent | Revenue / Ad Spend |
| CAC (Customer Acquisition Cost) | Full cost to acquire a customer | (Total marketing + sales cost) / Customers acquired |
| LTV (Lifetime Value) | Average total revenue per customer | Avg Purchase × Repeat Rate × Retention Duration |
| Churn Rate | How many customers left | (Lost Customers / Total Customers) × 100 |
| Revenue by Channel | Sales generated by each source | Tracked via UTM/source |
📊 KPI Dashboard Segmentation Examples
| Segment | Example |
|---|---|
| By Channel | ROAS by Facebook, Google, Email |
| By Campaign | CPA by “Summer Sale” vs “New Launch” |
| By Region | CVR by Country or State |
| By Device | ROAS on Mobile vs Desktop |
| By Funnel Stage | Drop-off at Add-to-Cart vs Checkout |
🔁 Real-Time vs Strategic KPIs
| Real-Time KPIs | Use For |
|---|---|
| Daily Spend, Clicks | Daily pacing and budget control |
| CTR, CVR | Campaign performance optimization |
| Error rates, bounce rates | Landing page testing |
| Strategic KPIs | Use For |
|---|---|
| CAC, LTV, Churn | Board-level reporting, financial forecasting |
| ROAS trend (weekly/monthly) | Budget allocation |
| Attribution insights | Cross-channel investment |
🎯 Executive Dashboard: Key Metrics to Include
| Area | KPIs |
|---|---|
| Top-Level Cards | Total Spend, Total Revenue, ROAS, CPA |
| Channel Performance Table | Impressions, Clicks, Conversions, ROAS by channel |
| Time Series | Daily/weekly trend of spend and conversions |
| Funnel Chart | Website visit → Add to Cart → Purchase |
| Top Campaigns | CTR, CPC, CPA comparison |
| Customer Metrics | CAC, LTV, Retention rate |
Perfect! Let’s now explore one of the most transformational steps in any marketing analytics practice — enabling self-serve analytics so marketers, product managers, and leadership can explore data without relying on the data team.
📘 Module 13.3: Self-Serve Analytics Setup for Marketing
🧠 Why Self-Serve Analytics?
In many organizations, marketers constantly wait on data teams for:
-
Weekly campaign reports
-
Conversion breakdowns
-
Audience engagement insights
-
Budget pacing vs spend vs revenue
✅ Self-serve analytics empowers non-technical teams to explore real-time data on their own, saving time and driving faster decisions.
🧩 Core Components of a Self-Serve Analytics System
| Layer | Tool/Concept | Purpose |
|---|---|---|
| Data Warehouse | BigQuery, Snowflake, Redshift | Stores all cleaned data |
| Semantic Layer | dbt, LookML, Power BI datasets | Defines business logic (e.g., ROAS = Revenue/Spend) |
| Visualization Tool | Power BI, Tableau, Looker Studio | User interface to explore data |
| Access Control | Row-level, role-based permissions | Limits who sees what |
| Data Dictionary / Glossary | Notion, Confluence, Docs | Explains KPIs and tables |
| Training & Onboarding | Playbooks, video tutorials | Empowers users to explore confidently |
📊 What Should Be Self-Served?
| Report Type | Self-Serve? | Example |
|---|---|---|
| Campaign Performance | ✅ Yes | Facebook vs Google vs LinkedIn |
| Funnel Drop-Offs | ✅ Yes | Add-to-cart → Checkout |
| Email Metrics | ✅ Yes | Open, click, bounce rate |
| Attribution Paths | ❌ Complex | Needs advanced modeling |
| MMM Results | ❌ No | Needs statistical interpretation |
| Segment Creation for Retargeting | ✅ Yes (with governance) | High LTV customers in last 30 days |
🛠 Steps to Set Up a Self-Serve Analytics System
🔹 1. Build a Clean, Central Data Layer
-
Use Airflow/dbt to load and transform:
-
Campaign data
-
Website events
-
CRM contacts
-
Conversion metrics
-
-
Join into unified reporting tables (example:
marketing_performance_daily)
🔹 2. Create Semantic Views
Translate raw SQL logic into reusable views:
| View Name | Contains |
|---|---|
spend_summary |
channel, campaign, spend, impressions |
conversion_summary |
campaign, clicks, conversions, CVR |
roas_dashboard |
ROAS, CPA, CAC by date & channel |
✅ Tools like dbt, Power BI datasets, and LookML can define these centrally.
🔹 3. Build Visual Dashboards with Filters
-
Use Power BI/Tableau/Looker Studio
-
Add interactive filters:
-
Channel
-
Date Range
-
Campaign Name
-
Region
-
Device Type
-
✅ Marketers can filter and view only the data they need without SQL.
🔹 4. Set Role-Based Access Control
| Role | Access |
|---|---|
| Marketing Executive | Global view |
| Paid Media Manager | Only Meta + Google campaigns |
| CRM Manager | Only Email + SMS metrics |
| Regional Head | Only their geography |
✅ In Power BI: use RLS (Row-Level Security)
✅ In Tableau: use User Filters + Permissions
🔹 5. Create a Data Dictionary or Glossary
| Field | Definition |
|---|---|
| ROAS | Revenue ÷ Spend |
| CAC | Customer Acquisition Cost |
| UTM Source | Origin platform (e.g., facebook, google) |
| Sessions | Number of website visits |
✅ Store this in Notion, Confluence, or a pinned doc
✅ Helps marketers interpret fields and avoid confusion
🔹 6. Train Non-Technical Users
| Resource | Use |
|---|---|
| Video tutorials | “How to use the dashboard” |
| Live walkthroughs | 30-min Q&A sessions with marketers |
| Slack channel | #ask-data or #analytics-help |
| FAQ document | “Why is ROAS different than yesterday?” |
💡 Real-World Example: Self-Serve Funnel Dashboard
| Filter | Result |
|---|---|
| Channel = “Google Ads” | Show CVR and CPA trend from only Google |
| Region = “US” | See how ROAS differs in US vs other markets |
| Time Range = “Last 30 Days” | Updated funnel and budget burn rate |
Awesome! Now we enter the hands-on application phase — actually building a real Marketing Mix Model (MMM) using one of the most advanced open-source libraries: Facebook’s Robyn.
📘 Module 14.1: Build a Real MMM Model using Facebook Robyn
🧠 Why Facebook Robyn?
Facebook Robyn is an open-source MMM library designed to:
-
Automate model selection and optimization
-
Handle adstock, saturation, and multicollinearity
-
Optimize media allocation using simulations
-
Run parallel models to give confidence intervals
✅ It’s scalable, interpretable, and built for modern marketers.
🔧 What is Robyn?
| Feature | Description |
|---|---|
| Language | R (can be run via Python wrapper or Colab) |
| Modeling technique | Ridge regression with regularization |
| Handles | Saturation (Hill), Adstock (Geometric) |
| Model validation | Multi-model generation with decomposition |
| Output | Spend contribution, ROI, budget simulator |
🧩 Step-by-Step Workflow to Build a Robyn MMM
✅ 1. Install Robyn
Robyn is written in R. Use the following to install:
# Install devtools
install.packages("devtools")
library(devtools)
# Install Robyn
devtools::install_github("facebookexperimental/Robyn/R")
📦 Required packages:
library(Robyn)
library(dplyr)
library(ggplot2)
library(reticulate) # for Python if needed
✅ 2. Prepare Input Data
You need a weekly dataset with:
| Variable | Description |
|---|---|
date |
Week start date |
revenue |
Dependent variable |
tv_spend |
Channel 1 |
facebook_spend |
Channel 2 |
search_spend |
Channel 3 |
email_clicks |
Control variable (optional) |
holiday_flag |
External factor (optional) |
📁 Example format:
date,revenue,tv_spend,facebook_spend,search_spend,holiday_flag
2024-01-01,12000,5000,2000,1500,1
2024-01-08,13500,5200,2100,1600,0
...
✅ Keep weekly granularity, no missing dates, numeric values only.
✅ 3. Run Robyn’s Core Setup
InputCollect <- robyn_inputs(
dt_input = my_data,
date_var = "date",
dep_var = "revenue",
dep_var_type = "revenue", # could be "conversion" too
prophet_vars = c("holiday_flag"), # optional
media_vars = c("tv_spend", "facebook_spend", "search_spend"),
adstock = "geometric", # or "weibull"
window_start = "2024-01-01",
window_end = "2024-06-30"
)
✅ 4. Run MMM Models (Parallel)
OutputModels <- robyn_run(
InputCollect = InputCollect,
cores = 4, # number of CPU cores
iterations = 2000,
trials = 5 # number of models to keep
)
🔁 This runs 2000+ iterations and keeps 5 best-performing models based on NRMSE, DECOMP.RSSD, etc.
✅ 5. Model Selection & Interpretation
robyn_outputs(OutputModels)
You’ll see:
-
Media channel contributions
-
ROI by channel
-
Decomposed revenue
-
Saturation curves
-
Adstock response
✅ Helps understand which channel is contributing what share.
✅ 6. Budget Allocation Simulation
# Simulate with new budget split
robyn_allocator(
OutputModels,
scenario = "maximize_response",
total_budget = 100000,
channel_constr_low = c(0.1, 0.1, 0.1),
channel_constr_up = c(0.5, 0.5, 0.5)
)
🎯 Simulate:
-
Which split of spend gives highest revenue?
-
What’s the diminishing return threshold?
📈 Sample Outputs from Robyn
| Channel | ROI | Contribution % | Spend |
|---|---|---|---|
| TV | 1.8 | 30% | ₹1,00,000 |
| 2.4 | 45% | ₹70,000 | |
| Search Ads | 3.1 | 25% | ₹40,000 |
📊 Visuals:
-
ROI curves
-
Saturation response
-
Adstock lag impact
-
Weekly revenue decomposition
Perfect, Sanjay! Let’s now dive into Multi-Touch Attribution (MTA) — a powerful way to assign credit to multiple touchpoints across a user journey. In this module, you'll learn how to build MTA models using Markov Chains and Shapley Values, two widely-used data-driven approaches.
📘 Module 14.2: Build an MTA Model with Markov Chains & Shapley Values
🧠 Why MTA?
Unlike last-touch or first-touch, MTA considers every step in the customer journey, answering:
-
Which touchpoints (channels) matter most?
-
What’s the true contribution of email, paid ads, direct, etc.?
-
Where are drop-offs or assist opportunities?
✅ MTA helps optimize cross-channel marketing spend more fairly.
🎯 Use Case
Let’s say you have these user paths:
Path 1: Facebook → Google → Direct → Conversion
Path 2: Email → Direct → Conversion
Path 3: Google → Facebook → No Conversion
Which channel actually contributed most to conversions?
🔢 Input Data Format
MTA models typically need:
| user_id | path | converted |
|---|---|---|
| 1 | facebook > google > direct | 1 |
| 2 | email > direct | 1 |
| 3 | google > facebook | 0 |
✅ This is the minimum format needed to run both Markov and Shapley models.
🧩 Method 1: Markov Chain Attribution
📌 Concept
-
Every touchpoint is a state
-
Model the probability that a user moves from one channel to another and finally converts
-
Drop a channel → see drop in conversion probability = its attribution value
✅ Looks at removal effects (how important a touchpoint is in driving conversion)
🛠 Build Markov Model in Python
!pip install attribution-models
from attribution_models.markov import MarkovModel
import pandas as pd
# Sample paths
data = pd.DataFrame({
'path': ['facebook > google > direct', 'email > direct', 'google > facebook'],
'conversion': [1, 1, 0]
})
mm = MarkovModel()
mm.fit(data['path'], data['conversion'])
# Attribution scores
print(mm.get_attribution())
✅ Output: Attribution score per channel based on removal effect
📊 Interpreting Output
| Channel | Attribution Score |
|---|---|
| 0.35 | |
| 0.25 | |
| 0.20 | |
| Direct | 0.20 |
✅ Use this to redistribute budget or prioritize assists
🧮 Method 2: Shapley Value Attribution
📌 Concept
-
Comes from cooperative game theory
-
Each touchpoint is a “player” in the conversion
-
Shapley value = average marginal contribution of that player across all combinations
✅ Fair & mathematically rigorous, but computationally expensive
🛠 Build Shapley Model in Python
from attribution_models.shapley import ShapleyModel
sm = ShapleyModel()
sm.fit(data['path'], data['conversion'])
print(sm.get_attribution())
✅ Output: Attribution score per channel based on Shapley values
📊 Comparison Table
| Method | Strengths | Weaknesses |
|---|---|---|
| Markov Chain | Fast, interpretable, removal logic | Doesn’t consider all combinations |
| Shapley Value | Fair, based on all permutations | Slower with many channels |
✅ Practice Task
-
Create a dataset of at least 10 user journeys (path + conversion flag)
-
Use both Markov and Shapley models on the data
-
Compare results:
-
Which channels are ranked highest?
-
Are assist channels (like “Email”) showing more value in Shapley?
-
How does budget reallocation look based on attribution?
-
🔁 Combining MTA with MMM
| Technique | Role |
|---|---|
| MMM | Long-term, strategic (weekly/monthly) |
| MTA | Granular, user-level (daily/journey-wise) |
| Hybrid | MMM adjusts for spend; MTA helps allocate |
✅ Combine MTA’s touchpoint granularity with MMM’s budget optimization
Great choice, Sanjay! Now that you understand attribution and marketing mix modeling (MMM), let’s go one step further and use those insights to automatically recommend budget allocation across channels.
📘 Module 14.3: Budget Optimization Recommendation Engine
🧠 Why Budget Optimization?
Marketers often ask:
-
Where should I spend my next ₹1,00,000?
-
Which channel is under- or over-performing?
-
How much can I shift to maximize conversions or revenue?
✅ A budget recommendation engine answers these by combining model outputs (from MMM or MTA) with mathematical optimization.
🎯 Goal
Use performance data + constraints to recommend an optimal media mix for a given budget.
🧩 Inputs Required
| Input | Example |
|---|---|
| Channels | Facebook, Google, Email, TV |
| Historical Spend | ₹1,00,000 per channel (last month) |
| ROI or Response Curve | From MMM / MTA / observed data |
| Min/Max Constraints | Facebook (10–50%), Google (20–60%) |
| Objective | Maximize conversions or revenue |
| Total Budget | ₹5,00,000 |
🧠 Mathematical Formulation
A basic optimization problem:
Maximize
where is the ROI response curve (can be linear or non-linear)
Subject to:
(total budget)
(min/max constraints per channel)
✅ Can be solved using SciPy, CVXPY, or Bayesian Optimization.
🛠 Example in Python: Linear ROI
import numpy as np
from scipy.optimize import minimize
# Channels and ROI (from MMM or MTA)
channels = ['facebook', 'google', 'email']
roi = [2.0, 1.8, 1.2] # revenue per ₹ spent
# Budget constraints
total_budget = 500000
bounds = [(50000, 250000), (100000, 300000), (50000, 150000)] # (min, max) for each channel
# Objective: maximize revenue = ∑(roi[i] * spend[i])
def objective(spends):
return -sum(roi[i] * spends[i] for i in range(len(spends))) # negative for minimizer
# Constraint: sum of spends = total budget
constraints = {'type': 'eq', 'fun': lambda x: sum(x) - total_budget}
# Initial guess
init = [100000, 200000, 200000]
res = minimize(objective, init, bounds=bounds, constraints=constraints)
optimal_spends = dict(zip(channels, res.x))
print("🔧 Optimal Budget Allocation:")
for ch, val in optimal_spends.items():
print(f"{ch.title()}: ₹{val:,.0f}")
📈 Output Example
🔧 Optimal Budget Allocation:
Facebook: ₹2,50,000
Google: ₹2,00,000
Email: ₹50,000
✅ Allocate more to Facebook due to high ROI and room to grow
🔁 Using Saturation or Diminishing Return Curves
If you’ve modeled non-linear response using Hill or logistic functions:
def response(x):
return a * x / (b + x) # Hill function shape
# Use for each channel in optimization
⚠ This gives more realistic results than linear ROI (especially when channels saturate)
📊 Budget Simulator Dashboard (Optional Build)
| Channel | ROI | Spend | Contribution | Saturation Curve |
|---|---|---|---|---|
| 1.8 | ₹2L | ₹3.6L | ![curve] | |
| 1.2 | ₹0.5L | ₹0.6L | ![curve] |
✅ Add slider to adjust total budget and re-run optimization logic dynamically
📘 Module 14.4: End-to-End Marketing Analytics Pipeline
🧠 Why This Matters
A typical challenge in companies:
“We have dashboards, data in silos, and no unified flow from raw input → modeling → decision → reporting.”
An end-to-end pipeline solves this by automating the entire journey:
✅ Ingest → Clean → Model → Optimize → Visualize → Serve
🧩 Pipeline Overview
┌────────────┐
│ Marketing │
│ Channels │
└────┬───────┘
▼
┌──────────────┐
│ ETL Layer │ ← Airflow / dbt / Python
└────┬─────────┘
▼
┌─────────────┐
│ Data Lake / │
│ Warehouse │ ← BigQuery / Snowflake / Redshift
└────┬────────┘
▼
┌──────────────┐
│ Modeling │ ← MMM (Robyn) / MTA (Markov, Shapley)
└────┬─────────┘
▼
┌──────────────┐
│ Optimization │ ← Scipy / Pyomo / CVXPY
└────┬─────────┘
▼
┌────────────┐
│ Dashboards │ ← Power BI / Tableau / Streamlit
└────┬───────┘
▼
┌────────────┐
│ API Layer │ ← Flask / FastAPI (Serve models)
└────────────┘
🔧 Step-by-Step Breakdown
🔹 1. Data Collection / Ingestion
| Source | Tool | Output |
|---|---|---|
| GA4, Facebook Ads | Supermetrics, Funnel.io, APIs | Raw JSON/CSV |
| CRM (HubSpot, Salesforce) | API / CSV export | Contact & deal data |
| Internal DB | SQL scripts, Python ETL | Revenue, conversions |
✅ Use Airflow, dbt, or Python scripts to fetch on a schedule.
🔹 2. Data Storage
| Tool | Role |
|---|---|
| Google BigQuery | Serverless warehouse for large-scale storage |
| Snowflake | Great for scaling with marketing data |
| PostgreSQL | Simpler option for small teams |
✅ Ensure tables like:
-
campaign_spend_daily -
conversions_by_channel -
user_journeys -
funnel_stage_metrics
🔹 3. Modeling Layer
| Model | Technique | Output |
|---|---|---|
| MMM | Facebook Robyn (R) | ROI, contribution, optimizer |
| MTA | Markov / Shapley | Attribution weights |
| CLV | RFM or LTV models | Customer segments |
✅ Store model outputs back to the warehouse.
🔹 4. Optimization Engine
Use Scipy, CVXPY, or Pyomo to calculate:
-
Optimal budget split
-
ROAS-maximizing spend scenarios
-
Pacing plans per channel per week
✅ Automate this weekly or monthly via Airflow
🔹 5. Serving & API Layer
| Component | Tool |
|---|---|
| Model Hosting | Flask / FastAPI microservice |
| Triggering | Webhook / Scheduler |
| Response | JSON output: optimal budget, channel scores |
✅ Example: “/get-budget?revenue_goal=100000” → API returns suggested spend by channel
🔹 6. Visualization & Self-Serve Reporting
| Tool | Use |
|---|---|
| Power BI / Tableau | For CMO, marketing leads |
| Streamlit | Internal model testing, attribution explainability |
| Looker Studio | Lightweight reporting on Google data |
✅ Include:
-
Weekly revenue vs spend
-
Attribution contribution (%)
-
Funnel drop-offs
-
Optimized budget suggestion
🔁 Deployment Schedule Example
| Component | Frequency |
|---|---|
| ETL pipeline | Daily |
| MMM/MTA model | Weekly |
| Optimizer | Weekly |
| Dashboard sync | Daily |
| API call | On-demand |
✅ Practice Blueprint: Mini Project Plan
| Task | Tool |
|---|---|
| Pull GA4 + Meta spend | Python + API |
| Store in SQLite / BigQuery | SQLite |
| Run a dummy MMM with linear regression | Python |
| Add optimizer using Scipy | Python |
| Build Streamlit app with sliders for budget | Streamlit |
| Host model as API using FastAPI | FastAPI + render/huggingface spaces |
🧠 Summary
| Layer | Tools Used |
|---|---|
| Ingestion | Python, Airflow, dbt |
| Storage | BigQuery, PostgreSQL, Snowflake |
| Modeling | Facebook Robyn, Markov Chains |
| Optimization | Scipy, Pyomo, CVXPY |
| Visualization | Power BI, Tableau, Streamlit |
| API Serving | Flask, FastAPI, Docker |
✅ This is your production-ready marketing analytics architecture — just like top companies use.
🔚 Congrats! You've completed the core modules of your Marketing Analytics Full Course.
Comments
Post a Comment