Skip to content

Commit d9f5ca9

Browse files
bsneedBrandon Sneed
andauthored
Fixed issue where incorrect segment settings could be built (#993)
* Fixed issue where incorrect segment settings could be built * Modified to use the segment destination name constant Co-authored-by: Brandon Sneed <[email protected]>
1 parent 7eefc66 commit d9f5ca9

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

Segment/Classes/SEGSegmentIntegration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
NS_ASSUME_NONNULL_BEGIN
77

8+
extern NSString *const kSEGSegmentDestinationName;
9+
810
extern NSString *const SEGSegmentDidSendRequestNotification;
911
extern NSString *const SEGSegmentRequestDidSucceedNotification;
1012
extern NSString *const SEGSegmentRequestDidFailNotification;

Segment/Classes/SEGSegmentIntegration.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@import UIKit;
1414
#endif
1515

16+
NSString *const kSEGSegmentDestinationName = @"Segment.io";
17+
1618
NSString *const SEGSegmentDidSendRequestNotification = @"SegmentDidSendRequest";
1719
NSString *const SEGSegmentRequestDidSucceedNotification = @"SegmentRequestDidSucceed";
1820
NSString *const SEGSegmentRequestDidFailNotification = @"SegmentRequestDidFail";
@@ -258,7 +260,7 @@ - (NSDictionary *)integrationsDictionary:(NSDictionary *)integrations
258260
NSMutableDictionary *dict = [integrations ?: @{} mutableCopy];
259261
for (NSString *integration in self.analytics.bundledIntegrations) {
260262
// Don't record Segment.io in the dictionary. It is always enabled.
261-
if ([integration isEqualToString:@"Segment.io"]) {
263+
if ([integration isEqualToString:kSEGSegmentDestinationName]) {
262264
continue;
263265
}
264266
dict[integration] = @NO;

Segment/Classes/SEGSegmentIntegrationFactory.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ - (id)initWithHTTPClient:(SEGHTTPClient *)client fileStorage:(id<SEGStorage>)fil
2121

2222
- (NSString *)key
2323
{
24-
return @"Segment.io";
24+
return kSEGSegmentDestinationName;
2525
}
2626

2727
@end

Segment/Internal/SEGIntegrationsManager.m

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "SEGUserDefaultsStorage.h"
2222
#import "SEGIntegrationsManager.h"
2323
#import "SEGSegmentIntegrationFactory.h"
24+
#import "SEGSegmentIntegration.h"
2425
#import "SEGPayload.h"
2526
#import "SEGIdentifyPayload.h"
2627
#import "SEGTrackPayload.h"
@@ -396,7 +397,7 @@ - (void)setCachedSettings:(NSDictionary *)settings
396397
- (void)updateIntegrationsWithSettings:(NSDictionary *)projectSettings
397398
{
398399
// see if we have a new segment API host and set it.
399-
NSString *apiHost = projectSettings[@"Segment.io"][@"apiHost"];
400+
NSString *apiHost = projectSettings[kSEGSegmentDestinationName][@"apiHost"];
400401
if (apiHost) {
401402
[SEGUtils saveAPIHost:apiHost];
402403
}
@@ -443,15 +444,25 @@ - (void)configureEdgeFunctions:(NSDictionary *)settings
443444

444445
- (NSDictionary *)defaultSettings
445446
{
446-
return @{
447+
NSDictionary *segment = [self segmentSettings];
448+
NSDictionary *result = @{
447449
@"integrations" : @{
448-
@"Segment.io" : @{
449-
@"apiKey" : self.configuration.writeKey,
450-
@"apiHost" : [SEGUtils getAPIHost]
451-
},
450+
kSEGSegmentDestinationName : segment
452451
},
453-
@"plan" : @{@"track" : @{}}
452+
@"plan" : @{
453+
@"track" : @{}
454+
}
455+
};
456+
return result;
457+
}
458+
459+
- (NSDictionary *)segmentSettings
460+
{
461+
NSDictionary *result = @{
462+
@"apiKey" : self.configuration.writeKey,
463+
@"apiHost" : [SEGUtils getAPIHost]
454464
};
465+
return result;
455466
}
456467

457468
- (void)refreshSettings
@@ -485,9 +496,9 @@ - (void)refreshSettings
485496
NSMutableDictionary *newSettings = [self.configuration.defaultSettings serializableMutableDeepCopy];
486497
NSMutableDictionary *integrations = newSettings[@"integrations"];
487498
if (integrations != nil) {
488-
integrations[@"Segment.io"] = @{@"apiKey": self.configuration.writeKey, @"apiHost": [SEGUtils getAPIHost]};
499+
integrations[kSEGSegmentDestinationName] = [self segmentSettings];
489500
} else {
490-
newSettings[@"integrations"] = @{@"integrations": @{@"apiKey": self.configuration.writeKey, @"apiHost": [SEGUtils getAPIHost]}};
501+
newSettings[@"integrations"] = @{kSEGSegmentDestinationName: [self segmentSettings]};
491502
}
492503

493504
[self setCachedSettings:newSettings];
@@ -510,7 +521,7 @@ - (void)refreshSettings
510521
+ (BOOL)isIntegration:(NSString *)key enabledInOptions:(NSDictionary *)options
511522
{
512523
// If the event is in the tracking plan, it should always be sent to api.segment.io.
513-
if ([@"Segment.io" isEqualToString:key]) {
524+
if ([kSEGSegmentDestinationName isEqualToString:key]) {
514525
return YES;
515526
}
516527
if (options[key]) {
@@ -540,7 +551,7 @@ + (BOOL)isIntegration:(NSString *)key enabledInOptions:(NSDictionary *)options
540551
+ (BOOL)isTrackEvent:(NSString *)event enabledForIntegration:(NSString *)key inPlan:(NSDictionary *)plan
541552
{
542553
// Whether the event is enabled or disabled, it should always be sent to api.segment.io.
543-
if ([key isEqualToString:@"Segment.io"]) {
554+
if ([key isEqualToString:kSEGSegmentDestinationName]) {
544555
return YES;
545556
}
546557

0 commit comments

Comments
 (0)