Everyone got the same content.
Problem: Beginners saw advanced stuff, and advanced users saw basics. Wrong message, wrong person. 3% conversion rate. Lots of bounces.
Then I added AI personalization.
Now: Content adapts to each visitor. Beginners get beginner stuff, advanced users get advanced. Right message → right person. 11% conversion rate.
Here's the system:
import openai
from typing import Dict, List, Optional
import json
class ContentPersonalizationEngine:
"""AI-powered content personalization."""
def __init__(self):
self.client = openai.OpenAI()
self.user_profiles = {}
self.content_variants = {}
def analyze_visitor(
self,
visitor_data: Dict,
browsing_history: List[Dict],
referral_source: str
):
"""Analyze visitor to determine their profile."""
print("👤 Analyzing visitor...")
# Build visitor profile
profile = {
'visitor_id': visitor_data.get('id', 'unknown'),
'experience_level': self.detect_experience_level(browsing_history),
'interests': self.detect_interests(browsing_history),
'stage': self.detect_journey_stage(browsing_history, referral_source),
'preferences': self.detect_preferences(browsing_history),
'intent': self.detect_intent(browsing_history, referral_source)
}
# Get AI insights
ai_profile = self.enrich_profile_with_ai(profile, browsing_history)
print(f"✅ Profile: {ai_profile['experience_level']} | {ai_profile['stage']}")
return ai_profile
def detect_experience_level(self, browsing_history: List[Dict]):
"""Detect visitor's experience level."""
beginner_keywords = ['getting started', 'beginner', 'intro', 'basics', 'what is']
advanced_keywords = ['advanced', 'optimization', 'scaling', 'automation', 'API']
beginner_count = sum(
1 for content in browsing_history
if any(kw in content['title'].lower() for kw in beginner_keywords)
)
advanced_count = sum(
1 for content in browsing_history
if any(kw in content['title'].lower() for kw in advanced_keywords)
)
if advanced_count > beginner_count * 2:
return 'advanced'
elif beginner_count > advanced_count * 2:
return 'beginner'
else:
return 'intermediate'
def detect_interests(self, browsing_history: List[Dict]):
"""Detect what topics they're interested in."""
tags = [item['tags'] for item in browsing_history]
interests = {}
for tag_list in tags:
if not tag_list:
continue
for tag in tag_list:
interests[tag] = interests.get(tag, 0) + 1
top_interests = sorted(interests.items(), key=lambda x: x[1], reverse=True)[0:5]
return [interest[0] for interest in top_interests]
def detect_journey_stage(self, browsing_history: List[Dict], referral_source: str):
"""Detect where they are in customer journey."""
if not browsing_history:
return 'unaware'
if len(browsing_history) > 5:
return 'most_aware'
elif len(browsing_history) > 2:
return 'product_aware'
else:
return 'solution_aware'
def detect_preferences(self, browsing_history: List[Dict]):
"""Detect content format preferences."""
formats = {}
for item in browsing_history:
if not item.get('format'):
continue
formats[item['format']] = formats.get(item['format'], 0) + 1
preferred_format = max(formats.items(), key=lambda x: x[1])
return {'preferred_format': preferred_format[0]}
def detect_intent(self, browsing_history: List[Dict], referral_source: str):
"""Detect visitor intent."""
if not browsing_history:
return 'exploring'
avg_time = sum(item.get('time_spent', 0) for item in browsing_history) / len(browsing_history)
if avg_time > 180: # 3+ minutes average
return 'learning'
elif avg_time > 60:
return 'evaluating'
else:
return 'browsing'
def enrich_profile_with_ai(self, profile: Dict, browsing_history: List[Dict]):
"""Use AI to enhance visitor profile."""
prompt = f"""
Analyze this visitor profile and browsing behavior:
PROFILE:
{json.dumps(profile, indent=2)}
BROWSING HISTORY:
{json.dumps(browsing_history[0:10], indent=2)}
Provide enhanced insights:
1. Refined experience level assessment
2. Primary goal/need right now
3. Likely objections or concerns
4. Content recommendations (what to show them)
5. Messaging approach (how to communicate)
6. Next best action for them
Return as JSON with recommendations.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.4,
response_format={"type": "json_object"}
)
ai_insights = json.loads(response.choices[0].message.content)
# Merge AI insights with profile
profile.update(ai_insights)
return profile
def personalize_content(
self,
base_content: Dict,
visitor_profile: Dict
):
"""Personalize content for specific visitor."""
print(f"🎨 Personalizing for: {visitor_profile['experience_level']}")
# Get personalization strategy
strategy = self.get_personalization_strategy(visitor_profile)
# Apply personalizations
personalized = {
'headline': self.personalize_headline(
base_content.get('headline', ''),
visitor_profile,
strategy
),
'intro': self.personalize_intro(
base_content.get('intro', ''),
visitor_profile,
strategy
),
'body': self.adapt_body_content(
base_content.get('body', ''),
visitor_profile,
strategy
),
'cta': self.personalize_cta(
base_content.get('cta', ''),
visitor_profile,
strategy
),
'recommendations': self.get_content_recommendations(
visitor_profile
)
}
print("✅ Content personalized")
return personalized
def get_personalization_strategy(self, profile: Dict):
"""Determine personalization strategy."""
experience = profile['experience_level']
stage = profile['stage']
intent = profile['intent']
strategies = {
'beginner': {
'tone': 'helpful_and_simple',
'complexity': 'basic',
'assumptions': 'explain_everything',
'examples': 'step_by_step',
'cta': 'educational_resource'
},
'intermediate': {
'tone': 'practical_and_actionable',
'complexity': 'moderate',
'assumptions': 'some_knowledge',
'examples': 'real_world_cases',
'cta': 'implementation_guide'
},
'advanced': {
'tone': 'technical_and_efficient',
'complexity': 'advanced',
'assumptions': 'knowledgeable',
'examples': 'optimization_tactics',
'cta': 'advanced_resource'
}
}
base_strategy = strategies[experience]
if stage == 'unaware':
base_strategy['focus'] = 'education'
base_strategy['cta_urgency'] = 'low'
elif stage == 'problem_aware':
base_strategy['focus'] = 'solution_preview'
base_strategy['cta_urgency'] = 'medium'
elif stage == 'most_aware':
base_strategy['focus'] = 'specific_outcomes'
base_strategy['cta_urgency'] = 'high'
return base_strategy
def personalize_headline(
self,
base_headline: str,
profile: Dict,
strategy: Dict
):
"""Personalize headline for visitor."""
prompt = f"""
Personalize this headline:
BASE HEADLINE:
{base_headline}
VISITOR:
- Level: {profile['experience_level']}
- Stage: {profile['stage']}
- Goal: {profile['intent']}
- Interests: {', '.join(profile.get('interests', []))}
STRATEGY:
{json.dumps(strategy, indent=2)}
Create 3 headlines that match their experience level, stage, and intent.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
response_format={"type": "json_object"}
)
result = json.loads(response.choices[0].message.content)
headlines = result.get('headlines', [base_headline])
return headlines[0] if headlines else base_headline
def personalize_intro(self, base_intro: str, profile: Dict, strategy: Dict):
"""Personalize introduction."""
prompt = f"""
Adapt this intro for the visitor:
BASE INTRO:
{base_intro}
VISITOR:
- Level: {profile['experience_level']}
- Stage: {profile['stage']}
- Goal: {profile['intent']}
STRATEGY: {strategy.get('tone', 'helpful')}
Adapt to match their experience and goal.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.6
)
return response.choices[0].message.content.strip()
def adapt_body_content(self, base_body: str, profile: Dict, strategy: Dict):
"""Adapt main content body."""
complexity = strategy.get('complexity', 'moderate')
if profile['experience_level'] == 'beginner':
adaptation = 'Add more explanations, simpler language, step-by-step breakdown'
elif profile['experience_level'] == 'advanced':
adaptation = 'Remove basic explanations, add advanced tips, be more concise'
else:
adaptation = 'Balance detail and brevity, practical examples'
prompt = f"""
Adapt this content:
{base_body[0:2000]}
For: {profile['experience_level']} level
Adaptation: {adaptation}
Maintain core information but adjust language complexity, detail level, and examples.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.5
)
return response.choices[0].message.content.strip()
def personalize_cta(self, base_cta: str, profile: Dict, strategy: Dict):
"""Personalize call-to-action."""
stage = profile.get('stage', 'solution_aware')
cta_strategies = {
'unaware': 'Learn more',
'problem_aware': 'Get solution guide',
'solution_aware': 'See how it works',
'product_aware': 'Try it / Demo',
'most_aware': 'Get started now'
}
recommended_cta = cta_strategies.get(stage, base_cta)
prompt = f"""
Create personalized CTA:
BASE: {base_cta}
VISITOR: {profile['experience_level']} | {stage}
RECOMMENDED: {recommended_cta}
Make it match their readiness level and feel natural.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
response_format={"type": "json_object"}
)
result = json.loads(response.choices[0].message.content)
ctas = result.get('ctas', [base_cta])
return ctas[0] if ctas else base_cta
def get_content_recommendations(self, profile: Dict):
"""Recommend next content for this visitor."""
interests = profile['interests']
experience = profile['experience_level']
prompt = f"""
Recommend 5 pieces of content:
- Experience: {experience}
- Interests: {', '.join(interests)}
- Goal: {profile['intent']}
Match their interests and experience level.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.6,
response_format={"type": "json_object"}
)
result = json.loads(response.choices[0].message.content)
return result.get('recommendations', [])
def create_dynamic_landing_page(self, visitor_profile: Dict):
"""Create personalized landing page."""
print(f"📄 Creating personalized landing page...")
prompt = f"""
Create a personalized landing page for this visitor:
VISITOR PROFILE:
{json.dumps(visitor_profile, indent=2)}
Include headline, intro, hooks, value props, CTAs.
"""
response = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
response_format={"type": "json_object"}
)
landing_page = json.loads(response.choices[0].message.content)
print("✅ Personalized landing page created")
return landing_page
# Usage
engine = ContentPersonalizationEngine()
visitor_data = {
'id': 'user_12345',
'first_visit': False
}
browsing_history = [
{'title': 'Getting Started with AI Content', 'tags': ['AI', 'beginner'], 'time_spent': 245},
{'title': 'AI Writing Tools Compared', 'tags': ['AI', 'tools'], 'time_spent': 180},
{'title': 'Automating Your Content', 'tags': ['automation', 'AI'], 'time_spent': 320}
]
profile = engine.analyze_visitor(
visitor_data=visitor_data,
browsing_history=browsing_history,
referral_source='google.com'
)
base_content = {
'headline': 'AI Content Creation Guide',
'intro': 'Creating content is time-consuming. Learn how AI can help.',
'body': 'AI tools can automate many aspects of content creation...',
'cta': 'Download our guide'
}
personalized = engine.personalize_content(
base_content=base_content,
visitor_profile=profile
)
print("\n📝 PERSONALIZED CONTENT:")
print(f"Headline: {personalized['headline']}")
print(f"CTA: {personalized['cta']}")
print("\n💡 RECOMMENDED CONTENT:")
for i, rec in enumerate(personalized['recommendations'][0:3], 1):
print(f"{i}. {rec.get('title', 'N/A')}")
print(f" Why: {rec.get('why', 'N/A')}\n")
landing_page = engine.create_dynamic_landing_page(profile)
print("✅ Personalization complete!")
Personalization Strategies
How to adapt content:
- By experience level
- Beginners: Simple language, more explanation
- Intermediates: Practical focus, real examples
- Advanced: Technical depth, efficient language
- By journey stage:
- Unaware: Educational content, problem identification
- Problem aware: Solution introduction, success stories
- Most aware: Specific outcomes, comparison details
What to Personalize
Key elements:
- Headlines
- Content depth
- CTAs
- Recommendations
Implementation Options
Ways to personalize:
- Dynamic content
- Email segmentation
- Landing page variants
- Content recommendations
Tools & Costs
Personalization stack:
- OpenAI API: Free-$50/month - AI personalization
- Analytics platform: Free-$50/month - Visitor tracking
- Personalization software: $50-200/month - Dynamic content
- Email platform: $15-100/month - Segmentation
Total: $85-370/month
ROI:
- Conversion rate: 3.7× better (3% → 11%)
- Revenue: +280%
- Bounce rate: -40%
- Time on page: 2.8× longer
- Customer satisfaction: Higher
Getting Started
Day 1: Track Visitor Data Set up analytics, track browsing behavior, segment by experience.
Day 2: Create Variations Write beginner version, advanced version, different CTAs.
Day 3: Implement Set up dynamic content, add personalization logic, test thoroughly.
Day 4-7: Optimize Monitor performance, A/B test variants, refine targeting.
Call To Action
Check out my real AI tools at axon.nepa-ai.com
