Files
HOALedgerIQ_Website/agents/marketing-seo/scripts/daily-report.sh
olsch01 eb1a65b661 feat: Integrate GA4 analytics into SEO agent
- Added GA4 traffic monitoring to seo-agent.py
- Tracks sessions, users, bounce rate from GA4
- Detects traffic anomalies (>50% drop triggers alert)
- Maintains 30-day traffic history in state
- Updated daily-report.sh with enhanced GA4 metrics
- GA4 data now flows to morning brief
- Hourly checks every 6 hours to avoid API fatigue
2026-04-01 19:23:00 -04:00

68 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Daily SEO Report - 8 AM UTC
# Includes GA4 Analytics Data
WORKSPACE="/Users/claw/.openclaw/workspace/agents/marketing-seo"
LOG="$WORKSPACE/logs"
cd $WORKSPACE
# Get GA4 data
echo "📊 Fetching GA4 Analytics..."
GA_OUTPUT=$(python3 scripts/ga4-direct.py 2>/dev/null)
# Parse GA4 metrics
SESSIONS=$(echo "$GA_OUTPUT" | grep -i "Sessions:" | grep -o "[0-9]*" | head -1)
USERS=$(echo "$GA_OUTPUT" | grep -i "Users:" | grep -o "[0-9]*" | head -1)
BOUNCE=$(echo "$GA_OUTPUT" | grep -i "Bounce Rate:" | grep -o "[0-9.]*" | head -1)
# Set defaults if empty
SESSIONS=${SESSIONS:-"N/A"}
USERS=${USERS:-"N/A"}
BOUNCE=${BOUNCE:-"N/A"}
# Get site status
WWW_UP=$(curl -s -o /dev/null -w "%{http_code}" https://www.hoaledgeriq.com -m 10)
APP_UP=$(curl -s -o /dev/null -w "%{http_code}" https://app.hoaledgeriq.com -m 10)
# Format status icons
WWW_ICON="✅"
APP_ICON="✅"
if [ "$WWW_UP" != "200" ]; then WWW_ICON="❌"; fi
if [ "$APP_UP" != "200" ]; then APP_ICON="❌"; fi
# Get rankings status (from rank-tracker if available)
RANK_FILE="$WORKSPACE/state/rank-data.json"
if [ -f "$RANK_FILE" ]; then
KEYWORDS=$(cat "$RANK_FILE" | grep -o '"keywords":\[[^]]*\]' | grep -o '[0-9]*' | head -1)
RANK_STATUS="Tracking $KEYWORDS keywords"
else
RANK_STATUS="Baseline monitoring active"
fi
# Build message
MSG="📊 *DAILY SEO REPORT* - $(date '+%a %b %d')
🌐 *Sites:*
${WWW_ICON} www.hoaledgeriq.com: ${WWW_UP}
${APP_ICON} app.hoaledgeriq.com: ${APP_UP}
📈 *Traffic (24h):*
• Sessions: ${SESSIONS}
• Users: ${USERS}
• Bounce Rate: ${BOUNCE}%
📈 *Rankings:*
${RANK_STATUS}
• Monitoring for breakthrough
⚡ Status: Healthy ✅
_GA4 Analytics Integrated_"
# Send via Telegram
openclaw message send --channel telegram --target telegram:8269921691 --message "$MSG" 2>/dev/null || echo "$MSG" >> "$LOG/daily-$(date +%Y%m%d).log"
# Log success
echo "Report sent: $(date)" >> "$LOG/report-sent.log"
echo "Daily report completed at $(date)"