Skip to content

Commit 8328299

Browse files
committed
Actually send custom context fields
1 parent abbc9a6 commit 8328299

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

Analytics/Integrations/Segmentio/SEGSegmentioIntegration.m

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ - (id)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration {
104104

105105
- (NSDictionary *)staticContext {
106106
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
107-
107+
108108
dict[@"library"] = @{ @"name": @"analytics-ios", @"version": SEGStringize(ANALYTICS_VERSION) };
109-
109+
110110
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
111111
if (infoDictionary.count) {
112112
dict[@"app"] = @{
@@ -116,9 +116,9 @@ - (NSDictionary *)staticContext {
116116
@"namespace": [[NSBundle mainBundle] bundleIdentifier] ?: @"",
117117
};
118118
}
119-
119+
120120
UIDevice *device = [UIDevice currentDevice];
121-
121+
122122
dict[@"device"] = ({
123123
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
124124
dict[@"manufacturer"] = @"Apple";
@@ -133,22 +133,22 @@ - (NSDictionary *)staticContext {
133133
}
134134
dict;
135135
});
136-
136+
137137
dict[@"os"] = @{
138138
@"name" : device.systemName,
139139
@"version" : device.systemVersion
140140
};
141-
141+
142142
CTCarrier *carrier = [[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider];
143143
if (carrier.carrierName.length)
144144
dict[@"network"] = @{ @"carrier": carrier.carrierName };
145-
145+
146146
CGSize screenSize = [UIScreen mainScreen].bounds.size;
147147
dict[@"screen"] = @{
148148
@"width": @(screenSize.width),
149149
@"height": @(screenSize.height)
150150
};
151-
151+
152152
#if !(TARGET_IPHONE_SIMULATOR)
153153
Class adClient = NSClassFromString(SEGADClientClass);
154154
if (adClient) {
@@ -167,48 +167,48 @@ - (NSDictionary *)staticContext {
167167
#pragma clang diagnostic pop
168168
}
169169
#endif
170-
170+
171171
return dict;
172172
}
173173

174174
- (NSMutableDictionary *)liveContext {
175175
NSMutableDictionary *context = [[NSMutableDictionary alloc] init];
176-
176+
177177
[context addEntriesFromDictionary:self.context];
178-
178+
179179
context[@"locale"] = [NSString stringWithFormat:
180180
@"%@-%@",
181181
[NSLocale.currentLocale objectForKey:NSLocaleLanguageCode],
182182
[NSLocale.currentLocale objectForKey:NSLocaleCountryCode]];
183-
183+
184184
context[@"timezone"] = [[NSTimeZone localTimeZone] name];
185-
185+
186186
context[@"network"] = ({
187187
NSMutableDictionary *network = [[NSMutableDictionary alloc] init];
188-
188+
189189
if (self.bluetooth.hasKnownState)
190190
network[@"bluetooth"] = @(self.bluetooth.isEnabled);
191-
191+
192192
if (self.reachability.isReachable){
193193
network[@"wifi"] = @(self.reachability.isReachableViaWiFi);
194194
network[@"cellular"] = @(self.reachability.isReachableViaWWAN);
195195
}
196-
196+
197197
network;
198198
});
199-
199+
200200
if (self.location.hasKnownLocation)
201201
context[@"location"] = self.location.locationDictionary;
202-
202+
203203
context[@"traits"] = ({
204204
NSMutableDictionary *traits = [[NSMutableDictionary alloc] initWithDictionary:[self traits]];
205-
205+
206206
if (self.location.hasKnownLocation)
207207
traits[@"address"] = self.location.addressDictionary;
208-
208+
209209
traits;
210210
});
211-
211+
212212
return context;
213213
}
214214

@@ -222,7 +222,7 @@ - (void)dispatchBackgroundAndWait:(void(^)(void))block {
222222

223223
- (void)beginBackgroundTask {
224224
[self endBackgroundTask];
225-
225+
226226
self.flushTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
227227
[self endBackgroundTask];
228228
}];
@@ -266,13 +266,13 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDic
266266
[self saveUserId:userId];
267267
[self addTraits:traits];
268268
}];
269-
269+
270270
[self enqueueAction:@"identify" dictionary:@{ @"traits": traits } options:options];
271271
}
272272

273273
- (void)track:(NSString *)event properties:(NSDictionary *)properties options:(NSDictionary *)options {
274274
NSCParameterAssert(event.length > 0);
275-
275+
276276
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
277277
[dictionary setValue:event forKey:@"event"];
278278
[dictionary setValue:properties forKey:@"properties"];
@@ -282,21 +282,21 @@ - (void)track:(NSString *)event properties:(NSDictionary *)properties options:(N
282282

283283
- (void)screen:(NSString *)screenTitle properties:(NSDictionary *)properties options:(NSDictionary *)options {
284284
NSCParameterAssert(screenTitle.length > 0);
285-
285+
286286
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
287287
[dictionary setValue:screenTitle forKey:@"name"];
288288
[dictionary setValue:properties forKey:@"properties"];
289-
289+
290290
[self enqueueAction:@"screen" dictionary:dictionary options:options];
291291
}
292292

293293
- (void)group:(NSString *)groupId traits:(NSDictionary *)traits options:(NSDictionary *)options {
294294
NSCParameterAssert(groupId.length > 0);
295-
295+
296296
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
297297
[dictionary setValue:groupId forKey:@"groupId"];
298298
[dictionary setValue:traits forKey:@"traits"];
299-
299+
300300
[self enqueueAction:@"group" dictionary:dictionary options:options];
301301
}
302302

@@ -312,7 +312,7 @@ - (void)alias:(NSString *)newId options:(NSDictionary *)options {
312312

313313
- (void)registerForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken options:(NSDictionary *)options {
314314
NSCParameterAssert(deviceToken != nil);
315-
315+
316316
const unsigned char *buffer = (const unsigned char *)[deviceToken bytes];
317317
if (!buffer) {
318318
return;
@@ -343,7 +343,7 @@ - (void)enqueueAction:(NSString *)action dictionary:(NSDictionary *)dictionary o
343343
payload[@"type"] = action;
344344
payload[@"timestamp"] = [[NSDate date] description];
345345
payload[@"messageId"] = GenerateUUIDString();
346-
346+
347347
[self dispatchBackground:^{
348348
// attach userId and anonymousId inside the dispatch_async in case
349349
// they've changed (see identify function)
@@ -358,7 +358,7 @@ - (void)enqueueAction:(NSString *)action dictionary:(NSDictionary *)dictionary o
358358
NSMutableDictionary *context = [NSMutableDictionary dictionaryWithCapacity:capacity];
359359
[context addEntriesFromDictionary:defaultContext];
360360
[context addEntriesFromDictionary:customContext]; // let the custom context override ours
361-
[payload setValue:[self liveContext] forKey:@"context"];
361+
[payload setValue:[self context] forKey:@"context"];
362362

363363
SEGLog(@"%@ Enqueueing action: %@", self, payload);
364364
[self queuePayload:payload];
@@ -388,17 +388,17 @@ - (void)flushWithMaxSize:(NSUInteger)maxBatchSize {
388388
} else {
389389
self.batch = [NSArray arrayWithArray:self.queue];
390390
}
391-
391+
392392
SEGLog(@"%@ Flushing %lu of %lu queued API calls.", self, (unsigned long)self.batch.count, (unsigned long)self.queue.count);
393-
393+
394394
NSMutableDictionary *payloadDictionary = [NSMutableDictionary dictionary];
395395
[payloadDictionary setObject:self.configuration.writeKey forKey:@"writeKey"];
396396
[payloadDictionary setObject:[[NSDate date] description] forKey:@"sentAt"];
397397
[payloadDictionary setObject:self.context forKey:@"context"];
398398
[payloadDictionary setObject:self.batch forKey:@"batch"];
399-
399+
400400
SEGLog(@"Flushing payload %@", payloadDictionary);
401-
401+
402402
NSError *error = nil;
403403
NSException *exception = nil;
404404
NSData *payload = nil;
@@ -419,7 +419,7 @@ - (void)flushWithMaxSize:(NSUInteger)maxBatchSize {
419419
- (void)flushQueueByLength {
420420
[self dispatchBackground:^{
421421
SEGLog(@"%@ Length is %lu.", self, (unsigned long)self.queue.count);
422-
422+
423423
if (self.request == nil && [self.queue count] >= self.configuration.flushAt) {
424424
[self flush];
425425
}
@@ -452,7 +452,7 @@ - (void)sendData:(NSData *)data {
452452
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
453453
[urlRequest setHTTPMethod:@"POST"];
454454
[urlRequest setHTTPBody:data];
455-
455+
456456
SEGLog(@"%@ Sending batch API request.", self);
457457
self.request = [SEGAnalyticsRequest startWithURLRequest:urlRequest completion:^{
458458
[self dispatchBackground:^{
@@ -466,7 +466,7 @@ - (void)sendData:(NSData *)data {
466466
[self.queue writeToURL:[self queueURL] atomically:YES];
467467
[self notifyForName:SEGSegmentioRequestDidSucceedNotification userInfo:self.batch];
468468
}
469-
469+
470470
self.batch = nil;
471471
self.request = nil;
472472
[self endBackgroundTask];
@@ -532,7 +532,7 @@ - (void)setConfiguration:(SEGAnalyticsConfiguration *)configuration {
532532
[self.configuration removeObserver:self forKeyPath:@"shouldUseLocationServices"];
533533
[self.configuration removeObserver:self forKeyPath:@"enableAdvertisingTracking"];
534534
}
535-
535+
536536
[super setConfiguration:configuration];
537537
[self.configuration addObserver:self forKeyPath:@"shouldUseLocationServices" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew context:NULL];
538538
[self.configuration addObserver:self forKeyPath:@"enableAdvertisingTracking" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew context:NULL];

0 commit comments

Comments
 (0)