You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: This project is currently in the Pilot phase and is covered by Segment's [First Access & Beta Preview Terms](https://segment.com/legal/first-access-beta-preview/). We encourage you
4
-
to try out this new library. Please provide feedback via Github issues/PRs, and feel free to submit pull requests. This library will eventually
5
-
supplant our `analytics-ios` library, but customers should not use this library for production applications during our Pilot phase.
3
+
NOTE: This project is currently in the Beta phase and is covered by Segment's [First Access & Beta Preview Terms](https://segment.com/legal/first-access-beta-preview/). We encourage you
4
+
to try out this new library. Please provide feedback via Github issues/PRs, and feel free to submit pull requests.
6
5
7
-
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).
6
+
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.
8
7
9
-
## Table of Contents
10
-
-[Installation](#installation)
11
-
-[Usage](#usage)
12
-
- [Setting up the client](#setting-up-the-client)
13
-
- [Client Options](#client-options)
14
-
-[Client Methods](#client-methods)
15
-
- [track](#track)
16
-
- [identify](#identify)
17
-
- [screen](#screen)
18
-
- [group](#group)
19
-
- [add](#add)
20
-
- [find](#find)
21
-
- [remove](#remove)
22
-
- [flush](#flush)
23
-
-[Plugin Architecture](#plugin-architecture)
24
-
- [Fundamentals](#fundamentals)
25
-
- [Advanced Concepts](#advanced-concepts)
26
-
-[Contributing](#contributing)
27
-
-[Code of Conduct](#code-of-conduct)
28
-
-[License](#license)
8
+
## How to get started
9
+
1.**Collect analytics data** from your app(s).
10
+
- The top 200 Segment companies collect data from 5+ source types (web, mobile, server, CRM, etc.).
11
+
2.**Send the data to analytics tools** (for example, Google Analytics, Amplitude, Mixpanel).
12
+
- Over 250+ Segment companies send data to eight categories of destinations such as analytics tools, warehouses, email marketing and remarketing systems, session recording, and more.
13
+
3.**Explore your data** by creating metrics (for example, new signups, retention cohorts, and revenue generation).
14
+
- The best Segment companies use retention cohorts to measure product market fit. Netflix has 70% paid retention after 12 months, 30% after 7 years.
29
15
30
-
## Installation
31
-
Add the Swift package as a dependency either via your package.swift, or via Xcode's File->Swift Packages->Add Package Dependency menu item.
16
+
[Segment](https://segment.com) collects analytics data and allows you to send it to more than 250 apps (such as Google Analytics, Mixpanel, Optimizely, Facebook Ads, Slack, Sentry) just by flipping a switch. You only need one Segment code snippet, and you can turn integrations on and off at will, with no additional code. [Sign up with Segment today](https://app.segment.com/signup).
32
17
33
-
`git@github.com:segmentio/analytics-swift.git`
18
+
### Why?
19
+
1.**Power all your analytics apps with the same data**. Instead of writing code to integrate all of your tools individually, send data to Segment, once.
34
20
35
-
Once completed, Analytics can be referenced by importing Segment's Analytics package
21
+
2.**Install tracking for the last time**. We're the last integration you'll ever need to write. You only need to instrument Segment once. Reduce all of your tracking code and advertising tags into a single set of API calls.
36
22
37
-
`import Segment`
23
+
3.**Send data from anywhere**. Send Segment data from any device, and we'll transform and send it on to any tool.
38
24
39
-
## Usage
40
-
### Setting up the client
41
-
The Analytics client will typically be set up at application launch time, such as `applicationDidFinishLaunching`.
25
+
4.**Query your data in SQL**. Slice, dice, and analyze your data in detail with Segment SQL. We'll transform and load your customer behavioral data directly from your apps into Amazon Redshift, Google BigQuery, or Postgres. Save weeks of engineering time by not having to invent your own data warehouse and ETL pipeline.
42
26
43
-
Typically the following call may be all that's required.
| trackDeepLinks |`true`| automatically track deep links |
67
-
| flushAt |`20`| count of events at which we flush events |
68
-
| flushInterval | `30` (seconds) | interval in seconds at which we flush events
69
-
| defaultSettings | `{}` | Settings object that will be used as fallback in case of network failure
70
-
| autoAddSegmentDestination | `true` | automatically add SegmentDestination plugin, disable in case you want to add plugins to SegmentDestination
71
-
| apiHost | `api.segment.io/v1` | set a default apiHost to which Segment sends event
72
-
73
-
You may notice that some configuration options such as IDFA collection and automatic screen tracking from our previous library have been removed.
74
-
These options have been moved to distinct plugins that can be found in our [Plugin Examples repo](https://github.com/segmentio/analytics-example-plugins/tree/main/plugins/swift).
75
-
## Client Methods
76
-
77
-
### track
78
-
The track method is how you record any actions your users perform, along with any properties that describe the action.
79
-
80
-
Method signatures:
81
-
```swift
82
-
functrack(name: String)
83
-
// This signature provides a typed version of properties.
The identify call lets you tie a user to their actions and record traits about them. This includes a unique user ID and any optional traits you know about them like their email, name, etc. The traits option can include any information you might want to tie to the user, but when using any of the reserved user traits, you should make sure to only use them for their intended meaning.
104
-
105
-
Method signatures:
106
-
```swift
107
-
// These signatures provide for a typed version of user traits
You can enable automatic screen tracking by using the [example plugin](https://github.com/segmentio/analytics-example-plugins/blob/main/plugins/swift/UIKitScreenTracking.swift).
139
-
140
-
Once the plugin has been added to your project add it to your Analytics instance:
141
-
```swift
142
-
analytics.add(plugin: UIKitScreenTracking()
143
-
```
144
-
145
-
### group
146
-
The group API call is how you associate an individual user with a group—be it a company, organization, account, project, team or whatever other crazy name you came up with for the same concept! This includes a unique group ID and anyoptional group traits you know about them like the company name industry, number of employees, etc. The traits option can include any information you might want to tie to the group, but when using any of the reserved group traits, you should make sure to only use them for their intended meaning.
Find a registered plugin from the analytics timeline. It will return the first plugin
185
-
of the specified type.
186
-
187
-
Method signature:
188
-
```swift
189
-
func find<T: Plugin>(pluginType: T.Type) -> T?
190
-
```
191
-
192
-
Example Usage:
193
-
```swift
194
-
let plugin = analytics.find(pluginType: SomePlugin.self)
195
-
```
196
-
197
-
### remove
198
-
Remove a registered plugin from the analytics timeline.
199
-
200
-
Method signature:
201
-
```swift
202
-
funcremove(plugin: Plugin)
203
-
```
204
-
205
-
Example Usage:
206
-
```swift
207
-
analytics.remove(plugin: somePlugin)
208
-
```
209
-
210
-
### flush
211
-
Flushes the current queue of events.
212
-
213
-
Example Usage:
214
-
```swift
215
-
analytics.flush()
216
-
```
217
-
218
-
## Plugin Architecture
219
-
Our new plugin architecture enables you to modify/augment how the analytics client works completely. From modifying event payloads to changing analytics functionality, plugins are the easiest way to get things done.
220
-
Plugins are run through a timeline, which executes plugins in order of insertion based on their types.
221
-
We have the following [types]
222
-
- `before` _Executed before event processing begins_
223
-
- `enrichment` _Executed as the first level of event processing_
224
-
- `destination` _Executed as events begin to pass off to destinations_
225
-
- `after` _Executed after all event processing is completed. This can be used to perform cleanup operations, etc_
226
-
- `utility` _Executed only when called manually, such as Logging_
227
-
228
-
### Fundamentals
229
-
We have 3 types of basic plugins that you can use as a foundation for modifying functionality
230
-
231
-
- `Plugin`
232
-
The most trivial plugin interface that will act on any event payload going through the timeline.
233
-
For example if you wanted to add something to the context object of any event payload as an enrichment.
234
-
```swift
235
-
class SomePlugin: Plugin {
236
-
let type: PluginType = .enrichment
237
-
let analytics: Analytics
238
-
239
-
init() {
240
-
}
241
-
242
-
override fun execute(event: BaseEvent): BaseEvent? {
A plugin interface most commonly used for device-mode destinations. This plugin contains an internal timeline that follows the same process as the analytics timeline,
278
-
allowing you to modify/augment how events reach the particular destination.
279
-
For example if you wanted to implement a device mode destination plugin for AppsFlyer
280
-
```swift
281
-
internalstruct AppsFlyerSettings: Codable {
282
-
let appsFlyerDevKey: String
283
-
let appleAppID: String
284
-
let trackAttributionData: Bool?
285
-
}
286
-
287
-
@objc
288
-
class AppsFlyerDestination: UIResponder, DestinationPlugin, UserActivities, RemoteNotifications {
You can find usage documentation at [https://segment.com/docs/sources/mobile/swift-ios/](https://segment.com/docs/sources/mobile/swift-ios/).
322
46
323
-
### Advanced concepts
324
-
- `update(settings:type:)`
325
-
Use this function to react to any settings updates. This will be implicitly called when settings are updated.
326
-
- OS Lifecycle hooks
327
-
Plugins can also hook into lifecycle events by conforming to the platform appropriate protocol. These functions will get called implicitly as the lifecycle events are processed.
328
-
`iOSLifecycleEvents`
329
-
`macOSLifecycleEvents`
330
-
`watchOSLifecycleEvents`
331
-
`LinuxLifecycleEvents`
332
47
## Contributing
333
48
334
49
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
335
50
51
+
## Integrating with Segment
52
+
53
+
Interested in integrating your service with us? Check out our [Partners page](https://segment.com/partners/) for more details.
54
+
336
55
## Code of Conduct
337
56
338
57
Before contributing, please also see our [code of conduct](CODE_OF_CONDUCT.md).
339
58
340
59
## License
341
-
60
+
```
342
61
MIT License
343
62
344
63
Copyright (c) 2021 Segment
@@ -360,3 +79,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
360
79
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
361
80
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0 commit comments