feat: Enhanced GA4 integration with engagement tracking

- Added scroll depth tracking (25%, 50%, 75%)
- Track form interactions and outbound clicks
- Added engagement rate, avg session duration, page views
- Updated daily report with comprehensive engagement metrics
- Created ga4-list-events.py to discover tracked events
- All metrics now flow to morning brief
This commit is contained in:
2026-04-01 19:40:51 -04:00
parent e59ddd045d
commit ba066f9984
3 changed files with 304 additions and 129 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# Daily SEO Report - 8 AM UTC
# Includes GA4 Analytics Data
# Enhanced with GA4 Engagement Metrics
WORKSPACE="/Users/claw/.openclaw/workspace/agents/marketing-seo"
LOG="$WORKSPACE/logs"
@@ -11,14 +11,30 @@ 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)
SESSIONS=$(echo "$GA_OUTPUT" | grep "Sessions:" | grep -o "[0-9,]*" | tr -d "," | head -1)
USERS=$(echo "$GA_OUTPUT" | grep "Active Users:" | grep -o "[0-9,]*" | tr -d "," | head -1)
ENGAGEMENT=$(echo "$GA_OUTPUT" | grep "Engagement Rate:" | grep -o "[0-9.]*" | head -1)
BOUNCE=$(echo "$GA_OUTPUT" | grep "Bounce Rate:" | grep -o "[0-9.]*" | head -1)
AVG_SESSION=$(echo "$GA_OUTPUT" | grep "Avg Session:" | grep -o "[0-9.]*" | head -1)
PAGE_VIEWS=$(echo "$GA_OUTPUT" | grep "Page Views:" | grep -o "[0-9,]*" | tr -d "," | head -1)
SCROLL_25=$(echo "$GA_OUTPUT" | grep "Scroll Depth 25%:" | grep -o "[0-9]*" | head -1)
SCROLL_50=$(echo "$GA_OUTPUT" | grep "Scroll Depth 50%:" | grep -o "[0-9]*" | head -1)
SCROLL_75=$(echo "$GA_OUTPUT" | grep "Scroll Depth 75%:" | grep -o "[0-9]*" | head -1)
FORM_INT=$(echo "$GA_OUTPUT" | grep "Form Interactions:" | grep -o "[0-9]*" | head -1)
CLICKS=$(echo "$GA_OUTPUT" | grep "Outbound Clicks:" | grep -o "[0-9]*" | head -1)
# Set defaults if empty
SESSIONS=${SESSIONS:-"N/A"}
USERS=${USERS:-"N/A"}
BOUNCE=${BOUNCE:-"N/A"}
SESSIONS=${SESSIONS:-"0"}
USERS=${USERS:-"0"}
ENGAGEMENT=${ENGAGEMENT:-"0"}
BOUNCE=${BOUNCE:-"0"}
AVG_SESSION=${AVG_SESSION:-"0"}
PAGE_VIEWS=${PAGE_VIEWS:-"0"}
SCROLL_25=${SCROLL_25:-"0"}
SCROLL_50=${SCROLL_50:-"0"}
SCROLL_75=${SCROLL_75:-"0"}
FORM_INT=${FORM_INT:-"0"}
CLICKS=${CLICKS:-"0"}
# Get site status
WWW_UP=$(curl -s -o /dev/null -w "%{http_code}" https://www.hoaledgeriq.com -m 10)
@@ -30,7 +46,7 @@ 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)
# Get rankings status
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)
@@ -39,7 +55,7 @@ else
RANK_STATUS="Baseline monitoring active"
fi
# Build message
# Build enhanced message
MSG="📊 *DAILY SEO REPORT* - $(date '+%a %b %d')
🌐 *Sites:*
@@ -49,7 +65,17 @@ ${APP_ICON} app.hoaledgeriq.com: ${APP_UP}
📈 *Traffic (24h):*
• Sessions: ${SESSIONS}
• Users: ${USERS}
• Page Views: ${PAGE_VIEWS}
• Engagement: ${ENGAGEMENT}%
• Bounce Rate: ${BOUNCE}%
• Avg Session: ${AVG_SESSION}s
🎯 *Engagement Events:*
• Scroll 25%: ${SCROLL_25}
• Scroll 50%: ${SCROLL_50}
• Scroll 75%: ${SCROLL_75}
• Form Interactions: ${FORM_INT}
• Outbound Clicks: ${CLICKS}
📈 *Rankings:*
${RANK_STATUS}
@@ -57,11 +83,11 @@ ${APP_ICON} app.hoaledgeriq.com: ${APP_UP}
⚡ Status: Healthy ✅
_GA4 Analytics Integrated_"
_GA4 Analytics + Engagement Tracking_"
# 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)"
echo "Enhanced daily report completed at $(date)"