10 minutes

How to Monitor Brand Mentions on Twitter

Set up real-time monitoring for your brand on Twitter. Get instant webhook alerts when someone mentions your brand or products.

1

Get your API key

Sign up at scrapebadger.com and grab your API key.

2

Create a Stream Monitor

Set up real-time monitoring for your brand's Twitter account(s).

curl -X POST 'https://scrapebadger.com/v1/twitter/stream/monitors' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Brand Monitor",
    "usernames": ["yourbrand", "your_ceo"],
    "webhook_url": "https://your-app.com/webhooks/twitter",
    "webhook_secret": "your_webhook_secret"
  }'
3

Set up keyword monitoring

Create Filter Rules to catch indirect mentions that don't @tag your account.

curl -X POST 'https://scrapebadger.com/v1/twitter/stream/filter-rules' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "tag": "Brand Keywords",
    "query": "\"your brand\" OR \"your product\" OR #yourbrand",
    "interval_seconds": 60,
    "webhook_url": "https://your-app.com/webhooks/keywords"
  }'
4

Handle webhook payloads

Process incoming tweet notifications in your application.

from flask import Flask, request
import hmac
import hashlib

app = Flask(__name__)
SECRET = "your_webhook_secret"

@app.route("/webhooks/twitter", methods=["POST"])
def handle_webhook():
    # Verify HMAC signature
    sig = request.headers.get("X-Webhook-Signature")
    expected = hmac.new(SECRET.encode(), request.data, hashlib.sha256).hexdigest()
    if sig != expected:
        return "Invalid signature", 401

    data = request.json
    tweet = data["tweet"]
    print(f"New mention from @{tweet['author']['username']}: {tweet['text']}")
    # Send to Slack, log to DB, trigger alert, etc.
    return "OK", 200
5

Monitor via WebSocket (alternative)

For real-time streaming without webhooks, connect via WebSocket.

import asyncio
import websockets
import json

async def monitor():
    uri = "wss://scrapebadger.com/v1/twitter/stream?api_key=YOUR_API_KEY"
    async with websockets.connect(uri) as ws:
        async for message in ws:
            tweet = json.loads(message)
            print(f"@{tweet['author']['username']}: {tweet['text']}")

asyncio.run(monitor())

Frequently Asked Questions

Webhooks are delivered within seconds of the tweet being posted. Typical latency is 1-5 seconds.

Yes. Create additional monitors and filter rules for competitor usernames and brand keywords.

ScrapeBadger retries failed webhook deliveries with exponential backoff. Missed deliveries are logged and can be retrieved from the logs endpoint.

Stream Monitors use volume-based pricing per monitored account per day. Check the pricing page for current rates.