Auto-Analyst — Adding marketing analytics AI agents

This is a post on how I added marketing analytics functionality to the Auto-Analyst

Arslan Shahid
FireBird Technologies
7 min readNov 5, 2024

--

Image by Author

A few months back, I built a multi-agent system to work like an AI data scientist. Now, I’m planning to add some specialized agents focused on marketing analytics — a hot area, especially with digital marketing turning into such a big industry.

Here are a few new agents I have in mind:

  1. Marketing Reporting Agent — This agent would create a custom marketing report based on what the user asks for.
  2. Bidding Strategy Analytics — This one would analyze strategies like CPC (cost per click), CPA (cost per acquisition), and CPS (cost per sale) to see their impact on campaigns. It could even provide insights before a campaign starts.
  3. Customer Analytics — This agent would build statistical models for things like customer lifetime value or customer acquisition, helping to understand long-term customer behavior.

There are plenty of other agents that can be designed while keeping marketing in mind. As a starting point, I have picked these three use cases.

Building the agent signatures

The auto-analyst is built using DSPy and each analytics agent is a DSPy signature.

DSPy Signature explained

DSPy makes it very straightforward and convenient to build a custom LLM agent/program that does some specific task.

Marketing Reporting agent

import dspy 

class marketing_reporting_agent(dspy.Signature):
# Analytics Agent for generating marketing reports
# Prompt
"""You are a marketing reporting agent specialized in creating data-driven marketing reports.
Your task is to take marketing data, a user-defined goal, and report instructions to generate
Python code that creates insightful marketing reports and visualizations.
You should use libraries like pandas, matplotlib, seaborn, and plotly for the analysis and visualization.


Make sure your output matches the report instructions and goal!

Visualization Requirements:
- Line charts showing trends for all metrics
- Correlation heatmap between metrics
- Use Plotly for all visualizations
- Monthly comparison bar charts
- Rolling averages to smooth out fluctuations
- Interactive plots for detailed exploration
- Don't set index, just use the default index
- Set number of floating points to 2

Additional Analysis:
- Calculate key statistical measures (mean, median, std dev)
- Identify any significant correlations between metrics
- Highlight notable insights and patterns
- Provide recommendations based on findings
"""
#Inputs
dataset = dspy.InputField(desc="Available datasets loaded in the system, use this df,columns. set df as copy of df")
goal = dspy.InputField(desc="The user defined goal")
report_instructions = dspy.InputField(desc="Specific instructions for report format, metrics, and visualizations")
# Outputs
code = dspy.OutputField(desc="The code that generates the marketing report")


This is the marketing Dataset.

The agent takes in three things. dataset (a string of data information like columns, variable type, etc), goal (user-intended goal or query), and report_instructions (string on what the report should do). You can create any custom way to pass reporting instructions. Below is an example:

query = "Tell me about how key KPIs are changing over time?"
report_instructions = """
1. Executive Summary
- Highlight top 3 KPIs showing significant changes
- Provide clear actionable insights
- Flag any metrics requiring immediate attention

2. Action Items Section
- List top 3 areas needing improvement
- Provide data-backed recommendations
- Include estimated impact of proposed changes

3. Report Format Requirements
- Use executive-friendly visualizations
- Keep decimal points to maximum of 2 places
- Use consistent color scheme for all charts
"""

Here is the output from the marketing report agent:

Image of parts of the report
GIF animation of the entire generated report

The agent was able to create an entire marketing report in one shot. You can change the reporting instructions to come up with a custom reporting style.

Want an expert to build custom AI agents for you?

Click here to reach out:
https://form.jotform.com/240744327173051

Bidding Strategy Agent

For the bidding strategy agent, I’m following a similar setup as the other agents in the auto-analyst system. The agent takes in a user’s question or goal, along with information about the dataset, and then generates code to perform the analysis needed to answer the question.

class bidding_strategy_agent(dspy.Signature):
# Analytics Agent for optimizing bidding strategies
"""You are a bidding strategy analytics agent specialized in marketing analytics.
Your task is to take marketing campaign data and a user-defined goal, and output Python code that performs
bidding strategy analysis and optimization.
You should use libraries like numpy, pandas, and scikit-learn for the analysis.

Bidding strategy tasks include:
- Analyzing historical bid performance
- Optimizing bid values across channels
- Forecasting campaign performance
- A/B testing bid strategies
- ROI and conversion rate analysis
- Budget allocation optimization

Make sure your output is as intended!
Use Plotly for all visualizations

The dataset is loaded as bidding_df, just use bidding_df.copy(), make a copy don't change the original bidding_df
handle numeric and categorical columns differently.

Calculate bid improvements as numbers and percentages. Show clearly how to improve the bids.


"""
dataset = dspy.InputField(desc="Available datasets loaded in the system, use this df,columns. set df as copy of df")
goal = dspy.InputField(desc="The user defined goal ")
code = dspy.OutputField(desc="The code that performs the bidding strategy analysis")
commentary = dspy.OutputField(desc="The comments about what bidding strategy analysis is being performed")

Query = "Figure out in which product categories is our bidding strategy failing? Tell us which bids we should improve and by how much? Which variables are most important?"

Example:

Query: Figure out in which product categories is our bidding strategy failing. Tell us which bids we should improve and by how much. Which variables are most important?”

dataset head, has information of bidding strategy applied.
Output generated

The plots show the difference between the placed bid vs the winning bid.

This is a dummy dataset. Usually, winning bids are not shared on Meta / Google Ads, but the AI can adapt to the dataset. You can change the prompt to meet your specific requirements.

Customer Analytics Agent

class customer_analytics_agent(dspy.Signature):
# Analytics Agent for customer value and acquisition analysis
"""You are a customer analytics agent specialized in analyzing customer behavior and value.
Your task is to take customer data and a user-defined goal, and output Python code that performs
customer lifetime value, acquisition cost, and ROI analysis.
You should use libraries like numpy, pandas, scikit-learn and lifetimes for the analysis.

Customer analytics tasks include:
- Customer Lifetime Value (CLV/LTV) modeling
- Customer Acquisition Cost (CAC) analysis
- Customer segmentation and clustering
- Churn prediction and prevention
- Customer journey mapping
- ROI and retention metrics
- Purchase behavior analysis

Make sure your output is as intended!

Use Plotly for all visualizations

"""
dataset = dspy.InputField(desc="Available datasets loaded in the system, use this df,columns. set df as copy of df")
goal = dspy.InputField(desc="The user defined goal ")
code = dspy.OutputField(desc="The code that performs the customer analytics")
commentary = dspy.OutputField(desc="The comments about what customer analysis is being performed")

Like most analytics agent(s) the customer analytics agent has a similar input/output structure.

Dummy dataset for customer analytics

Example:

Query= “Build a statistical model to predict customer lifetime value?”

Generated output, which shows the lifetime value predictions (dummy dataset)

The agent generates a statistical model which can be used to compute life time value for your customers, informing which customers to target and what is the expected ‘value’ of each customer.

Conclusion

These are three marketing analytics agents I’m adding to the auto-analyst system. They work well in the examples shown, but they’ll likely need a lot more work to perfect in real-world scenarios.

This post is just the first step in building a multi-agent system focused on marketing analytics. If you’re interested in updates on this project, please follow me and FireBird Technologies on Medium!

Thank you for reading!

Want an expert to build custom AI agentic systems for you?

Click here to reach out:

https://tally.so/r/3x9bgo

--

--

No responses yet