BTAnalyticsService.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #import <Foundation/Foundation.h>
  2. @class BTAPIClient;
  3. @class BTHTTP;
  4. NS_ASSUME_NONNULL_BEGIN
  5. /**
  6. Domain for analytics service errors.
  7. */
  8. extern NSString * const BTAnalyticsServiceErrorDomain;
  9. /**
  10. Error codes associated with analytics services.
  11. */
  12. typedef NS_ENUM(NSUInteger, BTAnalyticsServiceErrorType) {
  13. /// Unknown error
  14. BTAnalyticsServiceErrorTypeUnknown = 1,
  15. /// Missing analytics url
  16. BTAnalyticsServiceErrorTypeMissingAnalyticsURL,
  17. /// Invalid API client
  18. BTAnalyticsServiceErrorTypeInvalidAPIClient,
  19. };
  20. @interface BTAnalyticsService : NSObject
  21. - (instancetype)initWithAPIClient:(BTAPIClient *)apiClient;
  22. /**
  23. Defaults to 1, can be overridden
  24. */
  25. @property (nonatomic, assign) NSUInteger flushThreshold;
  26. @property (nonatomic, strong) BTAPIClient *apiClient;
  27. /**
  28. Tracks an event.
  29. Events are queued and sent in batches to the analytics service, based on the status of the app
  30. and the number of queued events. After exiting this method, there is no guarantee that the event has been
  31. sent.
  32. */
  33. - (void)sendAnalyticsEvent:(NSString *)eventKind;
  34. /**
  35. Tracks an event and sends it to the analytics service. It will also flush any queued events.
  36. @param completionBlock A callback that is invoked when the analytics service has completed.
  37. */
  38. - (void)sendAnalyticsEvent:(NSString *)eventKind completion:(nullable void(^)(NSError * _Nullable))completionBlock;
  39. /**
  40. Sends all queued events to the analytics service.
  41. @param completionBlock A callback that is invoked when the analytics service has completed.
  42. */
  43. - (void)flush:(nullable void (^)(NSError * _Nullable error))completionBlock;
  44. /**
  45. The HTTP client for communication with the analytics service endpoint. Exposed for testing.
  46. */
  47. @property (nonatomic, strong) BTHTTP *http;
  48. @end
  49. NS_ASSUME_NONNULL_END