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

[TIMOB-17021] iOS: FeatureEvent should accept a jsonString, string and Dictionary #5728

Merged
merged 1 commit into from
May 22, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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