{"id":28404007,"url":"https://github.com/simpleanalytics/swift-package","last_synced_at":"2025-08-27T05:06:17.625Z","repository":{"id":205348915,"uuid":"712385945","full_name":"simpleanalytics/swift-package","owner":"simpleanalytics","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-04T14:44:16.000Z","size":63,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-18T14:55:07.966Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.simpleanalytics.com/install-simple-analytics-with-swift","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simpleanalytics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-10-31T11:19:02.000Z","updated_at":"2025-01-04T14:42:55.000Z","dependencies_parsed_at":"2024-02-12T16:46:39.082Z","dependency_job_id":null,"html_url":"https://github.com/simpleanalytics/swift-package","commit_stats":null,"previous_names":["simpleanalytics/swift-package"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/simpleanalytics/swift-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleanalytics%2Fswift-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleanalytics%2Fswift-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleanalytics%2Fswift-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleanalytics%2Fswift-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simpleanalytics","download_url":"https://codeload.github.com/simpleanalytics/swift-package/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleanalytics%2Fswift-package/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272293583,"owners_count":24908649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-01T19:11:19.203Z","updated_at":"2025-08-27T05:06:17.617Z","avatar_url":"https://github.com/simpleanalytics.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Analytics Swift Package\nSwift package for [Simple Analytics](https://www.simpleanalytics.com/?referral=roel-van-der-kraan). Add privacy friendly analytics to your iOS apps. Currently in development. This is an alpha version, everything might change.\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsimpleanalytics%2Fswift-package%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/simpleanalytics/swift-package)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsimpleanalytics%2Fswift-package%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/simpleanalytics/swift-package)\n\n## Installation\nWhen using Xcode to add the package dependency add this repository via `File` \u003e `Add package dependency`:\n`https://github.com/simpleanalytics/swift-package.git`\n\nOr when working with a package manifest use:\n```swift\n.package(url: \"https://github.com/simpleanalytics/swift-package.git\", from: \"0.3.0\")\n```\n\n## Usage\nYou'll need a Simple Analytics account to be able to use this package. See [Simple Analytics](https://www.simpleanalytics.com/?referral=roel-van-der-kraan) for more info.\n\nImport the library:\n```swift\nimport SimpleAnalytics\n```\n\nYou will need the hostname of a Simple Analytics website to start an instance of `SimpleAnalytics` in your app. You can add a fake \"website\" to Simple Analytics specifically for your app. There is no need to point to a real server. You can use something like `mobileapp.yourdomain.com`. Skip the HTML validation by clicking \"I installed the script\". \n⚠️ Make sure the hostname you set in Swift matches the website domain name in Simple Analytics (without http:// or https://).\n```swift\nlet simpleAnalytics = SimpleAnalytics(hostname: \"mobileapp.yourdomain.com\")\n```\n\nYou can create an instance where you need it, or you can make an extension and use it as a static class.\n```swift\nimport SimpleAnalytics\n\nextension SimpleAnalytics {\n    static let shared: SimpleAnalytics = SimpleAnalytics(hostname: \"mobileapp.yourdomain.com\")\n}\n```\n\n## Tracking\nYou can call the tracking functions from anywhere in your app.\n### Tracking Pageviews\nUse pageviews to track screens in your app.\n```swift\nSimpleAnalytics.shared.track(path: [\"list\"])\n```\nTo represent a hierarchy in your views, add every level as an entry in the path array:\n```swift\nSimpleAnalytics.shared.track(path: [\"detailview\", \"item1\", \"edit\"])\n```\nThis will be converted to a pageview on `/detailview/item1/edit` on Simple Analytics.\n\n### Tracking Events\nUse events to track interactions or noticable events like errors or success on a page.\n```swift\nSimpleAnalytics.shared.track(event: \"logged in\")\n```\nYou can provide an optional path to track alongside the event.\n```swift\nSimpleAnalytics.shared.track(event: \"logged in\", path: [\"login\", \"social\"])\n```\n\n### Tracking Visitors for Apps + Widgets\nIf you have an app + widget(s), by default one visit per day per target (app, widget) is treated as separate 'visitors'. This means that if you have an app with a small and medium widget, one person using the core app and both widgets will show in your SimpleAnalytics dashboard as 3 visitors. However, you can ensure one visitor only appears once per day by creating an App Group in your Xcode project. Create a new App Group ([instructions](https://developer.apple.com/documentation/xcode/configuring-app-groups)) in each of your targets (Project \u003e Targets \u003e Signing \u0026 Capabilities \u003e App Groups) with the same name. Use this app group name in your SimpleAnalytics instance.\n```swift\nlet simpleAnalytics = SimpleAnalytics(hostname: \"app.simpleanalytics.com\", sharedDefaultsSuiteName: \"group.com.simpleanlytics.app\")\n```\n\n## Examples\n### SwiftUI example\n In SwiftUI, a good place to put the Pageview tracking code is in your view `.onAppear{}` modifier. \n```swift\nimport SwiftUI\nimport SimpleAnalytics\n\nstruct ContentView: View {\n    var body: some View {\n        VStack {\n            Image(systemName: \"globe\")\n                .imageScale(.large)\n                .foregroundStyle(.tint)\n            Text(\"Hello, world!\")\n        }\n        .padding()\n        .onAppear {\n            SimpleAnalytics.shared.track(path: [\"example\"])\n        }\n    }\n}\n```\n\n### UIKit example\nWhen using UIKit, you can put Pageview tracking in `viewDidAppear()`\n```swift\nimport UIKit\nimport SimpleAnalytics\n\nclass ExampleViewController: UITableViewController {\n    override func viewDidAppear(_ animated: Bool) {\n        super.viewDidAppear(animated)\n        SimpleAnalytics.shared.track(path: [\"example\"])\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpleanalytics%2Fswift-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimpleanalytics%2Fswift-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpleanalytics%2Fswift-package/lists"}