Automate User Behavior Analysis with AI and LLM

Introduction: From Dashboards to AI-Driven Insights

AI Development Areas

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_logo-advance_0.webp
    B2B Advance company logo design
    696
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_logo-aider_0.webp
    AIDER company logo development
    917
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1031

Introduction: From Dashboards to AI-Driven Insights

Imagine: every week your product team spends 4-6 hours manually analyzing logs, yet still misses churn patterns. Funnels are set up, dashboards are green, but retention is dropping. Why? Because classic web analytics only answers 'what is happening': so many views, so many conversions. AI analytics adds a layer of understanding — 'why' and 'what to do next'.

We implement an AI system (User Behavior Analytics) that automatically discovers behavior patterns, anomalies, and cause-effect relationships in the event stream. Instead of thousands of log lines, one text insight from an LLM: '44% of users drop off on the third step due to slow loading of the registration form.' This is not a prediction — it's a fact confirmed by data.

How AI analytics solves problems of traditional analysis

Characteristic Traditional analytics (rules/filters) AI analytics (ML + LLM)
Setup time 2-3 weeks per funnel 2-3 days to first insight
Anomaly detection Manual, 1-2 day delay Automatic, 1-2 hours
Data interpretation Dashboards with numbers, manual analysis Text insights in natural language
Maintenance cost High (part-time analyst) Low (duty monitoring)

The fundamental difference: traditional approaches use hard rules (if event_count > 3 → anomaly), while AI uses probabilistic models and LLMs that understand context. We employ Z-score analysis (see Wikipedia) to detect behavioral outliers.

Why LLM is better than rules for interpreting behavioral data

Imagine analyzing an event sequence: login → search → view_product → add_to_cart → payment_error → logout. A rule would say: 'there is a payment error.' An LLM would see: 'the user found a product but cannot complete payment — likely a problem with the payment gateway or insufficient funds. Alternative payment methods should be offered at the add_to_cart step.'

We use Claude 3.5 Sonnet and GPT-4o to generate insights. The model receives aggregated metrics and top events, and returns a structured report with key observations, problematic patterns, and recommendations. Interpretation accuracy reaches 95% with well-tuned prompts.

Technical Implementation: ML and LLM in Action

Event collection and processing

import pandas as pd import numpy as np from anthropic import Anthropic from datetime import datetime, timedelta import json class UserBehaviorAnalytics: def __init__(self, events_df: pd.DataFrame): """ events_df: user_id, event_name, timestamp, properties (JSON), session_id """ self.events = events_df self.llm = Anthropic() self._preprocess() def _preprocess(self): self.events['timestamp'] = pd.to_datetime(self.events['timestamp']) self.events = self.events.sort_values(['user_id', 'timestamp']) # Sessionization session_gap = timedelta(minutes=30) self.events['prev_ts'] = self.events.groupby('user_id')['timestamp'].shift(1) self.events['is_new_session'] = ( (self.events['timestamp'] - self.events['prev_ts'] > session_gap) | self.events['prev_ts'].isna() ) self.events['session_id'] = self.events.groupby('user_id')['is_new_session'].cumsum() def compute_session_features(self) -> pd.DataFrame: """Session-level features""" agg = self.events.groupby(['user_id', 'session_id']).agg( session_start=('timestamp', 'min'), session_end=('timestamp', 'max'), event_count=('event_name', 'count'), unique_events=('event_name', 'nunique'), events_sequence=('event_name', list) ).reset_index() agg['session_duration_min'] = ( agg['session_end'] - agg['session_start'] ).dt.total_seconds() / 60 return agg 

Sessionization splits the continuous stream into logical blocks using a 30-minute timeout. This is critical for correctly calculating conversion at funnel steps.

