Skip to content

Commit

Permalink
Merge pull request #45 from adjust/deep_link
Browse files Browse the repository at this point in the history
Added deep link parameters
  • Loading branch information
nonelse committed Apr 16, 2014
2 parents bdda238 + 87a30bc commit 8a1d1c8
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Adjust.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "Adjust"
s.version = "3.2.1"
s.version = "3.3.0"
s.summary = "This is the iOS SDK of Adjust. You can read more about it at http://adjust.io."
s.homepage = "http://adjust.io"
s.license = { :type => 'MIT', :file => 'MIT-LICENSE' }
s.author = { "Christian Wellenbrock" => "[email protected]" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v3.2.1" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v3.3.0" }
s.platform = :ios, '4.3'
s.framework = 'SystemConfiguration'
s.weak_framework = 'AdSupport'
Expand Down
1 change: 1 addition & 0 deletions Adjust/AIActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- (void)finishedTrackingWithResponse:(AIResponseData *)response;
- (void)setEnabled:(BOOL)enabled;
- (BOOL)isEnabled;
- (void)readOpenUrl:(NSURL*)url;

@end

Expand Down
47 changes: 44 additions & 3 deletions Adjust/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#import "AIAdjustFactory.h"

static NSString * const kActivityStateFilename = @"AdjustIoActivityState";
static NSString * const kAdjustPrefix = @"adjust_";
static const char * const kInternalQueueName = "io.adjust.ActivityQueue";

static const uint64_t kTimerInterval = 60 * NSEC_PER_SEC; // 1 minute
static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second
static const uint64_t kTimerInterval = 60 * NSEC_PER_SEC; // 1 minute
static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second


#pragma mark -
Expand Down Expand Up @@ -141,6 +142,12 @@ - (BOOL)isEnabled {
}
}

- (void)readOpenUrl:(NSURL*)url {
dispatch_async(self.internalQueue, ^{
[self readOpenUrlInternal:url];
});
}

#pragma mark - internal
- (void)initInternal:(NSString *)yourAppToken {
if (![self checkAppTokenNotNil:yourAppToken]) return;
Expand Down Expand Up @@ -309,6 +316,40 @@ - (void)revenueInternal:(double)amount
[self.logger debug:@"Event %d (revenue)", self.activityState.eventCount];
}

- (void) readOpenUrlInternal:(NSURL *)url {
NSArray* queryArray = [url.query componentsSeparatedByString:@"&"];
NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary];

for (NSString* fieldValuePair in queryArray) {
NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="];
if (pairComponents.count != 2) continue;

NSString* key = [pairComponents objectAtIndex:0];
if (![key hasPrefix:kAdjustPrefix]) continue;

NSString* value = [pairComponents objectAtIndex:1];
if (value.length == 0) continue;

NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length];
if (keyWOutPrefix.length == 0) continue;

[adjustDeepLinks setObject:value forKey:keyWOutPrefix];
}

if (adjustDeepLinks.count == 0) {
return;
}

AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init];
reattributionBuilder.deeplinkParameters = adjustDeepLinks;
[self injectGeneralAttributes:reattributionBuilder];
AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage];
[self.packageHandler addPackage:reattributionPackage];
[self.packageHandler sendFirstPackage];

[self.logger debug:@"Reattribution %@", adjustDeepLinks];
}

#pragma mark - private

// returns whether or not the activity state should be written
Expand Down Expand Up @@ -358,7 +399,7 @@ - (void)writeActivityState {
BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename];
if (result == YES) {
[AIUtil excludeFromBackup:filename];
[self.logger verbose:@"Wrote activity state: %@", self.activityState];
[self.logger debug:@"Wrote activity state: %@", self.activityState];
} else {
[self.logger error:@"Failed to write activity state"];
}
Expand Down
9 changes: 5 additions & 4 deletions Adjust/AIActivityKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#import <Foundation/Foundation.h>

typedef enum {
AIActivityKindUnknown = 0,
AIActivityKindSession = 1,
AIActivityKindEvent = 2,
AIActivityKindRevenue = 3,
AIActivityKindUnknown = 0,
AIActivityKindSession = 1,
AIActivityKindEvent = 2,
AIActivityKindRevenue = 3,
AIActivityKindReattribution = 4,
} AIActivityKind;

AIActivityKind AIActivityKindFromString(NSString *string);
Expand Down
11 changes: 7 additions & 4 deletions Adjust/AIActivityKind.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ AIActivityKind AIActivityKindFromString(NSString *string) {
return AIActivityKindEvent;
} else if ([@"revenue" isEqualToString:string]) {
return AIActivityKindRevenue;
} else if ([@"reattribution" isEqualToString:string]) {
return AIActivityKindReattribution;
} else {
return AIActivityKindUnknown;
}
}

