In this playbook, we'll explore the essentials of creating an AI-powered agent that analyzes Google Analytics 4 (GA4) data to provide actionable customer acquisition recommendations. This agent will analyze traffic channels, user behavior, and conversion data to identify which acquisition channels are performing well and where improvements can be made.

The recommendations will include specific actions for improving customer acquisition across different traffic sources, each with a rationale, expected impact, and priority level.

Here's an example of a report generated by the agent:

=== RECOMMENDED MARKETING ACTIONS ===
# Marketing Action Recommendations

## Google Organic
- **Action**: Develop content targeting high-converting keywords and optimize landing pages for improved SEO
- **Rationale**: While Google Organic drives the highest user volume (12,221 users) and has a strong new user acquisition rate (81.97%), the conversion rate (2.32%) is lower than channels like Referral and Other
- **Expected Impact**: Increasing the conversion rate from 2.32% to 3.2% (matching "Other" channel) could generate approximately 107 additional conversions and $8,000+ in revenue
- **Priority**: High

## Referral
- **Action**: Expand partnership and affiliate marketing programs with websites driving quality traffic
- **Rationale**: Referral traffic has the highest conversion rate (3.45%) and strong revenue per conversion ($74.92), indicating high-quality traffic despite lower total volume
- **Expected Impact**: A 20% increase in referral traffic could produce approximately 48 additional conversions and $3,600 in revenue
- **Priority**: High

## Other
- **Action**: Analyze and identify the specific sources within the "Other" category that are driving strong performance
- **Rationale**: "Other" shows the second-highest conversion rate (3.23%) and solid revenue ($19,496), but lacks source specificity needed for targeted optimization
- **Expected Impact**: Proper attribution and scaling of top-performing "Other" sources could increase conversions by 15% (45 additional conversions)
- **Priority**: Medium

## Paid Search
- **Action**: Reallocate budget to higher-performing keywords and improve ad targeting and landing page relevance
- **Rationale**: Despite strong new user acquisition (89.27%) and engagement rate (60.31%), Paid Search has low conversion volume (39) and average revenue per conversion ($50.31)
- **Expected Impact**: Optimizing campaigns could increase conversion rate from 2.24% to 3.0%, generating 13 additional conversions
- **Priority**: Medium

## Direct
- **Action**: Implement branded retargeting campaigns to re-engage the large base of direct traffic users
- **Rationale**: Direct traffic represents significant volume (9,131 users) but has the lowest engagement rate (55.92%) and second-lowest conversion rate (2.28%)
- **Expected Impact**: Improving engagement and conversion rates could generate 20% more conversions (42 additional) from this existing traffic
- **Priority**: Medium

## Overall Strategy

The data reveals an opportunity to improve quality over quantity in our acquisition efforts. Our strategy should focus on three key areas:

1. Maximize organic search efficiency by creating content that better converts the substantial traffic we already receive
2. Scale up referral partnerships that are already demonstrating high-quality traffic and conversions
3. Improve attribution and analysis of "Other" sources to identify hidden opportunities

By focusing on these higher-converting channels rather than simply driving more volume, we can improve overall marketing ROI while building a more sustainable customer acquisition framework.

How The Agent Works

Before diving into the code, let's understand the overall architecture of our Customer Acquisition Agent. The diagram below illustrates how data flows through the system, from raw GA4 data to actionable insights. The agent uses BigQuery SQL to extract and transform GA4 data, processes it through PydanticAI, and generates specific recommendations that marketing teams can implement to improve customer acquisition effectiveness.

We follow a straightforward data pipeline pattern: extract data from GA4 using BigQuery, analyze it with AI, and transform the analysis into structured, actionable recommendations.

🚀
The end of the playbook links to a production-ready code bundle on GitHub for the Customer Acquisition Report Agent.

Let's examine how we implement each part of this pipeline in code.

Step 1: The Core Functionality

The heart of our system is the CustomerAcquisitionAgent class in agent.py. Let's look at its key components:

This post is for paying subscribers only

Sign up now and upgrade your account to read the post and get access to the full library of posts for paying subscribers only.

Sign up now Already have an account? Sign in