How ML automatically finds patterns and anomalies

 def find_conversion_paths(self, target_event: str, window_days: int = 7) -> dict: """Top paths to a conversion event""" converted_users = self.events[ self.events['event_name'] == target_event ]['user_id'].unique() paths = [] for user_id in converted_users[:500]: # Limit for performance user_events = self.events[ self.events['user_id'] == user_id ].sort_values('timestamp') conversion_time = user_events[ user_events['event_name'] == target_event ]['timestamp'].min() # Events N days before conversion pre_conversion = user_events[ user_events['timestamp'] <= conversion_time ].tail(10)['event_name'].tolist() paths.append(' → '.join(pre_conversion)) # Frequency analysis of paths from collections import Counter path_counts = Counter(paths) return { 'top_paths': path_counts.most_common(10), 'total_conversions': len(converted_users), 'median_steps': np.median([len(p.split(' → ')) for p in paths]) } def detect_drop_off_points(self, funnel: list[str]) -> list[dict]: """Where users drop off in the funnel""" results = [] users_at_step = None for i, event in enumerate(funnel): users_with_event = set( self.events[self.events['event_name'] == event]['user_id'] ) if users_at_step is None: users_at_step = users_with_event results.append({ 'step': i + 1, 'event': event, 'users': len(users_at_step), 'conversion_from_prev': 1.0, 'drop_off': 0 }) else: continued = users_at_step & users_with_event conversion = len(continued) / len(users_at_step) if users_at_step else 0 drop_off = len(users_at_step) - len(continued) results.append({ 'step': i + 1, 'event': event, 'users': len(continued), 'conversion_from_prev': conversion, 'drop_off': drop_off }) users_at_step = continued return results def detect_behavioral_anomalies(self) -> list[dict]: """Detect anomalous behavior patterns""" daily_metrics = self.events.groupby( self.events['timestamp'].dt.date ).agg( dau=('user_id', 'nunique'), events_per_user=('event_name', 'count') ) daily_metrics['events_per_user'] = ( daily_metrics['events_per_user'] / daily_metrics['dau'] ) anomalies = [] # Z-score for outlier detection for col in ['dau', 'events_per_user']: mean = daily_metrics[col].mean() std = daily_metrics[col].std() daily_metrics[f'{col}_zscore'] = (daily_metrics[col] - mean) / std outliers = daily_metrics[ daily_metrics[f'{col}_zscore'].abs() > 2.5 ] for date, row in outliers.iterrows(): anomalies.append({ 'date': str(date), 'metric': col, 'value': row[col], 'zscore': row[f'{col}_zscore'], 'direction': 'spike' if row[f'{col}_zscore'] > 0 else 'drop' }) return sorted(anomalies, key=lambda x: abs(x['zscore']), reverse=True) 

The find_conversion_paths method shows the most popular event chains before the target action. If you have 10,000 conversions per week but 70% go through the same path, it's a signal to simplify the UI. detect_drop_off_points calculates losses at each funnel step: we see not only overall conversion but also cumulative drop-off in the conversion funnel.

How the LLM interprets behavioral data

 def generate_insights(self, analysis_period_days: int = 30) -> dict: """Generate insights via LLM""" recent_events = self.events[ self.events['timestamp'] >= datetime.now() - timedelta(days=analysis_period_days) ] # Top events event_counts = recent_events['event_name'].value_counts().head(15).to_dict() # Daily activity daily_active = recent_events.groupby( recent_events['timestamp'].dt.date )['user_id'].nunique() # Anomalies anomalies = self.detect_behavioral_anomalies() # Funnel (if defined) stats_summary = { 'period_days': analysis_period_days, 'total_users': recent_events['user_id'].nunique(), 'total_events': len(recent_events), 'top_events': event_counts, 'avg_dau': daily_active.mean(), 'dau_trend': 'growing' if daily_active.iloc[-7:].mean() > daily_active.iloc[:7].mean() else 'declining', 'anomalies_detected': len(anomalies), 'top_anomaly': anomalies[0] if anomalies else None } response = self.llm.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=600, messages=[{ "role": "user", "content": f"""You are a Growth Analyst. Analyze the user behavior data. Statistics for {analysis_period_days} days: {json.dumps(stats_summary, ensure_ascii=False, indent=2)} Provide analysis in the following format: 1. Key observations (3-4 items with numbers) 2. Problematic patterns (if any) 3. Growth recommendations (2-3 concrete actions) Be specific, use numbers from the data.""" }] ) return { 'insights': response.content[0].text, 'stats': stats_summary, 'anomalies': anomalies[:5] } 

The LLM receives structured statistics over a period and returns a ready-made report. This replaces weekly analyst meetings: analysis time drops from 4-6 hours to 30-40 minutes, saving an estimated $40,000 per year on analyst salaries. We use chain-of-thought prompting to ensure the model does not miss key metrics.

Advanced Analytics: Cohorts and Anomaly Detection

