31
31
static NSString *const SEGCachedSettingsKey = @" analytics.settings.v2.plist" ;
32
32
33
33
34
- @interface SEGAnalyticsConfiguration (Private)
34
+ @interface SEGIdentifyPayload (AnonymousId)
35
+ @property (nonatomic , readwrite , nullable ) NSString *anonymousId;
36
+ @end
37
+
38
+
39
+ @interface SEGPayload (Options)
40
+ @property (readonly ) NSDictionary *options;
41
+ @end
42
+ @implementation SEGPayload (Options)
43
+ // Combine context and integrations to form options
44
+ - (NSDictionary *)options
45
+ {
46
+ return @{
47
+ @" context" : self.context ?: @{},
48
+ @" integrations" : self.integrations ?: @{}
49
+ };
50
+ }
51
+ @end
35
52
36
- @property (nonatomic , strong ) NSArray *factories;
37
53
54
+ @interface SEGAnalyticsConfiguration (Private)
55
+ @property (nonatomic , strong ) NSArray *factories;
38
56
@end
39
57
40
58
@@ -153,10 +171,37 @@ - (NSString *)description
153
171
154
172
#pragma mark - Analytics API
155
173
174
+ - (void )identify : (SEGIdentifyPayload *)payload
175
+ {
176
+ NSCAssert2 (payload.userId.length > 0 || payload.traits.count > 0 , @" either userId (%@ ) or traits (%@ ) must be provided." , payload.userId, payload.traits);
177
+
178
+ NSString *anonymousId = payload.anonymousId ;
179
+ if (anonymousId) {
180
+ [self saveAnonymousId: anonymousId];
181
+ } else {
182
+ anonymousId = self.cachedAnonymousId ;
183
+ }
184
+ payload.anonymousId = anonymousId;
185
+
186
+ [self callIntegrationsWithSelector: NSSelectorFromString (@" identify:" )
187
+ arguments: @[ payload ]
188
+ options: payload.options
189
+ sync: false ];
190
+ }
191
+ /*
156
192
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
157
193
{
158
194
NSCAssert2(userId.length > 0 || traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", userId, traits);
159
195
196
+ NSDictionary *options;
197
+ if (p.anonymousId) {
198
+ NSMutableDictionary *mutableOptions = [[NSMutableDictionary alloc] initWithDictionary:p.options];
199
+ mutableOptions[@"anonymousId"] = p.anonymousId;
200
+ options = [mutableOptions copy];
201
+ } else {
202
+ options = p.options;
203
+ }
204
+
160
205
NSString *anonymousId = [options objectForKey:@"anonymousId"];
161
206
if (anonymousId) {
162
207
[self saveAnonymousId:anonymousId];
@@ -174,68 +219,49 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDic
174
219
arguments:@[ payload ]
175
220
options:options
176
221
sync:false];
177
- }
222
+ }*/
178
223
179
224
#pragma mark - Track
180
225
181
- - (void )track : (NSString *)event properties : ( NSDictionary *) properties options : ( NSDictionary *) options
226
+ - (void )track : (SEGTrackPayload *)payload
182
227
{
183
- NSCAssert1 (event.length > 0 , @" event (%@ ) must not be empty." , event);
184
-
185
- SEGTrackPayload *payload = [[SEGTrackPayload alloc ] initWithEvent: event
186
- properties: SEGCoerceDictionary (properties)
187
- context: SEGCoerceDictionary ([options objectForKey: @" context" ])
188
- integrations: [options objectForKey: @" integrations" ]];
228
+ NSCAssert1 (payload.event.length > 0 , @" event (%@ ) must not be empty." , payload.event);
189
229
190
230
[self callIntegrationsWithSelector: NSSelectorFromString (@" track:" )
191
231
arguments: @[ payload ]
192
- options: options
232
+ options: payload. options
193
233
sync: false ];
194
234
}
195
235
196
236
#pragma mark - Screen
197
237
198
- - (void )screen : (NSString *)screenTitle properties : ( NSDictionary *) properties options : ( NSDictionary *) options
238
+ - (void )screen : (SEGScreenPayload *)payload
199
239
{
200
- NSCAssert1 (screenTitle.length > 0 , @" screen name (%@ ) must not be empty." , screenTitle);
201
-
202
- SEGScreenPayload *payload = [[SEGScreenPayload alloc ] initWithName: screenTitle
203
- properties: SEGCoerceDictionary (properties)
204
- context: SEGCoerceDictionary ([options objectForKey: @" context" ])
205
- integrations: [options objectForKey: @" integrations" ]];
240
+ NSCAssert1 (payload.name.length > 0 , @" screen name (%@ ) must not be empty." , payload.name);
206
241
207
242
[self callIntegrationsWithSelector: NSSelectorFromString (@" screen:" )
208
243
arguments: @[ payload ]
209
- options: options
244
+ options: payload. options
210
245
sync: false ];
211
246
}
212
247
213
248
#pragma mark - Group
214
249
215
- - (void )group : (NSString *)groupId traits : ( NSDictionary *) traits options : ( NSDictionary *) options
250
+ - (void )group : (SEGGroupPayload *)payload
216
251
{
217
- SEGGroupPayload *payload = [[SEGGroupPayload alloc ] initWithGroupId: groupId
218
- traits: SEGCoerceDictionary (traits)
219
- context: SEGCoerceDictionary ([options objectForKey: @" context" ])
220
- integrations: [options objectForKey: @" integrations" ]];
221
-
222
252
[self callIntegrationsWithSelector: NSSelectorFromString (@" group:" )
223
253
arguments: @[ payload ]
224
- options: options
254
+ options: payload. options
225
255
sync: false ];
226
256
}
227
257
228
258
#pragma mark - Alias
229
259
230
- - (void )alias : (NSString *)newId options : ( NSDictionary *) options
260
+ - (void )alias : (SEGAliasPayload *)payload
231
261
{
232
- SEGAliasPayload *payload = [[SEGAliasPayload alloc ] initWithNewId: newId
233
- context: SEGCoerceDictionary ([options objectForKey: @" context" ])
234
- integrations: [options objectForKey: @" integrations" ]];
235
-
236
262
[self callIntegrationsWithSelector: NSSelectorFromString (@" alias:" )
237
263
arguments: @[ payload ]
238
- options: options
264
+ options: payload. options
239
265
sync: false ];
240
266
}
241
267
@@ -550,32 +576,15 @@ - (void)callIntegrationsWithSelector:(SEL)selector arguments:(NSArray *)argument
550
576
@end
551
577
552
578
553
- @interface SEGPayload (Options)
554
- @property (readonly ) NSDictionary *options;
555
- @end
556
-
557
-
558
- @implementation SEGPayload (Options)
559
-
560
- // Combine context and integrations to form options
561
- - (NSDictionary *)options
562
- {
563
- return @{
564
- @" context" : self.context ?: @{},
565
- @" integrations" : self.integrations ?: @{}
566
- };
567
- }
568
-
569
- @end
570
-
571
-
572
579
@implementation SEGIntegrationsManager (SEGMiddleware)
573
580
574
581
- (void )context : (SEGContext *)context next : (void (^_Nonnull)(SEGContext *_Nullable))next
575
582
{
576
583
switch (context.eventType ) {
577
584
case SEGEventTypeIdentify: {
578
585
SEGIdentifyPayload *p = (SEGIdentifyPayload *)context.payload ;
586
+ [self identify: p];
587
+ /*
579
588
NSDictionary *options;
580
589
if (p.anonymousId) {
581
590
NSMutableDictionary *mutableOptions = [[NSMutableDictionary alloc] initWithDictionary:p.options];
@@ -584,27 +593,27 @@ - (void)context:(SEGContext *)context next:(void (^_Nonnull)(SEGContext *_Nullab
584
593
} else {
585
594
options = p.options;
586
595
}
587
- [self identify: p.userId traits: p.traits options: options];
596
+ [self identify:p.userId traits:p.traits options:options];*/
588
597
break ;
589
598
}
590
599
case SEGEventTypeTrack: {
591
600
SEGTrackPayload *p = (SEGTrackPayload *)context.payload ;
592
- [self track: p.event properties: p.properties options: p.options ];
601
+ [self track: p];
593
602
break ;
594
603
}
595
604
case SEGEventTypeScreen: {
596
605
SEGScreenPayload *p = (SEGScreenPayload *)context.payload ;
597
- [self screen: p.name properties: p.properties options: p.options ];
606
+ [self screen: p];
598
607
break ;
599
608
}
600
609
case SEGEventTypeGroup: {
601
610
SEGGroupPayload *p = (SEGGroupPayload *)context.payload ;
602
- [self group: p.groupId traits: p.traits options: p.options ];
611
+ [self group: p];
603
612
break ;
604
613
}
605
614
case SEGEventTypeAlias: {
606
615
SEGAliasPayload *p = (SEGAliasPayload *)context.payload ;
607
- [self alias: p.theNewId options: p.options ];
616
+ [self alias: p];
608
617
break ;
609
618
}
610
619
case SEGEventTypeReset:
0 commit comments