NSString* AIActivityKindToString(AIActivityKind activityKind) {
switch (activityKind) {
case AIActivityKindSession: return @"session";
case AIActivityKindEvent: return @"event";
case AIActivityKindRevenue: return @"revenue";
case AIActivityKindUnknown: return @"unknown";
case AIActivityKindSession: return @"session";
case AIActivityKindEvent: return @"event";
case AIActivityKindRevenue: return @"revenue";
case AIActivityKindReattribution: return @"reattribution";
case AIActivityKindUnknown: return @"unknown";
}
}
5 changes: 5 additions & 0 deletions Adjust/AIPackageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
@property (nonatomic, copy) NSDictionary *callbackParameters;
@property (nonatomic, assign) double amountInCents;

// reattributions
@property (nonatomic, copy) NSDictionary* deeplinkParameters;


- (AIActivityPackage *)buildSessionPackage;
- (AIActivityPackage *)buildEventPackage;
- (AIActivityPackage *)buildRevenuePackage;
- (AIActivityPackage *)buildReattributionPackage;

@end
29 changes: 25 additions & 4 deletions Adjust/AIPackageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ - (AIActivityPackage *)buildRevenuePackage {
return revenuePackage;
}

- (AIActivityPackage *)buildReattributionPackage {
NSMutableDictionary *parameters = [self defaultParameters];
[self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_parameters"];

AIActivityPackage *reattributionPackage = [self defaultActivityPackage];
reattributionPackage.path = @"/reattribute";
reattributionPackage.activityKind = AIActivityKindReattribution;
reattributionPackage.suffix = @"";
reattributionPackage.parameters = parameters;

return reattributionPackage;
}

#pragma mark private
- (AIActivityPackage *)defaultActivityPackage {
AIActivityPackage *activityPackage = [[AIActivityPackage alloc] init];
Expand Down Expand Up @@ -87,9 +100,9 @@ - (NSMutableDictionary *)defaultParameters {

- (void)injectEventParameters:(NSMutableDictionary *)parameters {
// event specific
[self parameters:parameters setInt:self.eventCount forKey:@"event_count"];
[self parameters:parameters setString:self.eventToken forKey:@"event_token"];
[self parameters:parameters setDictionary:self.callbackParameters forKey:@"params"];
[self parameters:parameters setInt:self.eventCount forKey:@"event_count"];
[self parameters:parameters setString:self.eventToken forKey:@"event_token"];
[self parameters:parameters setDictionaryBase64:self.callbackParameters forKey:@"params"];
}

- (NSString *)amountString {
Expand Down Expand Up @@ -138,13 +151,21 @@ - (void)parameters:(NSMutableDictionary *)parameters setDuration:(double)value f
[self parameters:parameters setInt:intValue forKey:key];
}

- (void)parameters:(NSMutableDictionary *)parameters setDictionary:(NSDictionary *)dictionary forKey:(NSString *)key {
- (void)parameters:(NSMutableDictionary *)parameters setDictionaryBase64:(NSDictionary *)dictionary forKey:(NSString *)key {
if (dictionary == nil) return;

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
NSString *dictionaryString = jsonData.aiEncodeBase64;
[self parameters:parameters setString:dictionaryString forKey:key];
}

- (void)parameters:(NSMutableDictionary *)parameters setDictionaryJson:(NSDictionary *)dictionary forKey:(NSString *)key {
if (dictionary == nil) return;

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
NSString *dictionaryString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[self parameters:parameters setString:dictionaryString forKey:key];
}

@end

2 changes: 1 addition & 1 deletion Adjust/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <sys/xattr.h>

static NSString * const kBaseUrl = @"https://app.adjust.io";
static NSString * const kClientSdk = @"ios3.2.1";
static NSString * const kClientSdk = @"ios3.3.0";

static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'Z";
static NSDateFormatter * dateFormat;
Expand Down
5 changes: 5 additions & 0 deletions Adjust/Adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ static NSString * const AIEnvironmentProduction = @"production";
*/
+ (BOOL)isEnabled;

/**
* Read the URL that opened the application to search for
* an adjust deep link
*/
+ (void)appWillOpenUrl:(NSURL *)url;
@end


Expand Down
4 changes: 4 additions & 0 deletions Adjust/Adjust.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,8 @@ + (BOOL)isEnabled {
return [activityHandler isEnabled];
}

+ (void)appWillOpenUrl:(NSURL *)url {
[activityHandler readOpenUrl:url];
}

@end
4 changes: 4 additions & 0 deletions AdjustTests/AIActivityHandlerMock.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ - (BOOL)isEnabled {
return YES;
}

- (void)readOpenUrl:(NSURL *)url {
[self.loggerMock test:[prefix stringByAppendingFormat:@"readOpenUrl"]];
}

@end
Loading

0 comments on commit 8a1d1c8

Please sign in to comment.