Build a Click Fraud Detection Agent Workflow: Real-Time AI Bot Detection with LangGraph and Google Ads API [2026]
Build a click fraud detection agent workflow with LangGraph: real-time bot traffic detection, ad campaign monitoring, and automated fraud response using Google Ads API.
Elena Rostova
Principal Distributed Systems Architect
The Google Ads click fraud story from earlier this month revealed that 60 percent of app installs from a $220 ad campaign were from AI-powered bots. This workflow builds a LangGraph agent that detects, analyzes, and reports click fraud patterns in real time by combining ad platform data fingerprinting, behavioral analysis, and automated alerting.
The Click Fraud Detection Problem
Traditional click fraud detection operates after the fact: Google's systems analyze traffic patterns and issue refunds weeks later. By the time a refund arrives, the fraudulent ad spend has already been incurred, and the bot farm has moved to new targets.
An AI agent that monitors ad traffic in real time can detect fraud within hours rather than weeks, stopping campaigns before the budget is exhausted. The Google Ads Click Fraud analysis showed that the key signals are available from the first install batch -- you just need an agent watching for them.
The Workflow Architecture
The click fraud detection agent uses four LangGraph nodes running on a continuous monitoring cycle:
Node 1: Campaign Data Collector -- Queries the Google Ads API and the app store analytics API for campaign performance data. Collects install counts, cost per install, session duration, in-app event rates, and device fingerprint distributions.
Node 2: Anomaly Detector -- Compares current campaign metrics against historical baselines. Flags campaigns where the share of single-session installs exceeds 40 percent, where device fingerprints show suspicious uniformity, or where in-app event rates drop below 20 percent of the historical average.
Node 3: Fraud Classifier -- For each flagged campaign, runs a deeper analysis using device fingerprinting data, IP geolocation distributions, and session timing patterns. Classifies the suspicious traffic as bot farm, device farm, or AI-generated engagement based on the specific pattern detected.
Node 4: Campaign Controller -- If confirmed fraud exceeds a configurable threshold (default 30 percent of installs), the controller node pauses the campaign and generates a detailed fraud report. The report includes the estimated fraudulent spend, the specific detection signals, and evidence for Google's refund request process.
LangGraph Implementation
The workflow connects through a state graph with a fraud escalation path:
from langgraph.graph import StateGraph
from typing import TypedDict, List
class FraudDetectionState(TypedDict):
campaigns: List[dict]
anomaly_flags: List[dict]
confirmed_fraud: List[dict]
paused_campaigns: List[str]
workflow = StateGraph(FraudDetectionState)
workflow.add_node("collect", campaign_data_collector)
workflow.add_node("detect", anomaly_detector)
workflow.add_node("classify", fraud_classifier)
workflow.add_node("control", campaign_controller)
workflow.set_entry_point("collect")
workflow.add_edge("collect", "detect")
workflow.add_edge("detect", "classify")
workflow.add_edge("classify", "control")
workflow.compile()
Integration with Ad Platforms
The collector node integrates with Google Ads API and the Apple App Store or Google Play Console APIs:
def campaign_data_collector(state: FraudDetectionState) -> FraudDetectionState:
ads_client = GoogleAdsClient(CONFIG["ads_credentials"])
campaigns = ads_client.get_campaigns(status="ENABLED")
for campaign in campaigns:
metrics = ads_client.get_campaign_metrics(campaign["id"], days=1)
store_metrics = store_client.get_install_metrics(campaign["app_id"])
campaign.update({
"installs": metrics.get("installs", 0),
"cost": metrics.get("cost_micros", 0) / 1e6,
"single_session_rate": store_metrics.get("single_session_rate", 0),
"in_app_event_rate": store_metrics.get("in_app_event_rate", 0),
})
return {**state, "campaigns": campaigns}
The BankMCP Server follows a similar pattern of wrapping external APIs as MCP tools for automated financial data collection. The click fraud detector extends this approach to ad platform data.
Detection Signals
The anomaly detector and fraud classifier examine six key signals:
-
Single-session rate: Bot installs rarely generate more than one session. A single-session rate above 40 percent indicates bot traffic.
-
Device fingerprint entropy: Bot farms use a limited pool of device IDs. If the same device fingerprint appears across multiple installs with different advertising IDs, the traffic is fraudulent.
-
Session duration distribution: Human sessions show a natural distribution with a long tail. Bot sessions cluster tightly around a fixed duration (the amount of time the bot spends simulating engagement).
-
In-app event funnel: Real users progress through the in-app event funnel at predictable rates. Bot traffic shows event rates that are either zero or uniformly distributed across all event types.
-
Geographic concentration: Bot farms operate from specific geographic regions. If 80 percent of installs come from a single city where you have no marketing focus, the traffic is suspect.
-
Hourly distribution: Human installs follow the day-night cycle of the target market. Bot installs are uniformly distributed across all hours, or concentrated during off-peak hours when detection systems are less active.
Automated Response
When confirmed fraud exceeds the threshold, the campaign controller takes action:
def campaign_controller(state: FraudDetectionState) -> FraudDetectionState:
paused = []
for fraud in state["confirmed_fraud"]:
if fraud["fraud_rate"] > CONFIG["fraud_threshold"]:
ads_client.pause_campaign(fraud["campaign_id"])
generate_fraud_report(fraud)
paused.append(fraud["campaign_id"])
return {**state, "paused_campaigns": paused}
The generated report includes all detection signals, screenshots of anomalous patterns, and a formatted refund request. The MCP Analytics Server provides the historical baseline data that the anomaly detector uses for comparison.
Production Deployment
Deploy the workflow as a scheduled LangGraph agent running every 6 hours. Each monitoring cycle takes approximately 1 minute per active campaign. For a portfolio of 50 campaigns, the total cycle time is under an hour.
The agent can also run in a continuous monitoring mode for high-spend campaigns, checking for fraud signals every 15 minutes. In continuous mode, a campaign with confirmed fraud can be paused within 30 minutes of the first fraudulent install, saving thousands in wasted ad spend.
This workflow turns click fraud detection from a retrospective refund process into a real-time prevention system. By the time a bot farm has generated 100 installs, the agent has already analyzed the patterns, classified the traffic, and paused the campaign.
The Device Fingerprinting Challenge
One of the hardest aspects of click fraud detection is that bot farms adapt to fingerprinting. When a detection system starts flagging a specific device ID pattern, the bot farm rotates its device pool. When session timing analysis catches uniform distributions, the bots introduce random timing variation.
The fraud classifier node addresses this through multi-dimensional analysis. Instead of relying on any single signal, it aggregates evidence across all six detection dimensions. A campaign must score above the fraud threshold on at least three dimensions to trigger the pause action. This reduces false positives while maintaining high detection accuracy.
The Geiger MCP Scanner faces a similar challenge with MCP server behavior detection -- a single anomalous signal could be a false positive, but multiple correlated signals across different dimensions reliably indicate malicious activity.
False Positive Prevention
False positives in click fraud detection are expensive. Pausing a legitimate campaign costs money and disrupts user acquisition. The agent includes a three-stage verification pipeline:
Stage 1: Statistical flagging -- The anomaly detector flags campaigns exceeding any single detection threshold. This is high-sensitivity, low-specificity. It catches everything but generates false positives.
Stage 2: Cross-signal verification -- The fraud classifier checks whether flagged campaigns show anomalies across multiple independent signals. A campaign with high single-session rate and suspicious device fingerprint entropy is more likely fraudulent than one with a high single-session rate alone.
Stage 3: Manual review queue -- Campaigns that trigger the fraud threshold but have ambiguous evidence are placed in a manual review queue rather than paused automatically. A human reviews the evidence and decides whether to pause.
This multi-stage approach ensures that the automated pause action is only triggered for campaigns with clear, multi-dimensional evidence of fraud. The OKF Agent Architecture uses a similar confidence-scored approach for memory retrieval, only surfacing facts that exceed a configurable confidence threshold.
Scaling to Multiple Ad Platforms
The workflow supports monitoring across multiple ad platforms simultaneously. The collector node can query Google Ads, Meta Ads, TikTok Ads, and Apple Search Ads through their respective APIs. Each platform has different fraud signals and detection thresholds, which the classifier node handles through platform-specific analysis modules.
For organizations spending more than $100,000 per month on advertising, the ROI of this workflow is immediate. At 60 percent fraud rates on unprotected campaigns, the agent saves 60 percent of ad spend on the campaigns it detects and pauses. Even with a 10 percent false positive rate, the net savings are substantial.
The workflow closes the gap between fraud occurrence and fraud detection from weeks to hours, directly impacting the bottom line for any organization that depends on paid user acquisition. By @deepakb.
Enjoyed this breakdown? Get our morning dispatch in your inbox.
Curated breakdowns of frontier model architectures and compute markets delivered every weekday. Zero fluff.
Elena Rostova
Principal Distributed Systems Architect
Elena Rostova leads coverage on high-concurrency multi-agent frameworks, LangGraph orchestration, event-driven pipelines, and self-healing systems.
Build a Math Research Agent Workflow: AI-Assisted Theorem Proving with Attribution and Formal Verification [2026]
Next Story →Inside iLands' AI Agent Email Spam Empire: How LLMs Generate Personalized Spam at Scale and Why Traditional Filters Fail [2026]
Related Intelligence Analysis
The Step-by-Step Guide to Automating Meeting Tasks with Whisper
You're spending 45 minutes after every client meeting typing up notes and manually assigning tasks in Jira. This guide shows you how to wire OpenAI Whisper and Claude to automatically convert meeting recordings into assi...
Lovable AI UI-to-Code Pipeline: 2026 Tutorial
Lovable AI UI-to-code automation pipeline uses Lovable AI on Lovable Cloud to convert visual UI designs and natural language specs into production-grade web applications. UI/UX designers and frontend developers bridging...
Claude Code's New Browser: 5 Workflows That Save Hours Daily
Claude Code's built-in browser is a sandboxed tabbed browser inside the Claude Code desktop app (Week 28, July 2026) accessible via Cmd+Shift+B (macOS) or Ctrl+Shift+B (Windows). It lets Claude open websites, read docume...