Skip to main content
skill CX Codex

integration-swift — Claude Code skill: what it does, how to install

integration-swift guides PostHog analytics integration into Swift applications across iOS and macOS targets.

MIT 108 installs ★ 80 updated 2026-10-24

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PostHog/skills --skill integration-swift -a claude-code
Open on GitHub

What integration-swift does

The skill directs your coding agent through adding PostHog analytics to Swift codebases. Its workflow follows a clear four-step process from initial setup to review and completion. PostHog credentials stay out of source files: the setup reads POSTHOG_PROJECT_TOKEN and POSTHOG_HOST directly from scheme environment variables using a dedicated PostHogEnv enum.

When wiring Swift Package Manager into project.pbxproj, the agent creates separate objects with distinct UUIDs for the build file, product dependency, and remote package reference. The package references the latest release rather than a frozen build number. For macOS targets running App Sandbox, network access requires setting ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES without disabling the sandbox itself.

What it helps with

  • integrate PostHog SDK into iOS or macOS Swift projects via SPM
  • track user identity during login and signup flows
  • forward session and distinct IDs to backend services via HTTP headers
  • capture runtime errors around sensitive flows and network boundaries

Example prompts for the agent

  • Integrate PostHog analytics into my Swift iOS project
  • Set up user identification for signup and signin flows with PostHog
  • Configure error tracking around our API boundary in Swift

How to install integration-swift

1Skills CLI (Vercel)

npx skills add PostHog/skills --skill integration-swift -a claude-code

2Manually: put the files in place

~/.claude/skills/integration-swift/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/integration-swift/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about integration-swift

How to install integration-swift in Claude Code?

Run npx skills add PostHog/skills --skill integration-swift -a claude-code.

What does integration-swift do?

It outlines a sequential procedure to embed PostHog in iOS and macOS projects, configure SPM dependencies in project.pbxproj, and wire environment flags.

How does the skill handle macOS App Sandbox?

It sets ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES in the target build settings so events reach analytics servers without disabling sandbox protection.

Source text

SKILL.md · MIT
---
name: integration-swift
description: PostHog integration for Swift iOS and macOS applications
metadata:
  author: PostHog
  version: 1.9.4
---

# PostHog integration for Swift (iOS/macOS)

This skill helps you add PostHog analytics to Swift (iOS/macOS) applications.

## Workflow

Follow these steps in order to complete the integration:

1. `basic-integration-1.0-begin.md` - PostHog Setup - Begin ← **Start here**
2. `basic-integration-1.1-edit.md` - PostHog Setup - Edit
3. `basic-integration-1.2-revise.md` - PostHog Setup - Revise
4. `basic-integration-1.3-conclude.md` - PostHog Setup - Conclusion

## Reference files

- `references/EXAMPLE.md` - Swift (iOS/macOS) example project code
- `references/ios.md` - Ios - docs
- `references/identify-users.md` - Identify users - docs
- `references/basic-integration-1.0-begin.md` - PostHog setup - begin
- `references/basic-integration-1.1-edit.md` - PostHog setup - edit
- `references/basic-integration-1.2-revise.md` - PostHog setup - revise
- `references/basic-integration-1.3-conclude.md` - PostHog setup - conclusion

The example project shows the target implementation pattern. Consult the documentation for API details.

## Key principles

- **Environment variables**: Always use environment variables for PostHog keys. Never hardcode them.
- **Minimal changes**: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
- **Match the example**: Your implementation should follow the example project's patterns as closely as possible.

## Framework guidelines

- Read configuration from environment variables via a `PostHogEnv` enum with a `value` computed property that calls `ProcessInfo.processInfo.environment[rawValue]` and `fatalError`s if missing — cases should be `projectToken = "POSTHOG_PROJECT_TOKEN"` and `host = "POSTHOG_HOST"`, set in the Xcode scheme's Run environment variables
- When adding SPM dependencies to project.pbxproj, create three distinct objects with unique UUIDs — a `PBXBuildFile` (with `productRef`), an `XCSwiftPackageProductDependency` (with `package` and `productName`), and an `XCRemoteSwiftPackageReference` (with `repositoryURL` and `requirement`). The build file goes in the Frameworks phase `files`, the product dependency goes in the target's `packageProductDependencies`, and the package reference goes in the project's `packageReferences`.
- Check the latest release version of posthog-ios at `https://github.com/PostHog/posthog-ios/releases` before setting the `minimumVersion` in the SPM package reference — do not hardcode a stale version
- If the project uses App Sandbox (macOS), add `ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES` to the target's build settings so PostHog can reach its servers — do NOT disable the sandbox entirely

## Identifying users

Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` headers to maintain correlation.

## Error tracking

Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.

© PostHog · MIT · PostHog/skills

Similar skills

All skills for Mobile →

From the same set112

The whole set →
feature-flags-api The feature-flags-api skill guides agents through adding PostHog feature flag checks to API applications. Use it when you want to introduce flags without restructuring existing code. CX Codex +1 111installs integration-react-native The integration-react-native skill guides an agent through adding PostHog analytics to a React Native app, including user identification and error tracking. CX Codex +1 109installs feature-flags-react-native feature-flags-react-native integrates PostHog feature flags into React Native apps following best practices for hooks, environment variables, and navigation. CX Codex +1 109installs integration-astro-ssr integration-astro-ssr adds PostHog analytics to server-rendered Astro setups with API endpoints. Connects frontend tracking with backend routes. CX Codex +1 109installs integration-react-vite integration-react-vite adds PostHog analytics to a React app built with Vite and no router: setup in four steps, user identification, feature flags and error tracking. CX Codex +1 107installs omnibus-instrument-llm-analytics omnibus-instrument-llm-analytics adds PostHog LLM analytics to your code so each generation reports tokens, latency and cost. Installs the SDK too when the project has none. CX Codex +1 106installs integration-nextjs-pages-router The integration-nextjs-pages-router skill guides PostHog setup in Next.js Pages Router apps. It covers analytics events, user identity, feature flags, and error tracking. CX Codex +1 103installs integration-react-react-router-7-declarative integration-react-react-router-7-declarative integrates PostHog analytics into React Router v7 declarative mode projects. CX Codex +1 102installs

Project sponsors

Companies that keep this analytics open