Integrating with Google Analytics
This guide will show you how to integrate Superline Agent Detection with Google Analytics 4 (GA4) to segment your data and metrics based on whether users are humans or AI agents.Why Separate Human and AI Traffic
Analytics data is most valuable when it accurately reflects how humans interact with your site. With the growing prevalence of AI agents browsing the web, your analytics may be skewed by non-human traffic, leading to:- Inaccurate conversion rates
- Misleading engagement metrics
- Skewed A/B test results
- Distorted user behavior analysis
Integration Steps
1
Install Superline Agent Detection
First, install the Superline Agent Detection library:or use a script tag:
2
Initialize Both Libraries
Make sure both GA4 and Superline Agent Detection are initialized early in your application lifecycle:
3
Detect AI Agents and Send to GA4
After allowing sufficient time for data collection (typically a few seconds), check if the current session is from an AI agent and send this information to GA4:
4
Create Custom Dimensions in GA4
In your Google Analytics 4 property:
- Go to Admin > Custom definitions > Create custom dimensions
- Create two custom dimensions:
- Name: “Is Agent”, Scope: “User”, User property: “is_agent”
- Name: “Agent Confidence”, Scope: “User”, User property: “agent_confidence”
5
Create Segments for Analysis
Create segments to analyze human vs. AI traffic separately:
- Go to any report in GA4
- Click the ”+” button in the segments section
- Create two segments:
- Human Users: Add condition where “Is Agent” equals “false”
- AI Agents: Add condition where “Is Agent” equals “true”
Comprehensive Implementation Example
Here’s a complete example that handles various scenarios:Advanced Analytics Options
Using Probability/Confidence
Using Probability/Confidence
Instead of a simple boolean, you can use the continuous confidence for more nuanced analysis:This allows you to create segments for “likely human,” “uncertain,” and “likely agent” categories.
A/B Testing Considerations
A/B Testing Considerations
When running A/B tests, you can:
- Exclude AI agents from tests entirely
- Stratify your analysis to compare human-only results
- Run tests specifically targeting differences in human vs. AI behavior
Real-time Notification
Real-time Notification
Set up real-time alerts for significant AI agent traffic:Then configure GA4 to alert you when these events occur at an unusual rate.
Analyzing the Data
Once integrated, you can use GA4’s reporting tools to gain insights such as:Conversion Rate Differences
Compare conversion rates between human users and AI agents to understand how bots might be skewing your metrics.
Navigation Patterns
Identify differences in page flow and navigation patterns between humans and AI agents.
Engagement Metrics
Compare session duration, pages per session, and bounce rates to understand how agent traffic differs from human traffic.
Feature Usage
Determine if AI agents interact with certain features of your site differently than humans.
Best Practices
- Delay Initial Collection: Allow at least 3-5 seconds of interaction before finalizing detection for better accuracy
- Review Confidence Distribution: Analyze the
agent_confidence
distribution in GA4 instead of relying solely onis_agent
- Review Regularly: Monitor the proportion of AI traffic over time to spot trends
- Create Comparative Reports: Set up reports that compare key metrics between human and AI segments
- Adjust Threshold Based on Needs: Depending on your tolerance for false positives vs. false negatives, adjust your reporting threshold based on the
agent_confidence
, or use thethreshold
init option.