Skip to main content
Lesson 4 of 12 · Grok for Marketing & Competitive Intelligence

Thematic Alerts and Automated Monitoring

Lesson 4 of 12 Updated July 30, 2026 Intermediate
On this page
  1. From ad hoc monitoring to continuous monitoring
  2. Define your monitoring areas
  3. Architecting an alert system
  4. Configuring concrete alerts
  5. Managing notifications and routing
  6. Optimizing your monitoring costs
  7. Hands-on: monitoring dashboard
  8. Key takeaways

From ad hoc monitoring to continuous monitoring

Previous lessons showed you how to query X on an ad hoc basis. But the real power of marketing monitoring lies in automation: a system that runs continuously, filters out noise, and alerts you only when a relevant signal appears.

This lesson teaches you to build a complete thematic alert system, from defining criteria to notification.

Define your monitoring areas

An effective alert system starts with a precise map of your needs. Organize your alerts into four areas:

Area 1: Brand and reputation

Anything mentioning your brand, products, or executives, directly or indirectly.

Area 2: Competition

Moves by your direct and indirect competitors (covered in Lesson 2).

Area 3: Industry and regulation

Market developments, new regulations, technological shifts.

Area 4: Opportunities

Unmet demands, consumer frustrations, informal RFPs.

Architecting an alert system

Here is the architecture of an automated monitoring system based on X Search:

import json
from datetime import datetime, timedelta

class VeilleMarketing:
    def __init__(self, client):
        self.client = client
        self.alertes = []

    def definir_alerte(self, nom, prompt, handles=None,
                       frequence_heures=6, seuil_urgence="moyen"):
        self.alertes.append({
            "nom": nom,
            "prompt": prompt,
            "handles": handles,
            "frequence_heures": frequence_heures,
            "seuil_urgence": seuil_urgence,
            "dernier_scan": None
        })

    def executer_scan(self, alerte):
        tools_config = {"type": "x_search"}
        if alerte["handles"]:
            tools_config["allowed_x_handles"] = alerte["handles"]

        # Time window since last scan
        now = datetime.now()
        depuis = alerte["dernier_scan"] or (
            now - timedelta(hours=alerte["frequence_heures"])
        )

        tools_config["from_date"] = depuis.strftime("%Y-%m-%d")
        tools_config["to_date"] = now.strftime("%Y-%m-%d")

        response = self.client.responses.create(
            model="grok-4.20-0309-reasoning",
            input=f"""{alerte['prompt']}

            Evaluate the urgency of each detected signal:
            - CRITICAL: requires immediate action
            - IMPORTANT: handle within the day
            - INFORMATIVE: note for the weekly report

            If no relevant signal, simply reply 'NONE'.""",
            tools=[tools_config]
        )

        alerte["dernier_scan"] = now
        return response.output_text

Configuring concrete alerts

Here are examples of alerts adapted to different marketing contexts:

Reputation alert

veille = VeilleMarketing(client)

veille.definir_alerte(
    nom="Brand reputation",
    prompt="""Search for any mention of [your brand]
    on X. Identify complaints, criticism, or issues
    reported by users. Classify by severity.""",
    frequence_heures=4,
    seuil_urgence="critique"
)

Competitor launch alert

veille.definir_alerte(
    nom="Competitor launches",
    prompt="""Detect any sign of product launch
    or major campaign: teasers, announcements, pre-registration
    pages, changes to bio or profile photo.""",
    handles=["concurrent_a", "concurrent_b", "concurrent_c"],
    frequence_heures=12,
    seuil_urgence="important"
)

Industry opportunity alert

veille.definir_alerte(
    nom="Industry opportunities",
    prompt="""Identify unmet demands,
    frustrations, or requests for recommendations in
    the [your industry] sector. Focus on posts that
    express a concrete need our offer addresses.""",
    frequence_heures=8,
    seuil_urgence="moyen"
)

Managing notifications and routing

Your alert results must reach the right people at the right time. Structure your notification system based on urgency level:

def router_alerte(nom_alerte, resultat, seuil):
    if resultat.strip() == "NONE":
        return  # No notification

    if seuil == "critique":
        # Immediate notification (Slack, SMS, email)
        envoyer_notification_urgente(nom_alerte, resultat)
    elif seuil == "important":
        # Add to daily digest
        ajouter_au_digest(nom_alerte, resultat)
    else:
        # Archive for weekly report
        archiver_signal(nom_alerte, resultat)

Notification best practices

  • Do not over-notify: too many irrelevant alerts leads to ignoring them all
  • Provide context: each alert must explain why it triggered
  • Prioritize: the system should sort, not the recipient
  • Keep history: log all alerts to identify patterns

Optimizing your monitoring costs

At $5 per 1,000 X Search calls, active monitoring can generate significant costs. Here is how to control them:

Budget calculation

Nombre d'alertes × scans/jour × 30 jours = appels mensuels

Exemple :
- 5 alertes × 4 scans/jour × 30 = 600 appels/mois
- Coût : 600 / 1000 × 5 $ = 3 $/mois

Optimization strategies

You control the cost of automated monitoring first by grouping: a single query covering ten handles costs one invocation where ten separate queries cost ten, for the same information. Scan frequency is the second lever, and it has no reason to be constant—tighten it during key events (competitor launch, industry crisis) and loosen it during quiet periods: hourly monitoring on a Sunday in August burns budget for nothing. Prompt-side filtering then refines the signal: asking Grok to surface only items above a relevance threshold avoids processing—and storing—noise. Finally, a simple cache closes the loop: if the last scan is less than a few minutes old, serve its result instead of relaunching the query, especially when multiple users or dashboards consume the same monitoring.

Hands-on: monitoring dashboard

Combine all your monitoring areas into an orchestrator script:

def cycle_veille_complet(veille):
    resultats = {}
    for alerte in veille.alertes:
        now = datetime.now()
        dernier = alerte["dernier_scan"]

        # Check if scan is due
        if dernier and (now - dernier).total_seconds() < \
           alerte["frequence_heures"] * 3600:
            continue

        resultat = veille.executer_scan(alerte)
        resultats[alerte["nom"]] = resultat
        router_alerte(alerte["nom"], resultat, alerte["seuil_urgence"])

    return resultats

Pricing as of August 5, 2026 — prices change regularly: before any budget calculation, check the current schedule on the official xAI models and pricing page.

Key takeaways

  • Structure your monitoring into four areas: reputation, competition, industry, and opportunities
  • Each alert must have a frequency and urgency threshold adapted to its purpose
  • Route notifications to the right people based on urgency
  • At $5/1,000 calls, complete marketing monitoring costs a few dollars per month
  • Group handles and adjust frequency to optimize costs