analytics-setup

Generates protocol-based analytics infrastructure with swappable providers (TelemetryDeck, Firebase, Mixpanel). Use when user wants to add analytics, track events, or set up telemetry.

110 stars

Best use case

analytics-setup is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generates protocol-based analytics infrastructure with swappable providers (TelemetryDeck, Firebase, Mixpanel). Use when user wants to add analytics, track events, or set up telemetry.

Teams using analytics-setup should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/analytics-setup/SKILL.md --create-dirs "https://raw.githubusercontent.com/gustavscirulis/snapgrid/main/.claude/skills/skills/generators/analytics-setup/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/analytics-setup/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How analytics-setup Compares

Feature / Agentanalytics-setupStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates protocol-based analytics infrastructure with swappable providers (TelemetryDeck, Firebase, Mixpanel). Use when user wants to add analytics, track events, or set up telemetry.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Analytics Setup Generator

Generate a protocol-based analytics infrastructure that makes it easy to swap providers without changing app code.

## When This Skill Activates

Use this skill when the user:
- Asks to "add analytics" or "set up analytics"
- Mentions "TelemetryDeck", "Firebase Analytics", "Mixpanel"
- Wants to "track events" or "add telemetry"
- Asks about "privacy-friendly analytics"
- Wants to swap analytics providers

## Key Feature: Swappable Providers

The generated code uses a protocol-based architecture:

```swift
// Your app uses the protocol
analytics.track(.buttonTapped("subscribe"))

// Swap providers by changing ONE line:
let analytics: AnalyticsService = TelemetryDeckAnalytics() // or FirebaseAnalytics()
```

## Pre-Generation Checks

### 1. Project Context Detection
- [ ] Check for existing analytics implementations
- [ ] Look for TelemetryDeck/Firebase/Mixpanel in Package.swift or Podfile
- [ ] Identify source file locations

### 2. Conflict Detection
Search for existing analytics:
```
Glob: **/*Analytics*.swift, **/*Telemetry*.swift
Grep: "protocol.*Analytics" or "TelemetryDeck" or "Firebase"
```

If found, ask user:
- Extend existing analytics?
- Replace with new implementation?
- Add new provider to existing setup?

## Configuration Questions

Ask user via AskUserQuestion:

1. **Which provider(s)?**
   - TelemetryDeck (privacy-friendly, recommended)
   - Firebase Analytics
   - Mixpanel
   - None (NoOp for now, add later)

2. **What events to track?**
   - App lifecycle (launch, background, foreground)
   - Screen views
   - User actions (buttons, features used)
   - Errors
   - Custom events

3. **User properties?**
   - App version
   - Subscription status
   - Custom properties

## Generation Process

### Step 1: Create Core Files

Always generate these files:
1. `AnalyticsService.swift` - Protocol (never changes)
2. `AnalyticsEvent.swift` - Event definitions (app-specific)
3. `NoOpAnalytics.swift` - For testing/privacy mode

### Step 2: Create Selected Provider(s)

Based on user selection:
- `TelemetryDeckAnalytics.swift`
- `FirebaseAnalytics.swift`
- `MixpanelAnalytics.swift`

### Step 3: Create Environment Integration

For SwiftUI apps:
- `AnalyticsServiceKey.swift` - Environment key for dependency injection

### Step 4: Determine File Location

Check project structure:
- If `Sources/` exists → `Sources/Analytics/`
- If `App/` exists → `App/Analytics/`
- Otherwise → `Analytics/`

## Output Format

After generation, provide:

### Files Created
```
Sources/Analytics/
├── AnalyticsService.swift          # Protocol (stable interface)
├── AnalyticsEvent.swift            # Your app's events
├── Providers/
│   ├── NoOpAnalytics.swift         # Testing/privacy
│   └── [Provider]Analytics.swift   # Selected provider(s)
└── AnalyticsServiceKey.swift       # SwiftUI Environment (optional)
```

