-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure-tracking.sh
More file actions
executable file
·125 lines (103 loc) · 3.97 KB
/
configure-tracking.sh
File metadata and controls
executable file
·125 lines (103 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Tracking Mode Configuration Script
# Usage: ./configure-tracking.sh [visible|hidden]
set -e
TRACKING_MODE=${1:-"visible"}
ENV_FILE=".env"
NGINX_CONF="nginx.conf"
COMPOSE_FILE="docker-compose.yml"
echo "🔧 Configuring tracking mode: $TRACKING_MODE"
# Check DNS configuration first
echo "🌐 Checking DNS configuration..."
if [ -n "$PRIMARY_HOST" ]; then
PRIMARY_IP=$(dig +short $PRIMARY_HOST 2>/dev/null)
if [ -n "$PRIMARY_IP" ]; then
echo "✅ $PRIMARY_HOST → $PRIMARY_IP"
else
echo "⚠️ $PRIMARY_HOST → DNS not configured yet"
echo " See DNS-SETUP-GUIDE.md for configuration instructions"
fi
SGTM_IP=$(dig +short $SGTM_HOST 2>/dev/null)
if [ -n "$SGTM_IP" ]; then
echo "✅ $SGTM_HOST → $SGTM_IP"
else
echo "⚠️ $SGTM_HOST → DNS not configured yet"
fi
TRACKER_IP=$(dig +short $TRACKER_HOST 2>/dev/null)
if [ -n "$TRACKER_IP" ]; then
echo "✅ $TRACKER_HOST → $TRACKER_IP"
else
echo "⚠️ $TRACKER_HOST → DNS not configured yet"
fi
echo ""
fi
case $TRACKING_MODE in
"visible")
echo "📊 Setting up VISIBLE parallel tracking (recommended)"
# Update .env for visible tracking
sed -i 's/ENABLE_HIDDEN_PROXY=.*/ENABLE_HIDDEN_PROXY=false/' $ENV_FILE
sed -i 's/ENABLE_GA_ENHANCEMENT=.*/ENABLE_GA_ENHANCEMENT=false/' $ENV_FILE
sed -i 's/FORWARD_TO_GA=.*/FORWARD_TO_GA=true/' $ENV_FILE
# Use standard nginx config
cp nginx.conf nginx-active.conf
# Use standard tracker
sed -i 's|./tracker/.*-index.js:/app/index.js:ro|./tracker/ga-enhanced-index.js:/app/index.js:ro|' $COMPOSE_FILE
echo "✅ Visible tracking configured:"
echo " - GA tracking continues normally"
echo " - Parallel data capture for analytics"
echo " - GDPR compliant"
echo " - Easy to audit and debug"
;;
"hidden")
echo "🕵️ Setting up HIDDEN proxy tracking (advanced)"
# Update .env for hidden tracking
sed -i 's/ENABLE_HIDDEN_PROXY=.*/ENABLE_HIDDEN_PROXY=true/' $ENV_FILE
sed -i 's/ENABLE_GA_ENHANCEMENT=.*/ENABLE_GA_ENHANCEMENT=false/' $ENV_FILE
sed -i 's/FORWARD_TO_GA=.*/FORWARD_TO_GA=true/' $ENV_FILE
# Use hidden proxy nginx config
cp nginx-hidden-proxy.conf nginx-active.conf
# Use hidden proxy tracker
sed -i 's|./tracker/.*-index.js:/app/index.js:ro|./tracker/hidden-proxy-index.js:/app/index.js:ro|' $COMPOSE_FILE
echo "⚠️ Hidden tracking configured:"
echo " - Complete data control"
echo " - GA traffic routed through your server"
echo " - Ad blocker resistant"
echo " - Consider legal/compliance implications"
;;
*)
echo "❌ Invalid tracking mode: $TRACKING_MODE"
echo "Usage: $0 [visible|hidden]"
exit 1
;;
esac
# Update docker-compose to use active config
sed -i 's|./nginx.*\.conf:/etc/nginx/nginx.conf.template:ro|./nginx-active.conf:/etc/nginx/nginx.conf.template:ro|' $COMPOSE_FILE
echo ""
echo "🚀 Configuration complete! Next steps:"
echo ""
echo "1. Review your .env file:"
echo " cat .env"
echo ""
echo "2. Restart services:"
echo " docker compose down"
echo " docker compose up -d"
echo ""
echo "3. Test the configuration:"
echo " curl https://$PRIMARY_HOST/health"
echo " curl https://$TRACKER_HOST/v1/config/hidden"
echo ""
if [ "$TRACKING_MODE" = "hidden" ]; then
echo "⚠️ HIDDEN TRACKING WARNINGS:"
echo " - Ensure compliance with privacy laws in your jurisdiction"
echo " - Users cannot see data collection in browser dev tools"
echo " - May violate some website terms of service"
echo " - Consider adding privacy notice to your website"
echo ""
echo "🔍 Monitor hidden tracking:"
echo " curl https://$TRACKER_HOST/v1/analytics/hidden"
echo ""
fi
echo "📚 Documentation:"
echo " - Visible tracking: GA-PARALLEL-TRACKING.md"
echo " - Hidden tracking: TRACKING-STRATEGY-GUIDE.md"
echo " - Configuration: env.example"