Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
5.4 KiB
Copilot Instructions for mixpanel-swift
Repository Summary
This repository contains the Mixpanel Swift SDK - an analytics tracking library for Apple platforms. It enables iOS, tvOS, macOS, and watchOS applications to send event and user data to Mixpanel. The SDK supports Swift Package Manager, CocoaPods, and Carthage for installation.
Languages/Frameworks: Swift 5.0+
Platforms: iOS 12+, tvOS 11+, macOS 10.13+, watchOS 4+
Project Size: ~6,000 lines of Swift code across ~25 source files
Building and Testing
Prerequisites
- macOS with Xcode is required (Apple platform SDK dependencies: UIKit, Foundation, CoreTelephony)
- SwiftLint is used for linting (installed via Homebrew:
brew install swiftlint) - CocoaPods is required for pod linting:
gem install cocoapods
Build Commands
Swift Package Manager (does not work without Apple SDK):
swift build # Requires macOS with Xcode - will fail on Linux
Xcode Build & Test (iOS) - PRIMARY METHOD:
cd MixpanelDemo
# Use available simulator - check with: xcrun simctl list devices
xcodebuild \
-scheme MixpanelDemo \
-derivedDataPath Build/ \
-destination 'platform=iOS Simulator,name=iPhone 15,OS=latest' \
-configuration Debug \
ONLY_ACTIVE_ARCH=NO \
ENABLE_TESTABILITY=YES \
-enableCodeCoverage YES \
clean build test | xcpretty -c
Xcode Build & Test (macOS):
cd MixpanelDemo
xcodebuild \
-scheme MixpanelDemoMac \
-derivedDataPath Build/ \
-configuration Debug \
ONLY_ACTIVE_ARCH=NO \
ENABLE_TESTABILITY=YES \
-enableCodeCoverage YES \
clean build test | xcpretty -c
Pod Lint (validates CocoaPods spec):
pod lib lint --allow-warnings
SwiftLint:
swiftlint lint --config .swiftlint.yml
Important Notes
- Building requires macOS with Xcode - the SDK uses Apple platform frameworks (UIKit, CoreTelephony)
- Tests run from
MixpanelDemo/directory using Xcode schemes - CI uses
xcprettyfor cleaner output - install viagem install xcpretty - Available Xcode schemes:
MixpanelDemo(iOS),MixpanelDemoMac,MixpanelDemoTV,MixpanelDemoWatch
Project Layout
Source Files
Sources/- Main SDK source filesMixpanel.swift- Primary entry point, initialization methodsMixpanelInstance.swift- Core instance management (~1000 lines)Track.swift- Event tracking logicPeople.swift- User profile managementGroup.swift- Group analyticsFlush.swift,FlushRequest.swift- Network flush logicMPDB.swift,MixpanelPersistence.swift- SQLite persistenceFeatureFlags.swift- Feature flags supportAutomaticEvents.swift,AutomaticProperties.swift- Auto-trackingMixpanelOptions.swift- Configuration options
Sources/Mixpanel/PrivacyInfo.xcprivacy- Apple privacy manifest
Demo App and Tests
MixpanelDemo/- Demo application and test suiteMixpanelDemo.xcodeproj/- Xcode project (use this for building)MixpanelDemoTests/- iOS unit testsMixpanelDemoMacTests/- macOS unit testsMixpanelDemoTVTests/- tvOS tests- Test files:
MixpanelBaseTests.swift(base class),MixpanelDemoTests.swift(main tests)
Configuration Files
Package.swift- Swift Package Manager manifestMixpanel-swift.podspec- CocoaPods specification (version: 5.1.3).swiftlint.yml- SwiftLint rules (line_length: 140, excludesMixpanelDemo/)Info.plist- Framework bundle infoMixpanel.xcodeproj/- Framework Xcode project (schemes: Mixpanel, Mixpanel_macOS, Mixpanel_tvOS, Mixpanel_watchOS)
CI/CD Workflows (.github/workflows/)
iOS.yml- iOS tests on pull requests/pushes to mastermacOS.yml- macOS tests on pull requests/pushes to masterrelease.yml- Automated release on version tags (v*)
Scripts (scripts/)
generate_docs.sh- Generates API documentation with Jazzycarthage.sh- Builds Carthage frameworkrelease.py- Version bumping script (updates podspec, Info.plist, AutomaticProperties.swift)
Making Changes
Version Updates
When updating the SDK version, these files must be modified:
Mixpanel-swift.podspec-s.versionfieldInfo.plist-CFBundleShortVersionStringkeySources/AutomaticProperties.swift-libVersion()function return value (line ~151)scripts/generate_docs.sh---module-versionparameter
Test Patterns
Tests use MixpanelBaseTests as base class. Key patterns:
- Use
randomId()for test tokens - Use
waitForTrackingQueue()after async operations - Use
flushAndWaitForTrackingQueue()for network operations - Call
removeDBfile(token)in teardown to clean SQLite files
Platform-Specific Code
Use conditional compilation:
#if !os(OSX)
import UIKit
#else
import Cocoa
#endif
#if os(iOS)
// iOS-specific code
#endif
SwiftLint Exclusions
Files excluded from linting are listed in .swiftlint.yml - includes legacy/deprecated code. When adding new files, ensure they follow the configured rules (line_length: 140).
Validation Checklist
- Run SwiftLint:
swiftlint lint --config .swiftlint.yml - Build and test iOS: Use
xcodebuildwithMixpanelDemoscheme - Validate pod spec:
pod lib lint --allow-warnings - Ensure no breaking changes to public API (check
open classandpublicdeclarations)
Trust these instructions. Only search the codebase if information here is incomplete or incorrect.