Competitor Tweet Tracker

This Val Town project tracks tweets mentioning competitor URLs and visualizes the data in charts.

Project Structure

├── main.tsx (cron)          # Hourly cron job to collect tweet data
├── api.ts (http)            # HTTP API and static file server
├── db.ts                    # Database operations and schema
├── utils/
│   └── competitors.ts       # Competitor configuration utilities
└── views/
    ├── index.html          # Main HTML template
    └── charts.js           # Chart rendering JavaScript

Environment Variables

Required

  • TWITTER_BEARER_TOKEN: Your Twitter API bearer token for searching tweets

Optional

  • COMPETITORS: Comma-separated list of competitor hostnames to track (default: val.town)

    Examples:

    • val.town (default)
    • val.town,poe.com,shapes.inc
    • poe.com,character.ai,pi.ai,coze.com,gumloop.com,n8n.io

Here are some popular competitors you might want to track:

val.town,poe.com,character.ai,pi.ai,coze.com,gumloop.com,n8n.io,shapes.inc,manus.im,genspark.ai

Components

  1. Cron Job (main.tsx): Runs hourly to search Twitter for mentions of competitor URLs and stores the results in a database.
  2. Database (db.ts): Uses SQLite to store tweet data and provides functions to query the data.
  3. Web Interface (api.ts): Serves the HTML page and provides API endpoints for chart data.
  4. Views (views/): Contains the HTML template and JavaScript for rendering charts.

How to Use

  1. Set up the TWITTER_BEARER_TOKEN environment variable with your Twitter API bearer token.
  2. Optionally set the COMPETITORS environment variable with your list of competitors to track.
  3. The cron job will automatically run every hour to collect data.
  4. Visit the HTTP endpoint to view the charts showing tweet counts.

Features

  • Tracks tweets mentioning competitor URLs
  • Configurable competitor list via environment variables
  • Avoids double-counting tweets by storing unique tweet IDs
  • Visualizes data in daily trend charts and total count charts
  • Automatically updates as new data is collected
  • Separated HTML/CSS/JS from API logic for better maintainability