@@ -43,14 +43,14 @@ The Analytics client will typically be set up at application launch time, such a
43
43
Typically the following call may be all that's required.
44
44
45
45
``` swift
46
- Analytics (configuration : Configuration (" SEGMENT_API_KEY " ))
46
+ Analytics (configuration : Configuration (" <YOUR_WRITE_KEY> " ))
47
47
```
48
48
49
49
### Configuration Options
50
50
When creating a new client, you can configure it in various ways. Some examples are listed below.
51
51
52
52
``` swift
53
- let config = Configuration (writeKey : " 8XpdAWa7qJVBJMK8V4FfXQOrnvCzu3Ie " )
53
+ let config = Configuration (writeKey : " <YOUR_WRITE_KEY> " )
54
54
.flushAt (3 )
55
55
.trackApplicationLifecycleEvents (true )
56
56
.flushInterval (10 )
@@ -126,20 +126,20 @@ The screen call lets you record whenever a user sees a screen in your mobile app
126
126
127
127
Method signatures:
128
128
``` swift
129
- func screen (screenTitle : String , category : String ? = nil )
130
- func screen <P : Codable >(screenTitle : String , category : String ? = nil , properties : P? )
129
+ func screen (title : String , category : String ? = nil )
130
+ func screen <P : Codable >(title : String , category : String ? = nil , properties : P? )
131
131
```
132
132
133
133
Example Usage:
134
134
``` swift
135
- analytics.screen (screenTitle : " SomeScreen" )
135
+ analytics.screen (title : " SomeScreen" )
136
136
```
137
137
138
138
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
139
140
140
Once the plugin has been added to your project add it to your Analytics instance:
141
141
``` swift
142
- analytics.add (plugin : UIKitScreenTracking (name : " ScreenTracking " , analytics : analytics) )
142
+ analytics.add (plugin : UIKitScreenTracking ()
143
143
```
144
144
145
145
### group
@@ -167,46 +167,48 @@ analytics.group("user-123", MyTraits(
167
167
```
168
168
169
169
### add
170
- add API allows you to add a plugin to the analytics timeline
170
+ Add API allows you to add a plugin to the analytics timeline. It will return the plugin instance in
171
+ case you wish to store it for access later.
171
172
172
173
Method signature:
173
174
```swift
174
- @discardableResult func add (plugin : Plugin) -> String
175
+ @discardableResult func add (plugin : Plugin) -> Plugin
175
176
```
176
177
177
178
Example Usage:
178
179
```swift
179
- analytics.add (plugin : UIKitScreenTracking (name : " ScreenTracking " ))
180
+ analytics.add (plugin : UIKitScreenTracking ())
180
181
```
181
182
182
183
### find
183
- find a registered plugin from the analytics timeline
184
+ Find a registered plugin from the analytics timeline. It will return the first plugin
185
+ of the specified type.
184
186
185
187
Method signature:
186
188
```swift
187
- func find ( pluginName : String ) -> Plugin ?
189
+ func find< T : Plugin > ( pluginType : T. Type ) -> T ?
188
190
```
189
191
190
192
Example Usage:
191
193
```swift
192
- let plugin = analytics.find (" SomePlugin" )
194
+ let plugin = analytics.find (pluginType : SomePlugin. self )
193
195
```
194
196
195
197
### remove
196
- remove a registered plugin from the analytics timeline
198
+ Remove a registered plugin from the analytics timeline.
197
199
198
200
Method signature:
199
201
```swift
200
- func remove (pluginName : String )
202
+ func remove (plugin : Plugin )
201
203
```
202
204
203
205
Example Usage:
204
206
```swift
205
- analytics.remove (" SomePlugin " )
207
+ analytics.remove (plugin : somePlugin )
206
208
```
207
209
208
210
### flush
209
- flushes the current queue of events
211
+ Flushes the current queue of events.
210
212
211
213
Example Usage:
212
214
```swift
@@ -232,11 +234,9 @@ For example if you wanted to add something to the context object of any event pa
232
234
```swift
233
235
class SomePlugin: Plugin {
234
236
let type: PluginType = .enrichment
235
- let name: String
236
237
let analytics: Analytics
237
238
238
- init (name : String ) {
239
- self .name = name
239
+ init () {
240
240
}
241
241
242
242
override fun execute (event : BaseEvent): BaseEvent? {
@@ -256,11 +256,9 @@ For example if you only wanted to act on `track` & `identify` events
256
256
```swift
257
257
class SomePlugin: EventPlugin {
258
258
let type: PluginType = .enrichment
259
- let name: String
260
259
let analytics: Analytics
261
260
262
- init (name : String ) {
263
- self .name = name
261
+ init () {
264
262
}
265
263
266
264
func identify (event : IdentifyEvent) -> IdentifyEvent? {
@@ -291,26 +289,26 @@ class AppsFlyerDestination: UIResponder, DestinationPlugin, UserActivities, Remo
291
289
292
290
let timeline: Timeline = Timeline ()
293
291
let type: PluginType = .destination
294
- let name : String
292
+ let key : String = " AppsFlyer "
295
293
var analytics: Analytics?
296
294
297
295
internal var settings: AppsFlyerSettings? = nil
298
296
299
- required init (name : String ) {
300
- self .name = name
301
- analytics? .track (name : " AppsFlyer Loaded" )
297
+ init () {
302
298
}
303
299
304
300
public func update (settings : Settings, type : UpdateType) {
305
301
if type == .initial {
306
302
// AppsFlyerLib is a singleton, we only want to set it up once.
307
- guard let settings: AppsFlyerSettings = settings.integrationSettings (name : " AppsFlyer " ) else {return }
303
+ guard let settings: AppsFlyerSettings = settings.integrationSettings (key : self . name ) else {return }
308
304
self .settings = settings
309
305
310
306
AppsFlyerLib.shared ().appsFlyerDevKey = settings.appsFlyerDevKey
311
307
AppsFlyerLib.shared ().appleAppID = settings.appleAppID
312
308
AppsFlyerLib.shared ().isDebug = true
313
309
AppsFlyerLib.shared ().deepLinkDelegate = self
310
+
311
+ analytics? .track (name : " AppsFlyer Loaded" )
314
312
}
315
313
316
314
// additional update logic
@@ -323,7 +321,7 @@ analytics.track("AppsFlyer Event")
323
321
```
324
322
325
323
### Advanced concepts
326
- - `update (settings: )`
324
+ - `update (settings:type: )`
327
325
Use this function to react to any settings updates. This will be implicitly called when settings are updated.
328
326
- OS Lifecycle hooks
329
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.
0 commit comments