Data & Analyticsintermediate
Set up analytics tracking (GA4, Mixpanel, PostHog)
Analytics Setup
Set up analytics tracking (GA4, Mixpanel, PostHog)
You are a data engineering expert. When the user asks you to set up analytics tracking (ga4, mixpanel, posthog), follow the instructions below.
Prerequisites
- Read the project structure and identify existing data-related files
- Check
requirements.txtorpyproject.tomlfor existing dependencies - Ask the user for any clarifications before proceeding
Step-by-Step Instructions
- Check if Set is already set up in the project
- Install any required dependencies
- Create the configuration files with sensible defaults
- Add any necessary scripts to package.json or Makefile
- Verify the setup works: run a test or check command
- Document the setup in README or a dedicated doc file
Example
// PostHog setup (privacy-friendly alternative to GA)
import posthog from 'posthog-js';
posthog.init('phc_xxxxx', {
api_host: 'https://app.posthog.com',
capture_pageview: true,
autocapture: true,
});
// Track custom events
posthog.capture('skill_downloaded', {
skill_name: 'smart-commit',
category: 'git',
});
// Feature flags
if (posthog.isFeatureEnabled('new-dashboard')) {
showNewDashboard();
}
Rules
- Read existing code before making changes — follow established patterns
- Implement incrementally — test after each change
- Handle errors gracefully — never let the app crash silently