-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from deszip/feature/build-actions
Feature/build actions
- Loading branch information
Showing
604 changed files
with
43,526 additions
and
1,889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,21 @@ | |
#import "BRAnalytics.h" | ||
|
||
#import <Mixpanel/Mixpanel.h> | ||
#import <Sentry/Sentry.h> | ||
|
||
static NSString * const kBRAnalyticsAvailabilityKey = @"kBRAnalyticsAvailabilityKey"; | ||
|
||
static NSString * const kBRMixpanelOSXToken = @"ae64ff4c78b73e7f945f63aa02677fbb"; | ||
static NSString * const kBRMixpanelATVToken = @"4d209b738bd7dc6965ad1325080f83f1"; | ||
|
||
#if DEBUG | ||
static NSString * const kBRSentryOSXDSNPath = @"https://[email protected]/5731739"; | ||
#else | ||
static NSString * const kBRSentryOSXDSNPath = @"https://[email protected]/5783183"; | ||
#endif | ||
|
||
static NSString * const kBRSentryATVDSNPath = @"https://[email protected]/5737938"; | ||
|
||
typedef NSString BRAnalyticsEvent; | ||
|
||
static BRAnalyticsEvent * const kQuitAppEvent = @"app_quit"; | ||
|
@@ -63,22 +72,42 @@ + (instancetype)analytics { | |
} | ||
|
||
- (void)start { | ||
// First launch, enable by default | ||
if ([[NSUserDefaults standardUserDefaults] objectForKey:kBRAnalyticsAvailabilityKey] == nil) { | ||
[[BRAnalytics analytics] setEnabled:YES]; | ||
} | ||
|
||
// Start services if enabled | ||
if ([self isEnabled]) { | ||
#if TARGET_OS_OSX | ||
[Mixpanel sharedInstanceWithToken:kBRMixpanelOSXToken]; | ||
[self startMixpanel:kBRMixpanelOSXToken]; | ||
[self startSentry:kBRSentryOSXDSNPath]; | ||
#else | ||
[Mixpanel sharedInstanceWithToken:kBRMixpanelATVToken]; | ||
[self startMixpanel:kBRMixpanelATVToken]; | ||
[self startSentry:kBRSentryATVDSNPath]; | ||
#endif | ||
|
||
if ([[NSUserDefaults standardUserDefaults] objectForKey:kBRAnalyticsAvailabilityKey] == nil) { | ||
[[BRAnalytics analytics] setEnabled:YES]; | ||
} | ||
} | ||
|
||
- (void)stop { | ||
[self stopMixpanel]; | ||
[self stopSentry]; | ||
} | ||
|
||
- (void)toggle { | ||
[self setEnabled:![self isEnabled]]; | ||
if ([self isEnabled]) { | ||
[self start]; | ||
} else { | ||
[self stop]; | ||
} | ||
} | ||
|
||
- (void)setEnabled:(BOOL)isEnabled { | ||
if (isEnabled == [self isEnabled]) { | ||
return; | ||
} | ||
|
||
[self.defaults setBool:isEnabled forKey:kBRAnalyticsAvailabilityKey]; | ||
[self.defaults synchronize]; | ||
} | ||
|
@@ -87,6 +116,32 @@ - (BOOL)isEnabled { | |
return [self.defaults boolForKey:kBRAnalyticsAvailabilityKey]; | ||
} | ||
|
||
#pragma mark - Providers - | ||
|
||
- (void)startMixpanel:(NSString *)token { | ||
[Mixpanel sharedInstanceWithToken:token]; | ||
if ([[Mixpanel sharedInstance] hasOptedOutTracking]) { | ||
[[Mixpanel sharedInstance] optInTracking]; | ||
} | ||
} | ||
|
||
- (void)stopMixpanel { | ||
[[Mixpanel sharedInstance] flush]; | ||
[[Mixpanel sharedInstance] reset]; | ||
[[Mixpanel sharedInstance] optOutTracking]; | ||
} | ||
|
||
- (void)startSentry:(NSString *)dsn { | ||
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) { | ||
options.dsn = dsn; | ||
options.tracesSampleRate = @1.0; | ||
}]; | ||
} | ||
|
||
- (void)stopSentry { | ||
[SentrySDK close]; | ||
} | ||
|
||
#pragma mark - Events - | ||
|
||
- (void)trackQuitApp { [self sendEvent:kQuitAppEvent properties:@{}]; } | ||
|
@@ -97,13 +152,23 @@ - (void)trackNotificationsToggle { [self sendEvent:kNotificationsToggleEvent pro | |
- (void)trackAnalyticsToggle { [self sendEvent:kAnalyticsToggleEvent properties:@{}]; } | ||
|
||
- (void)trackAccountAdd { [self sendEvent:kAddAccountEvent properties:@{}]; } | ||
- (void)trackAccountAddFailure { [self sendEvent:kAddAccountFailureEvent properties:@{}]; } | ||
- (void)trackAccountAddFailure:(NSError *)error { | ||
[self sendEvent:kAddAccountFailureEvent properties:@{}]; | ||
[self sendError:error]; | ||
} | ||
- (void)trackAccountRemove { [self sendEvent:kRemoveAccountEvent properties:@{}]; } | ||
- (void)trackAccountRemoveError:(NSError *)error { | ||
[self sendEvent:kRemoveAccountEvent properties:@{}]; | ||
[self sendError:error]; | ||
} | ||
- (void)trackSyncWithStarted:(NSUInteger)started | ||
running:(NSUInteger)running | ||
finished:(NSUInteger)finished { [self sendEvent:kSyncEvent properties:@{ @"started" : @(started), | ||
@"running" : @(running), | ||
@"finished" : @(finished) }]; } | ||
- (void)trackSyncError:(NSError *)error { | ||
[self sendError:error]; | ||
} | ||
|
||
- (void)trackRebuildAction { [self sendEvent:kRebuildActionEvent properties:@{}]; } | ||
- (void)trackAbortAction { [self sendEvent:kAbortActionEvent properties:@{}]; } | ||
|
@@ -118,4 +183,14 @@ - (void)sendEvent:(BRAnalyticsEvent *)name properties:(NSDictionary *)properties | |
} | ||
} | ||
|
||
#pragma mark - Issues - | ||
|
||
- (void)sendError:(NSError *)error { | ||
[SentrySDK captureError:error]; | ||
|
||
// SentryEvent *event = [[SentryEvent alloc] initWithError:error]; | ||
// event.message = [[SentryMessage alloc] initWithFormatted:error.localizedDescription]; | ||
// [SentrySDK captureEvent:event]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.