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
This commit is contained in:
@@ -1,42 +1,67 @@
|
||||
#!/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
|
||||
GA=$(python3 scripts/ga4-direct.py 2>/dev/null | grep -A3 "Traffic Data")
|
||||
SESSIONS=$(echo "$GA" | grep Sessions | grep -o "[0-9]*")
|
||||
USERS=$(echo "$GA" | grep Users | grep -o "[0-9]*")
|
||||
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)
|
||||
|
||||
# Rankings
|
||||
RANK_STATUS="Establishment phase (not yet in top 100)"
|
||||
# Format status icons
|
||||
WWW_ICON="✅"
|
||||
APP_ICON="✅"
|
||||
if [ "$WWW_UP" != "200" ]; then WWW_ICON="❌"; fi
|
||||
if [ "$APP_UP" != "200" ]; then APP_ICON="❌"; fi
|
||||
|
||||
# Send Telegram report
|
||||
# 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.hoaledgeriq.com: ${WWW_UP}
|
||||
✅ app.hoaledgeriq.com: ${APP_UP}
|
||||
${WWW_ICON} www.hoaledgeriq.com: ${WWW_UP}
|
||||
${APP_ICON} app.hoaledgeriq.com: ${APP_UP}
|
||||
|
||||
📈 *Traffic (24h):*
|
||||
• Sessions: ${SESSIONS:-0}
|
||||
• Users: ${USERS:-0}
|
||||
• Sessions: ${SESSIONS}
|
||||
• Users: ${USERS}
|
||||
• Bounce Rate: ${BOUNCE}%
|
||||
|
||||
📈 *Rankings:*
|
||||
${RANK_STATUS}
|
||||
• 8 keywords tracked
|
||||
• Baseline established
|
||||
• Monitoring for break-through
|
||||
• ${RANK_STATUS}
|
||||
• Monitoring for breakthrough
|
||||
|
||||
⚡ Status: Healthy ✅"
|
||||
⚡ 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)"
|
||||
|
||||
Reference in New Issue
Block a user