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

Remove the ability to natively report attribution information via Segment integrations #941

Merged
merged 1 commit into from
Sep 17, 2020
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
5 changes: 0 additions & 5 deletions Analytics/Classes/SEGAnalyticsConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ NS_SWIFT_NAME(AnalyticsConfiguration)
*/
@property (nonatomic, assign) BOOL trackDeepLinks;

/**
* Whether the analytics client should automatically track attribution data from enabled providers using the mobile service.
*/
@property (nonatomic, assign) BOOL trackAttributionData;

/**
* Dictionary indicating the options the app was launched with.
*/
Expand Down
4 changes: 0 additions & 4 deletions Analytics/Classes/SEGHTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
// NOTE: `/` at the end kind of screws things up. So don't use it
//#define SEGMENT_API_BASE [NSURL URLWithString:@"https://api-segment-io-5fsaj1xnikhp.runscope.net/v1"]
//#define SEGMENT_CDN_BASE [NSURL URLWithString:@"https://cdn-segment-com-5fsaj1xnikhp.runscope.net/v1"]
//#define MOBILE_SERVICE_BASE [NSURL URLWithString:@"https://mobile--service-segment-com-5fsaj1xnikhp.runscope.net/v1"]
#define SEGMENT_API_BASE [NSURL URLWithString:@"https://api.segment.io/v1"]
#define SEGMENT_CDN_BASE [NSURL URLWithString:@"https://cdn-settings.segment.com/v1"]
#define MOBILE_SERVICE_BASE [NSURL URLWithString:@"https://mobile-service.segment.com/v1"]

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -38,8 +36,6 @@ NS_SWIFT_NAME(HTTPClient)

- (NSURLSessionDataTask *)settingsForWriteKey:(NSString *)writeKey completionHandler:(void (^)(BOOL success, JSON_DICT _Nullable settings))completionHandler;

- (NSURLSessionDataTask *)attributionWithWriteKey:(NSString *)writeKey forDevice:(JSON_DICT)context completionHandler:(void (^)(BOOL success, JSON_DICT _Nullable properties))completionHandler;

@end

NS_ASSUME_NONNULL_END
53 changes: 0 additions & 53 deletions Analytics/Classes/SEGHTTPClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,57 +178,4 @@ - (NSURLSessionDataTask *)settingsForWriteKey:(NSString *)writeKey completionHan
return task;
}

- (NSURLSessionDataTask *)attributionWithWriteKey:(NSString *)writeKey forDevice:(JSON_DICT)context completionHandler:(void (^)(BOOL success, JSON_DICT _Nullable properties))completionHandler;

{
NSURLSession *session = [self sessionForWriteKey:writeKey];

NSURL *url = [MOBILE_SERVICE_BASE URLByAppendingPathComponent:@"/attribution"];
NSMutableURLRequest *request = self.requestFactory(url);
[request setHTTPMethod:@"POST"];

NSError *error = nil;
NSException *exception = nil;
NSData *payload = nil;
@try {
payload = [NSJSONSerialization dataWithJSONObject:context options:0 error:&error];
}
@catch (NSException *exc) {
exception = exc;
}
if (error || exception) {
SEGLog(@"Error serializing context to JSON %@", error);
completionHandler(NO, nil);
return nil;
}
NSData *gzippedPayload = [payload seg_gzippedData];

NSURLSessionUploadTask *task = [session uploadTaskWithRequest:request fromData:gzippedPayload completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
if (error) {
SEGLog(@"Error making request %@.", error);
completionHandler(NO, nil);
return;
}

NSInteger code = ((NSHTTPURLResponse *)response).statusCode;
if (code > 300) {
SEGLog(@"Server responded with unexpected HTTP code %d.", code);
completionHandler(NO, nil);
return;
}

NSError *jsonError = nil;
id responseJson = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (jsonError != nil) {
SEGLog(@"Error deserializing response body %@.", jsonError);
completionHandler(NO, nil);
return;
}

completionHandler(YES, responseJson);
}];
[task resume];
return task;
}

@end
32 changes: 0 additions & 32 deletions Analytics/Classes/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ @interface SEGSegmentIntegration ()
@property (nonatomic, strong) SEGHTTPClient *httpClient;
@property (nonatomic, strong) id<SEGStorage> fileStorage;
@property (nonatomic, strong) id<SEGStorage> userDefaultsStorage;
@property (nonatomic, strong) NSURLSessionDataTask *attributionRequest;

