Skip to content

Commit

Permalink
Merge pull request #5729 from srahim/TIMOB-17021-3_3_X
Browse files Browse the repository at this point in the history
[TIMOB-17021] 3_3_X iOS: FeatureEvent should accept a jsonString, string and Dictionary
  • Loading branch information
pec1985 committed May 22, 2014
2 parents 898db29 + 393fb1d commit 0d36b26
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions iphone/Classes/AnalyticsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "AnalyticsModule.h"
#import "APSAnalytics/APSAnalytics.h"
#import "SBJSON.h"

@implementation AnalyticsModule

Expand All @@ -27,10 +28,10 @@ -(void)navEvent:(id)args
[self throwException:@"invalid number of arguments, expected at least 2" subreason:nil location:CODELOCATION];
return;
}
NSString *from = [[args objectAtIndex:0] autorelease];
NSString *to = [[args objectAtIndex:1] autorelease];
NSString *event = [args count] > 2 ? [[args objectAtIndex:2] autorelease] : @"";
id data = [args count] > 3 ? [[args objectAtIndex:3] autorelease] : [NSDictionary dictionary];
NSString *from = [args objectAtIndex:0] ;
NSString *to = [args objectAtIndex:1];
NSString *event = [args count] > 2 ? [args objectAtIndex:2] : @"";
id data = [args count] > 3 ? [args objectAtIndex:3] : [NSDictionary dictionary];
[APSAnalytics sendAppNavEventFrom:from to:to withName:event withPayload:data];
}

Expand All @@ -42,10 +43,23 @@ -(void)featureEvent:(id)args
[self throwException:@"invalid number of arguments, expected at least 1" subreason:nil location:CODELOCATION];
return;
}
NSString *event = [[args objectAtIndex:0] autorelease];
id data = [args count] > 1 ? [[args objectAtIndex:1] autorelease] : [NSDictionary dictionary];

[APSAnalytics sendFeatureEvent:event withPayload:data];
NSString *event = [args objectAtIndex:0];
id data = [args count] > 1 ? [args objectAtIndex:1] : [NSDictionary dictionary];
if (data!=nil && ([data isKindOfClass:[NSDictionary class]]== NO))
{
id value = nil;
if ([data isKindOfClass:[NSString class]] == YES) {
value = [TiUtils jsonParse:data];
if (value == nil)
value = [NSDictionary dictionaryWithObject:data forKey:@"data"];
} else {
//if all else fails fall back old behavior
value = [SBJSON stringify:data];
value = [NSDictionary dictionaryWithObject:value forKey:@"data"];
}
data = value;
}
[APSAnalytics sendFeatureEvent:event withPayload:data];
}

@end

0 comments on commit 0d36b26

Please sign in to comment.