Brand monitoring on social media shouldn't require expensive enterprise tools or complex API integrations. Yet most solutions today demand both, leaving many teams to manually search platforms or go without crucial mention tracking. If you’re looking for a home grown solution that can be modified for your business workflows, read on to learn how to build a simple Anchor Browser-powered solution. By the end, you’ll be able to automatically monitor X (also known as Twitter), save new posts in a Google Sheet, and send posts downstream to any tool of your choice.
What You'll Build
A Ruby script that:
- Searches X for specific keywords using Anchor Browser's AI agents
- Extracts post data (URL, author, content) from search results
- Saves new posts to a Google Sheet with post de-duplication
- Sends webhook notifications for downstream automation (Slack, email, etc.)
Key Features
AI-powered monitoring
Anchor Browser's agentic browsers handle complex Twitter authentication and data extraction without brittle selectors.
Smart Duplicate Prevention
Checks all existing post IDs in the spreadsheet, not just the last processed post.
Webhook Integration
Enables downstream automation through HTTP requests to services like Slack, Discord, Zapier, IFTTT, Pipedream, or custom endpoints.
Modifiable Workflows
Built as readable Ruby classes that you can easily adapt for different keywords, platforms, or data destinations.
Getting Started
Prerequisites
- Ruby 2.7+ installed
- Anchor Browser account and API key
- Google Cloud account with Sheets API access
- X (Twitter) account for authenticating an agentic browser profile
Clone and Setup
Clone the repository and install dependencies:
git clone https://github.com/jmarbach/x-mention-bot.git
cd x-mention-bot
bundle installHow it Works
- Anchor Browser Remote Browser Session
Anchor Browser handles the complex parts, such as authentication, navigation, and data extraction through AI agents:
class AnchorClient
def perform_web_task(task:, url: nil)
payload = {
prompt: task,
headless: true,
timeout: 120,
profile_name: ENV['ANCHOR_PROFILE_NAME']
}
response = self.class.post('/v1/tools/perform-web-task',
headers: @headers, body: payload.to_json)
response.parsed_response['data']['result']
end
end
# Usage
search_task = "Go to X and search for 'your_brand'. Extract recent posts as JSON."
results = anchor_client.perform_web_task(task: search_task, url: "https://twitter.com/search")- Smart Duplicate Prevention
Before saving posts, the bot checks all existing entries in your spreadsheet:
class PostTracker
def filter_truly_new_posts(posts, existing_post_ids)
existing_ids_set = existing_post_ids.to_set
posts.select do |post|
post_id = extract_post_id(post)
!existing_ids_set.include?(post_id)
end
end
def extract_post_id(post)
# Extract tweet ID from URL: /status/1234567890 -> 1234567890
if post['post_url']&.include?('/status/')
post['post_url'].split('/status/').last.split('?').first
else
post['post_id']
end
end
end
# Usage
existing_ids = sheets_client.get_all_post_ids
new_posts = post_tracker.filter_truly_new_posts(all_posts, existing_ids)- Optional: Downstream Destination Output
Send new mentions to any service via webhooks for instant notifications:
class WebhookClient
def send_new_posts(posts)
payload = {
event_type: "new_brand_mentions",
timestamp: Time.now.iso8601,
posts: posts.map do |post|
{
post_url: post['post_url'],
author: post['author'],
content: post['content'],
found_at: Time.now.iso8601
}
end
}
HTTParty.post(@webhook_url,
headers: { 'Content-Type' => 'application/json' },
body: payload.to_json)
end
end
# Usage
webhook_client = WebhookClient.new(webhook_url: ENV['SLACK_WEBHOOK_URL'])
webhook_client.send_new_posts(new_posts) # Instant Slack notificationsConnect to Zapier, Slack, Discord, or any HTTP endpoint to trigger alerts, update dashboards, or feed other business systems.
Running the Bot
First, create your X profile in Anchor Browser:
- Go to Anchor Browser Playground
- Start a new session and navigate to https://x.com
- Log in with your X account
- Save the browser profile in the Anchor Browser playground
- Set your profile name to the environment variable,
ANCHOR_PROFILE_NAME
Then set up your Google Sheet:
Create a new Google Spreadsheet:
- Copy the spreadsheet ID from the URL
- Set your Google sheet ID to
GOOGLE_SHEETS_ID - Create a service account in Google Cloud Console
- Download the JSON key and base64 encode it:
base64 -i service-account.json - Set your base64-encoded service account key to
GOOGLE_SERVICE_ACCOUNT_JSON - Share your spreadsheet with the service account email
And finally set your API key for Anchor Browser:
- Go to the Anchor Browser cloud app
- Navigate to the API Keys page
- Copy your API key and set your variable,
ANCHOR_API_KEY
Your environment variables should look as follows:
ANCHOR_API_KEY=your_anchor_api_key
ANCHOR_PROFILE_NAME=twitter-profile-name
GOOGLE_SHEETS_ID=your_spreadsheet_id
GOOGLE_SERVICE_ACCOUNT_JSON=base64_encoded_service_accountTest run:
ruby main.rb
You'll see log output that steps you through the program's execution flow and indicators of any available results.
Automated Monitoring
For continuous mention monitoring, deploy as a scheduled function using a cloud service provider of your choice.
Conclusion
You now have a fully automated brand monitoring system that runs continuously in the cloud, costs pennies to operate, and can be modified to fit your exact business needs. As new mentions appear on X, they'll automatically flow into your Google Sheet and trigger any downstream workflows you've configured—giving you real-time visibility into your brand's social media presence without the overhead of enterprise monitoring tools.
Have any questions on how to stand this up for your brand or have other ideas for your business? Feel free to reach out to us and we'll be glad to help.



