Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where incorrect segment settings could be built #993

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Segment/Classes/SEGSegmentIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

NS_ASSUME_NONNULL_BEGIN

extern NSString *const kSEGSegmentDestinationName;

extern NSString *const SEGSegmentDidSendRequestNotification;
extern NSString *const SEGSegmentRequestDidSucceedNotification;
extern NSString *const SEGSegmentRequestDidFailNotification;
Expand Down
4 changes: 3 additions & 1 deletion Segment/Classes/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@import UIKit;
#endif

NSString *const kSEGSegmentDestinationName = @"Segment.io";

NSString *const SEGSegmentDidSendRequestNotification = @"SegmentDidSendRequest";
NSString *const SEGSegmentRequestDidSucceedNotification = @"SegmentRequestDidSucceed";
NSString *const SEGSegmentRequestDidFailNotification = @"SegmentRequestDidFail";
Expand Down Expand Up @@ -258,7 +260,7 @@ - (NSDictionary *)integrationsDictionary:(NSDictionary *)integrations
NSMutableDictionary *dict = [integrations ?: @{} mutableCopy];
for (NSString *integration in self.analytics.bundledIntegrations) {
// Don't record Segment.io in the dictionary. It is always enabled.
if ([integration isEqualToString:@"Segment.io"]) {
if ([integration isEqualToString:kSEGSegmentDestinationName]) {
continue;
}
dict[integration] = @NO;
Expand Down
2 changes: 1 addition & 1 deletion Segment/Classes/SEGSegmentIntegrationFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (id)initWithHTTPClient:(SEGHTTPClient *)client fileStorage:(id<SEGStorage>)fil

- (NSString *)key
{
return @"Segment.io";
return kSEGSegmentDestinationName;
}

@end
33 changes: 22 additions & 11 deletions Segment/Internal/SEGIntegrationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "SEGUserDefaultsStorage.h"
#import "SEGIntegrationsManager.h"
#import "SEGSegmentIntegrationFactory.h"
#import "SEGSegmentIntegration.h"
#import "SEGPayload.h"
#import "SEGIdentifyPayload.h"
#import "SEGTrackPayload.h"
Expand Down Expand Up @@ -396,7 +397,7 @@ - (void)setCachedSettings:(NSDictionary *)settings
- (void)updateIntegrationsWithSettings:(NSDictionary *)projectSettings
{
// see if we have a new segment API host and set it.
NSString *apiHost = projectSettings[@"Segment.io"][@"apiHost"];
NSString *apiHost = projectSettings[kSEGSegmentDestinationName][@"apiHost"];
if (apiHost) {
[SEGUtils saveAPIHost:apiHost];
}
Expand Down Expand Up @@ -443,15 +444,25 @@ - (void)configureEdgeFunctions:(NSDictionary *)settings

- (NSDictionary *)defaultSettings
{
return @{
NSDictionary *segment = [self segmentSettings];
NSDictionary *result = @{
@"integrations" : @{
@"Segment.io" : @{
@"apiKey" : self.configuration.writeKey,
@"apiHost" : [SEGUtils getAPIHost]
},
kSEGSegmentDestinationName : segment
},
@"plan" : @{@"track" : @{}}
@"plan" : @{
@"track" : @{}
}
};
return result;
}

- (NSDictionary *)segmentSettings
{
NSDictionary *result = @{
@"apiKey" : self.configuration.writeKey,
@"apiHost" : [SEGUtils getAPIHost]
};
return result;
}

- (void)refreshSettings
Expand Down Expand Up @@ -485,9 +496,9 @@ - (void)refreshSettings
NSMutableDictionary *newSettings = [self.configuration.defaultSettings serializableMutableDeepCopy];
NSMutableDictionary *integrations = newSettings[@"integrations"];
if (integrations != nil) {
integrations[@"Segment.io"] = @{@"apiKey": self.configuration.writeKey, @"apiHost": [SEGUtils getAPIHost]};
integrations[kSEGSegmentDestinationName] = [self segmentSettings];
} else {
newSettings[@"integrations"] = @{@"integrations": @{@"apiKey": self.configuration.writeKey, @"apiHost": [SEGUtils getAPIHost]}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this would only happen if integrations never came down via settings? ie offline mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly.

newSettings[@"integrations"] = @{kSEGSegmentDestinationName: [self segmentSettings]};
}

[self setCachedSettings:newSettings];
Expand All @@ -510,7 +521,7 @@ - (void)refreshSettings
+ (BOOL)isIntegration:(NSString *)key enabledInOptions:(NSDictionary *)options
{
// If the event is in the tracking plan, it should always be sent to api.segment.io.
if ([@"Segment.io" isEqualToString:key]) {
if ([kSEGSegmentDestinationName isEqualToString:key]) {
return YES;
}
if (options[key]) {
Expand Down Expand Up @@ -540,7 +551,7 @@ + (BOOL)isIntegration:(NSString *)key enabledInOptions:(NSDictionary *)options
+ (BOOL)isTrackEvent:(NSString *)event enabledForIntegration:(NSString *)key inPlan:(NSDictionary *)plan
{
// Whether the event is enabled or disabled, it should always be sent to api.segment.io.
if ([key isEqualToString:@"Segment.io"]) {
if ([key isEqualToString:kSEGSegmentDestinationName]) {
return YES;
}

Expand Down