2026-03-206 phút đọcVI
Định dạng Case Study
PostHog vs GA4 — When to Use What
Mở đầu
leduykhuong.com dùng CẢ GA4 và PostHog. Tại sao? Chúng không phải duplicate — chúng có strengths khác nhau. GA4 giỏi về marketing analytics (traffic sources, SEO, audience). PostHog giỏi về product analytics (user behavior, session replay, feature flags).
Hiểu khi nào dùng gì giúp anh hỏi đúng tool đúng câu hỏi.
Mục tiêu: So sánh capabilities, hiểu philosophy khác nhau, và khi nào dùng GA4, khi nào PostHog, khi nào cả hai.
Philosophy — Marketing vs Product
| Khía cạnh | GA4 | PostHog |
|---|---|---|
| Focus | Marketing: Where users come from | Product: What users do |
| Core question | "How to get more traffic?" | "How to improve the product?" |
| Data ownership | Google servers (US) | Self-host hoặc PostHog cloud |
| Privacy | Google's data (shared ecosystem) | Your data only |
| Pricing | Free (với limits) | Free tier generous, self-host free |
| Real-time | Limited (Realtime report) | Yes (events stream) |
| Session Replay | ❌ | ✅ |
| Feature Flags | ❌ | ✅ |
| A/B Testing | ❌ (need Optimize, deprecated) | ✅ |
| Heatmaps | ❌ | ✅ |
| Search Console integration | ✅ | ❌ |
| Audience demographics | ✅ | Limited |
Điểm mạnh theo lĩnh vực (0–100):
▲ GA4 — mạnh marketing, yếu product
▲ PostHog — mạnh product, yếu marketing
PostHog exclusive capabilities (GA4 = 0):
Session Replay
Xem recording thực tế user sessions
Feature Flags
Toggle features per user segment
A/B Testing
Experiments tích hợp feature flags
Heatmaps
Click & scroll behavior maps
Khi nào dùng GA4
GA4 là best choice cho:
1. Traffic Analysis
"Traffic đến từ đâu?" — GA4 có built-in channel grouping, UTM parsing, và Search Console integration.
2. SEO Monitoring
"Organic traffic tăng hay giảm?" — GA4 + GSC cho full SEO picture.
3. Audience Demographics
"Users ở đâu? Dùng device gì?" — GA4 có Google's demographic data (age, gender, interests).
4. Cross-platform Comparison
"Site so với industry benchmarks thế nào?" — GA4 có benchmarking reports.
5. Attribution
"Channel nào drive conversions?" — GA4 có data-driven attribution model.
Khi nào dùng PostHog
PostHog là best choice cho:
1. Session Replay
"User thấy gì khi browse site?" — Xem recording thực tế: mouse movements, scrolls, clicks. Invaluable cho UX debugging.
2. Funnels
"Bao nhiêu % users từ blog listing → click bài → đọc xong?" — PostHog funnels chính xác hơn GA4 (event-level, không sampling).
3. Feature Flags
"Chỉ bật tính năng mới cho 10% users trước" — PostHog có feature flags native.
4. A/B Testing
"Title A hay Title B convert tốt hơn?" — PostHog Experiments tích hợp với feature flags.
5. Data Ownership
"Data của tôi, trên server của tôi" — PostHog có thể self-host. GDPR-friendly.
6. Autocapture
"Track mọi click, mọi form submit mà không cần code" — PostHog autocapture ghi lại interactions tự động.
leduykhuong.com Integration Architecture
Code architecture:
// AnalyticsProvider.tsx — wraps both
<PostHogProvider>
<GA4Script />
{children}
</PostHogProvider>PostHog config:
// PostHogProvider.tsx
posthog.init(POSTHOG_KEY, {
api_host: POSTHOG_HOST,
capture_pageview: true, // Auto page_view
capture_pageleave: true, // Track page exit
autocapture: true, // Auto click/form tracking
session_recording: {
maskAllInputs: true, // Privacy: mask form inputs
},
});Key config choices:
capture_pageview: true— PostHog tự track page views (giống GA4 enhanced measurement)capture_pageleave: true— Track khi user rời page (GA4 không có native)autocapture: true— PostHog ghi lại mọi click, form submit, page change. Không cần code thêm.maskAllInputs: true— Session replay che all form inputs. Privacy-first: không record passwords, search queries, etc.
Unified trackEvent() — Best of Both Worlds
// lib/analytics.ts
export function trackEvent(name: string, properties?: Record<string, unknown>) {
// GA4
if (typeof window !== "undefined" && window.gtag) {
window.gtag("event", name, properties);
}
// PostHog
if (typeof window !== "undefined" && window.posthog) {
window.posthog.capture(name, properties);
}
}Custom events gửi tới CẢ HAI tools. Tại sao?
- GA4 — Event xuất hiện trong marketing reports (Acquisition → Events → search_used → which channel drove search usage)
- PostHog — Event xuất hiện trong product reports (Funnels → how many users search → then read article → then return)
Cùng event, khác analysis context.
Decision Matrix
| Câu hỏi | Dùng tool nào |
|---|---|
| "Traffic organic tăng bao nhiêu tháng này?" | GA4 |
| "Users thấy gì khi đọc bài?" | PostHog (session replay) |
| "Query nào drive traffic?" | GA4 + GSC |
| "Bao nhiêu % users scroll qua 50% bài?" | PostHog |
| "Users từ LinkedIn vs Twitter — ai engage hơn?" | GA4 |
| "Feature mới có làm users ở lại lâu hơn?" | PostHog (A/B test) |
| "Demographic breakdown users" | GA4 |
| "User journey trên site" | PostHog (funnels, paths) |
| "Overall traffic trends" | GA4 |
| "Specific user behavior" | PostHog |
Rule of thumb: GA4 cho "macro" questions (traffic, channels, trends). PostHog cho "micro" questions (user behavior, UX, features).
Cost Comparison
| Feature | GA4 Free | PostHog Free |
|---|---|---|
| Events/month | Unlimited | 1M events |
| Session replay | ❌ | 5,000 recordings |
| Data retention | 14 months | 1 year |
| Users | Unlimited | Unlimited |
| Custom reports | 10 Explorations | Unlimited |
| Feature flags | ❌ | 1M evaluations |
leduykhuong.com usage vs free tier limits:
GA4 Tier
Unlimited events, 14-month retention
PostHog Tier
1M events, 5K recordings, feature flags
Kết luận: Cả hai free tiers thừa sức cover. Site có ~500-1000 sessions/month — nowhere near limits.
Thực hành
Bài tập 1: So sánh data
Cùng ngày, mở cả GA4 và PostHog:
- GA4: Users count
- PostHog: Unique users
- Câu hỏi: Hai con số có khớp không? Tại sao có thể khác?
Bài tập 2: PostHog autocapture
Mở PostHog → Events:
- Filter: event type =
$autocapture - Xem: PostHog đã auto-track những gì?
- So sánh: GA4 enhanced measurement track những gì?
Bài tập 3: Decision exercise
Cho mỗi scenario, chọn tool phù hợp:
- "Muốn biết bài blog nào từ organic search có engagement cao nhất"
- "Muốn xem user bị stuck ở đâu khi navigate blog"
- "Muốn test 2 versions của CTA button"
Tóm tắt
- GA4 = marketing analytics — Traffic sources, SEO, demographics, attribution
- PostHog = product analytics — Session replay, funnels, feature flags, A/B testing
- leduykhuong.com dùng cả hai vì chúng answer different questions
trackEvent()gửi events tới cả hai tools — cùng data, khác analysis- Production gate —
AnalyticsProviderchỉ load trên leduykhuong.com - PostHog autocapture — auto-track clicks, forms, page changes mà không cần code
Bài tiếp theo
Bài 14: Session Replay — Watching Real Users — PostHog's killer feature: xem recordings thực tế của user sessions. Cách cấu hình, privacy controls, và cách extract UX insights.