### Integration Steps

**App Entry Point:**
```swift
@main
struct MyApp: App {
    // Choose your provider
    private let analytics: AnalyticsService = TelemetryDeckAnalytics(appID: "YOUR-APP-ID")

    init() {
        analytics.configure()
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environment(\.analytics, analytics)
        }
    }
}
```

**Tracking Events:**
```swift
struct ContentView: View {
    @Environment(\.analytics) private var analytics

    var body: some View {
        Button("Subscribe") {
            analytics.track(.buttonTapped("subscribe"))
        }
    }
}
```

### Required Dependencies

**TelemetryDeck:**
```swift
// Package.swift
.package(url: "https://github.com/TelemetryDeck/SwiftClient", from: "1.0.0")
```

**Firebase:**
```swift
// Package.swift
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.0.0")
// Also requires GoogleService-Info.plist
```

### Swapping Providers Later

To switch providers:
1. Add new provider file (or generate with this skill)
2. Change ONE line in App.swift:
```swift
// Before
private let analytics: AnalyticsService = TelemetryDeckAnalytics(...)

// After
private let analytics: AnalyticsService = FirebaseAnalytics()
```

### Testing
- Use `NoOpAnalytics()` in tests and previews
- All tracking calls become no-ops
- No external dependencies in tests

## References

- **analytics-patterns.md** - Protocol architecture and best practices
- **templates/** - All template files

Related Skills

snapshot-test-setup

110
from gustavscirulis/snapgrid

Set up SwiftUI visual regression testing with swift-snapshot-testing. Generates snapshot test boilerplate and CI configuration. Use for UI regression prevention.

analytics-interpretation

110
from gustavscirulis/snapgrid

Interpret app metrics and make data-driven decisions. Covers DAU/MAU, retention, LTV, ARPU, App Store Connect analytics, AARRR funnel analysis, cohort analysis, and diagnostic decision trees. Use when user wants to understand their metrics, diagnose problems, or build a data-driven growth plan.

persistence-setup

110
from gustavscirulis/snapgrid

Generates SwiftData or CoreData persistence layer with optional iCloud sync. Use when user wants to add local storage, data persistence, or cloud sync.

offer-codes-setup

110
from gustavscirulis/snapgrid

Generates offer code distribution strategies and configuration guides for subscription and IAP promotions — including partner campaigns, influencer programs, and email re-engagement. Use when setting up offer codes for distribution.

logging-setup

110
from gustavscirulis/snapgrid

Generates structured logging infrastructure using os.log/Logger to replace print() statements. Use when user wants to add proper logging, replace print statements, or set up app logging.

Localization Setup Generator

110
from gustavscirulis/snapgrid

Generate internationalization (i18n) infrastructure for multi-language support in iOS/macOS apps.

CI/CD Setup Generator

110
from gustavscirulis/snapgrid

Generate CI/CD configuration for automated builds, tests, and distribution of iOS/macOS apps.

swiftui-ui-patterns

110
from gustavscirulis/snapgrid

Best practices and example-driven guidance for building SwiftUI views and components. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView, composing screens, or needing component-specific patterns and examples.

watchOS

110
from gustavscirulis/snapgrid

watchOS development guidance including SwiftUI for Watch, Watch Connectivity, complications, and watch-specific UI patterns. Use for watchOS code review, best practices, or Watch app development.

visionos-widgets

110
from gustavscirulis/snapgrid

visionOS widget patterns including mounting styles, glass/paper textures, proximity-aware layouts, and spatial widget families. Use when creating or adapting widgets for visionOS.

test-data-factory

110
from gustavscirulis/snapgrid

Generate test fixture factories for your models. Builder pattern and static factories for zero-boilerplate test data. Use when tests need sample data setup.

test-contract

110
from gustavscirulis/snapgrid

Generate protocol/interface test suites that any implementation must pass. Define the contract once, test every implementation. Use when designing protocols or swapping implementations.