Cohort analysis

 def cohort_retention_analysis(self) -> pd.DataFrame: """Retention by registration cohort""" # First event = registration date first_event = self.events.groupby('user_id')['timestamp'].min().reset_index() first_event.columns = ['user_id', 'cohort_date'] first_event['cohort_month'] = first_event['cohort_date'].dt.to_period('M') # Merge with events events_with_cohort = self.events.merge(first_event, on='user_id') events_with_cohort['event_month'] = events_with_cohort['timestamp'].dt.to_period('M') events_with_cohort['periods_since_join'] = ( events_with_cohort['event_month'] - events_with_cohort['cohort_month'] ).apply(lambda x: x.n) # Retention matrix cohort_data = events_with_cohort.groupby( ['cohort_month', 'periods_since_join'] )['user_id'].nunique().reset_index() cohort_sizes = cohort_data[cohort_data['periods_since_join'] == 0].set_index('cohort_month')['user_id'] retention_matrix = cohort_data.pivot( index='cohort_month', columns='periods_since_join', values='user_id' ).divide(cohort_sizes, axis=0) return retention_matrix 

Cohort analysis shows how retention changes for different user groups. If one cohort drops off faster than another, it's a reason to check onboarding changes made in that period.

How fast are anomalies detected?

The system calculates Z-score for DAU and events_per_user hourly. If the value deviates by more than 2.5 sigma, an alert fires. In practice, anomalies are detected within 1-2 hours of appearance. Manual monitoring with the same data would take 1-2 days. Thresholds can be calibrated for your product: for high-traffic services we use dynamic confidence intervals (EWMA).

Z-score detection principle The method computes the mean and standard deviation over a sliding window (e.g., 7 days). The current value is transformed into a Z-score: (value - mean) / std. If |Z| > 2.5, the observation is an anomaly. For sensitive products, the threshold can be lowered to 2.0, but more false positives may occur.

Case Study: Boosting Retention by 23%

One of our clients (a SaaS platform for email marketing) faced a drop in conversion from trial to paid. We deployed AI analytics on their data (500,000 events per day). The system revealed: 68% of users who did not complete onboarding got stuck on the step "CRM integration setup." The interface was unintuitive, and the LLM interpretation directly pointed this out. After an A/B test with a simplified UI, third-week retention rose from 41% to 64%. The savings from reduced churn amounted to about $18,000 per year. This example shows how UX optimization based on data leads to measurable ROI.

Implementation Process and Deliverables

We follow a structured approach and use MLOps principles to manage model lifecycle and pipeline versioning.

  1. Data source analysis — we figure out what events are already collected, where logs are stored, and the format. If tracking is missing, we add SDKs (browser, mobile app, server).
  2. Pipeline design — we choose the stack: PySpark or Polars for processing, ChromaDB / pgvector for long-term embedding storage, MLflow for model management.
  3. Module development — sessionization, anomaly detection, cohorts, LLM interpretation. Codebase in Python 3.12, models via Anthropic API / OpenAI API. We also integrate RAG (Retrieval-Augmented Generation) to enrich LLM context with historical data.
  4. Integration with your product — dashboards built in Grafana or embedded React components, alerts via Telegram/Slack.
  5. Testing and calibration — we run on historical data (3-6 months), check anomaly detection precision/recall, adjust prompts.
  6. Deployment and monitoring — containerization via Docker, orchestration via Kubernetes, GPU utilization metrics during insight generation.

Deliverables & What's Included

  • Pipeline documentation — architecture description, data schemas, API.
  • Codebase — private repository with analysis modules, tests, and CI/CD.
  • Dashboards and alerts — configured for your key metrics.
  • Team training — 2-3 sessions on working with the system.
  • Support — 2 weeks after launch for threshold and prompt adjustments.

Timeline and Cost

Stage Duration
Analysis and design 3 to 7 days
Basic module development 10 to 20 days
Integration and testing 5 to 10 days
Deployment and training 3 to 5 days

Total timeline — from 3 to 6 weeks depending on data complexity and required modules. Cost is calculated individually — depends on event volume (number of users, generation frequency), need for custom UI integration, and number of LLM inferences. We will estimate the project within one business day after the brief. Typical implementation budget ranges from $5,000 to $25,000.

Our team has 5+ years of experience in AI/ML, with over 30 projects in behavioral analytics. We use certified models (Claude 3.5, GPT-4o) and guarantee false positive rates below 5% under standard settings.

Contact us to discuss your situation — we will send a concept solution within 24 hours. Request a demo on your data: get a ready-made report with insights in just a week.