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-18851] Implement the filtering of analytics events for iOS #6923

Merged
merged 2 commits into from
Jun 20, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions iphone/Classes/AnalyticsModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

@interface AnalyticsModule : TiModule

+ (BOOL)isEventFltered:(NSString*)eventName;

@end
34 changes: 34 additions & 0 deletions iphone/Classes/AnalyticsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
#import "APSAnalytics/APSAnalytics.h"
#import "SBJSON.h"
extern BOOL const TI_APPLICATION_ANALYTICS;
static NSMutableArray* _filteredEvents;

@implementation AnalyticsModule

- (void)dealloc
{
RELEASE_TO_NIL(_filteredEvents);
[super dealloc];
}
-(NSString*)apiName
{
return @"Ti.Analytics";
Expand Down Expand Up @@ -70,4 +77,31 @@ -(void)featureEvent:(id)args
[[APSAnalytics sharedInstance] sendAppFeatureEvent:event payload:data];
}

-(void)filterEvents:(id)args
{
ENSURE_SINGLE_ARG(args, NSArray);
if (_filteredEvents == nil) {
_filteredEvents = [[NSMutableArray array] retain];
} else {
[_filteredEvents removeAllObjects];
}

for (id event in args) {
ENSURE_STRING(event);
if (![_filteredEvents containsObject:event]) {
[_filteredEvents addObject:event];
}
}
}

+ (BOOL)isEventFltered:(NSString*)eventName
{
if (_filteredEvents == nil) return NO;
for (NSString* event in _filteredEvents) {
if ([event isEqualToString:eventName]) {
return YES;
}
}
return NO;
}
@end
7 changes: 6 additions & 1 deletion iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import <sys/utsname.h>
#import "NSData+Additions.h"
#import "APSAnalytics.h"
#import "AnalyticsModule.h"

extern NSString * const TI_APPLICATION_GUID;
extern BOOL const TI_APPLICATION_ANALYTICS;
Expand Down Expand Up @@ -955,7 +956,11 @@ -(void)setPurpose:(NSString *)reason

#pragma mark Geolacation Analytics

-(void)fireApplicationAnalyticsIfNeeded:(NSArray *)locations{
-(void)fireApplicationAnalyticsIfNeeded:(NSArray *)locations
{
if ([AnalyticsModule isEventFltered:@"ti.geo"]) {
return;
}
static BOOL analyticsSend = NO;
Copy link
Contributor

Choose a reason for hiding this comment

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

Was trying to test and realised ti.geo is never fired anyway, both with and without the new code. have to remove 'static' here, otherwise analyticsSend will always be set to YES.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why that's there, it was there already. Let me do some research and find out

[lastLocationDict release];
lastLocationDict = [[self locationDictionary:[locations lastObject]] copy];
Expand Down