#if TARGET_OS_IPHONE
@property (nonatomic, assign) UIBackgroundTaskIdentifier flushTaskID;
Expand Down Expand Up @@ -95,9 +94,6 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)ht
}
#endif
}];
[self dispatchBackground:^{
[self trackAttributionData:self.configuration.trackAttributionData];
}];

self.flushTimer = [NSTimer timerWithTimeInterval:self.configuration.flushInterval
target:self
Expand Down Expand Up @@ -502,32 +498,4 @@ - (void)persistQueue
[self.fileStorage setArray:[self.queue copy] forKey:kSEGQueueFilename];
}

NSString *const SEGTrackedAttributionKey = @"SEGTrackedAttributionKey";

- (void)trackAttributionData:(BOOL)trackAttributionData
{
#if TARGET_OS_IPHONE
if (!trackAttributionData) {
return;
}

BOOL trackedAttribution = [[NSUserDefaults standardUserDefaults] boolForKey:SEGTrackedAttributionKey];
if (trackedAttribution) {
return;
}

NSDictionary *context = [SEGState sharedInstance].context.payload;

self.attributionRequest = [self.httpClient attributionWithWriteKey:self.configuration.writeKey forDevice:[context copy] completionHandler:^(BOOL success, NSDictionary *properties) {
[self dispatchBackground:^{
if (success) {
[self.analytics track:@"Install Attributed" properties:properties];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:SEGTrackedAttributionKey];
}
self.attributionRequest = nil;
}];
}];
#endif
}

@end
46 changes: 0 additions & 46 deletions AnalyticsTests/HTTPClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,50 +204,4 @@ class HTTPClientTest: XCTestCase {
}
wait(for: [doneExpectation], timeout: 1.0)
}

func testAttributionFailsForJSONError() {
let device = [
// Dates cannot be serialized as is so the json serialzation will fail.
"sentAt": NSDate(),
]
let doneExpectation = expectation(description: "Done with url session task")
_ = client.attribution(withWriteKey: "bar", forDevice: device) { success, properties in
XCTAssertFalse(success, "Retry should be false")
doneExpectation.fulfill()
}
wait(for: [doneExpectation], timeout: 1.0)
}

func testAttributionSucceedsFor2xx() {
_ = stubRequest("POST", "https://mobile-service.segment.com/v1/attribution" as NSString)
.withHeader("User-Agent", "analytics-ios/" + Analytics.version())!
.withWriteKey("foo")
.andReturn(200)!
.withBody("{\"provider\": \"mock\"}" as NSString)

let doneExpectation = expectation(description: "Done with url session task")
_ = client.attribution(withWriteKey: "foo", forDevice: context) { success, properties in
XCTAssert(success, "Success should be true")
XCTAssertEqual(properties as? [String: String], [
"provider": "mock"
])
doneExpectation.fulfill()
}
wait(for: [doneExpectation], timeout: 1.0)
}

func testAttributionFailsForNon2xx() {
_ = stubRequest("POST", "https://mobile-service.segment.com/v1/attribution" as NSString)
.withHeader("User-Agent", "analytics-ios/" + Analytics.version())!
.withWriteKey("foo")
.andReturn(404)!
.withBody("not found" as NSString)
let doneExpectation = expectation(description: "Done with url session task")
_ = client.attribution(withWriteKey: "foo", forDevice: context) { success, properties in
XCTAssertFalse(success, "Success should be false")
XCTAssertNil(properties, "Properties should be nil")
doneExpectation.fulfill()
}
wait(for: [doneExpectation], timeout: 1.0)
}
}
1 change: 0 additions & 1 deletion Examples/CocoapodsExample/CocoapodsExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[SEGAnalytics debug:YES];
SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:SEGMENT_WRITE_KEY];
configuration.trackApplicationLifecycleEvents = YES;
configuration.trackAttributionData = YES;
configuration.flushAt = 1;
[SEGAnalytics setupWithConfiguration:configuration];
[[SEGAnalytics sharedAnalytics] identify:@"Prateek" traits:nil options: @{
Expand Down