Streamline LTV Calculation with GA4 and Monday.com CRM
March 20, 2025
2 min
Here is a Python code example for a lead scoring algorithm using data from Google Analytics. This algorithm assigns scores based on user behavior metrics such as page views, session duration, bounce rate, and goal completions.
def lead_scoring(page_views, session_duration, bounce_rate, goal_completions):"""Calculate lead score based on Google Analytics metrics.Parameters:- page_views (int): Number of pages viewed by the user.- session_duration (float): Duration of the session in seconds.- bounce_rate (float): Percentage of sessions where users left after viewing one page.- goal_completions (int): Number of goals completed by the user.Returns:- lead_score (float): Calculated lead score."""# Assign weights to each metricweights = {'page_views': 0.3,'session_duration': 0.4,'bounce_rate': -0.2,'goal_completions': 0.5}# Normalize metrics (example normalization)normalized_page_views = min(page_views / 10, 1) # Cap at 10 pagesnormalized_session_duration = min(session_duration / 300, 1) # Cap at 5 minutesnormalized_bounce_rate = max(1 - bounce_rate / 100, 0) # Invert bounce ratenormalized_goal_completions = min(goal_completions / 5, 1) # Cap at 5 goals# Calculate lead scorelead_score = (weights['page_views'] * normalized_page_views +weights['session_duration'] * normalized_session_duration +weights['bounce_rate'] * normalized_bounce_rate +weights['goal_completions'] * normalized_goal_completions) * 100 # Scale to 0-100return lead_score# Example usageexample_lead = {'page_views': 15,'session_duration': 450,'bounce_rate': 50,'goal_completions': 3}lead_score = lead_scoring(page_views=example_lead['page_views'],session_duration=example_lead['session_duration'],bounce_rate=example_lead['bounce_rate'],goal_completions=example_lead['goal_completions'])print("Lead Score:", lead_score)
page_views
are capped at 10, and session_duration
is capped at 5 minutes. This prevents any single metric from dominating the score.goal_completions
have a higher weight because they indicate strong engagement.To integrate this algorithm with Google Analytics, you would need to:
You can also use Google Tag Manager to capture these metrics and trigger events that update lead scores. GTM allows you to set up custom JavaScript variables and triggers to track specific user interactions and send data to Google Analytics or other platforms for lead scoring.
Quick Links
Legal Stuff