All About CTV
HomeOur TeamContact

Lead Scoring Algorithm with GA4 Data

By Mariusz Przydatek
Published in Code
March 18, 2025
1 min read
Lead Scoring Algorithm with GA4 Data

Table Of Contents

01
Simple algorithm that uses Google Analytics data
02
Explanation
03
Integrating with Google Analytics
04
Using Google Tag Manager (GTM)
05
Best Practices

Simple algorithm that uses Google Analytics data

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 metric
weights = {
'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 pages
normalized_session_duration = min(session_duration / 300, 1) # Cap at 5 minutes
normalized_bounce_rate = max(1 - bounce_rate / 100, 0) # Invert bounce rate
normalized_goal_completions = min(goal_completions / 5, 1) # Cap at 5 goals
# Calculate lead score
lead_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-100
return lead_score
# Example usage
example_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)

Explanation

  1. Normalization: The code normalizes each metric to ensure that all values are on the same scale. For example, page_views are capped at 10, and session_duration is capped at 5 minutes. This prevents any single metric from dominating the score.
  2. Weight Assignment: Weights are assigned to each metric based on their perceived importance. For instance, goal_completions have a higher weight because they indicate strong engagement.
  3. Lead Score Calculation: The lead score is calculated as a weighted sum of the normalized metrics. The score is then scaled to a range of 0-100 for easier interpretation.

Integrating with Google Analytics

To integrate this algorithm with Google Analytics, you would need to:

  • Retrieve Data: Use the Google Analytics API to retrieve the necessary metrics (e.g., page views, session duration, bounce rate, goal completions) for each user.
  • Apply Algorithm: Apply the lead scoring algorithm to this data.
  • Store Scores: Store the calculated lead scores in a database or CRM for further analysis and sales qualification.

Using Google Tag Manager (GTM)

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.


Best Practices

  • Regularly Review and Adjust Weights: Ensure that the weights assigned to each metric align with your business goals and adjust them as needed.
  • Use Negative Scoring: Consider implementing negative scoring for behaviors that indicate low buying intent, such as unsubscribing from emails.
  • Monitor Conversion Rates: Track the conversion rates of leads with different scores to refine your scoring model over time.

Tags

#algorithms#code#ga4#lead-score

Share

Previous Article
Person-Based Viewership Data Challenges
Mariusz Przydatek

Mariusz Przydatek

Chief Editor

Table Of Contents

1
Simple algorithm that uses Google Analytics data
2
Explanation
3
Integrating with Google Analytics
4
Using Google Tag Manager (GTM)
5
Best Practices

Related Posts

Streamline LTV Calculation with GA4 and Monday.com CRM
March 20, 2025
2 min
All About CTV
© 2025, All Rights Reserved.

Quick Links

Advertise with usAbout UsContact Us

Social Media