Le Duy Khuong

Chuỗi: seo-posthog · Phần 1

Năng suất & công cụ dev

PostHog vs GA4 — Khi nào dùng gì

Marketing vs product analytics

2026-03-206 phút đọcVI

Định dạng Case Study

This post follows the Problem → Approach → Result → Lessons structure.

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ạnhGA4PostHog
FocusMarketing: Where users come fromProduct: What users do
Core question"How to get more traffic?""How to improve the product?"
Data ownershipGoogle servers (US)Self-host hoặc PostHog cloud
PrivacyGoogle's data (shared ecosystem)Your data only
PricingFree (với limits)Free tier generous, self-host free
Real-timeLimited (Realtime report)Yes (events stream)
Session Replay
Feature Flags
A/B Testing❌ (need Optimize, deprecated)
Heatmaps
Search Console integration
Audience demographicsLimited

Điểm mạnh theo lĩnh vực (0–100):

Marketing Analytics
95
SEO & Search
90
Demographics
85
Product Analytics
30

▲ GA4 — mạnh marketing, yếu product

Marketing Analytics
40
SEO & Search
20
Demographics
25
Product Analytics
95

▲ 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

Loading diagram...

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:

  1. capture_pageview: true — PostHog tự track page views (giống GA4 enhanced measurement)
  2. capture_pageleave: true — Track khi user rời page (GA4 không có native)
  3. autocapture: true — PostHog ghi lại mọi click, form submit, page change. Không cần code thêm.
  4. 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?

  1. GA4 — Event xuất hiện trong marketing reports (Acquisition → Events → search_used → which channel drove search usage)
  2. 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ỏiDù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).

Loading diagram...

Cost Comparison

FeatureGA4 FreePostHog Free
Events/monthUnlimited1M events
Session replay5,000 recordings
Data retention14 months1 year
UsersUnlimitedUnlimited
Custom reports10 ExplorationsUnlimited
Feature flags1M evaluations

leduykhuong.com usage vs free tier limits:

GA4 Events~2K / Unlimited
PostHog Events~2K / 1,000,000
PostHog Recordings~200 / 5,000
PostHog Feature Flags~100 / 1,000,000 evals

GA4 Tier

Free

Unlimited events, 14-month retention

PostHog Tier

Free

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:

  1. "Muốn biết bài blog nào từ organic search có engagement cao nhất"
  2. "Muốn xem user bị stuck ở đâu khi navigate blog"
  3. "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 gateAnalyticsProvider chỉ 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.

LDK

Le Duy Khuong

AI Transformation & Digital Strategy. Writing about agentic systems, engineering leadership, and building in public.