/flurry/mobile/ios/Classes/TiFlurryModule.m

https://bitbucket.org/plepic/titanium_modules · Objective C · 175 lines · 146 code · 24 blank · 5 comment · 12 complexity · d0d85b8ce849f514e810a704e59c4e47 MD5 · raw file

  1. /**
  2. * Ti.Flurry Module
  3. * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved.
  4. * Please see the LICENSE included with this distribution for details.
  5. */
  6. #import "TiFlurryModule.h"
  7. @implementation TiFlurryModule
  8. #pragma mark Lifecycle
  9. -(void)startup
  10. {
  11. [super startup];
  12. }
  13. -(void)shutdown:(id)sender
  14. {
  15. [super shutdown:sender];
  16. }
  17. #pragma mark -
  18. #pragma mark Public APIs
  19. #pragma mark -
  20. #pragma mark Public Lifecycle
  21. -(void)initialize:(id)apiKey
  22. {
  23. ENSURE_SINGLE_ARG(apiKey, NSString);
  24. [FlurryAnalytics startSession:apiKey];
  25. }
  26. # pragma mark Public Properties
  27. -(void)setUserID:(id)value
  28. {
  29. [FlurryAnalytics setUserID:value];
  30. }
  31. -(void)setUserId:(id)value
  32. {
  33. [self setUserID:value];
  34. }
  35. -(void)setAge:(id)value
  36. {
  37. [FlurryAnalytics setAge:[TiUtils intValue:value]];
  38. }
  39. -(void)setGender:(id)value
  40. {
  41. [FlurryAnalytics setGender:value];
  42. }
  43. -(void)setDebugLogEnabled:(id)value
  44. {
  45. [FlurryAnalytics setDebugLogEnabled:[TiUtils boolValue:value]];
  46. }
  47. -(void)setEventLoggingEnabled:(id)value
  48. {
  49. [FlurryAnalytics setEventLoggingEnabled:[TiUtils boolValue:value]];
  50. }
  51. -(void)setReportOnClose:(id)value
  52. {
  53. [FlurryAnalytics setSessionReportsOnCloseEnabled:[TiUtils boolValue:value]];
  54. }
  55. -(void)reportOnClose:(id)value
  56. {
  57. ENSURE_SINGLE_ARG(value, NSObject);
  58. [self setReportOnClose:value];
  59. }
  60. -(void)setSessionReportsOnPauseEnabled:(id)value
  61. {
  62. [FlurryAnalytics setSessionReportsOnPauseEnabled:[TiUtils boolValue:value]];
  63. }
  64. -(void)sessionReportsOnPauseEnabled:(id)value
  65. {
  66. ENSURE_SINGLE_ARG(value, NSObject);
  67. [self setSessionReportsOnPauseEnabled:value];
  68. }
  69. -(void)setSecureTransportEnabled:(id)value
  70. {
  71. [FlurryAnalytics setSecureTransportEnabled:[TiUtils boolValue:value]];
  72. }
  73. -(void)secureTransportEnabled:(id)value
  74. {
  75. ENSURE_SINGLE_ARG(value, NSObject);
  76. [self setSecureTransportEnabled:value];
  77. }
  78. # pragma mark Public Methods
  79. -(void)trackLocation:(id)args
  80. {
  81. ENSURE_SINGLE_ARG(args, NSDictionary);
  82. [FlurryAnalytics setLatitude:[TiUtils doubleValue:[args valueForKey:@"latitude"]]
  83. longitude:[TiUtils doubleValue:[args valueForKey:@"longitude"]]
  84. horizontalAccuracy:[TiUtils floatValue:[args valueForKey:@"horizontalAccuracy"]]
  85. verticalAccuracy:[TiUtils floatValue:[args valueForKey:@"verticalAccuracy"]]];
  86. }
  87. -(void)logEvent:(id)args
  88. {
  89. ENSURE_UI_THREAD(logEvent, args);
  90. NSString *event = [args objectAtIndex:0];
  91. NSDictionary *props = nil;
  92. if ([args count] > 1)
  93. {
  94. props = [args objectAtIndex:1];
  95. }
  96. if (props == nil)
  97. {
  98. [FlurryAnalytics logEvent:event];
  99. }
  100. else
  101. {
  102. [FlurryAnalytics logEvent:event withParameters:props];
  103. }
  104. }
  105. -(void)logTimedEvent:(id)args
  106. {
  107. ENSURE_UI_THREAD(logTimedEvent, args);
  108. NSString *event = [args objectAtIndex:0];
  109. NSDictionary *props = nil;
  110. if ([args count] > 1)
  111. {
  112. props = [args objectAtIndex:1];
  113. }
  114. if (props == nil)
  115. {
  116. [FlurryAnalytics logEvent:event timed:YES];
  117. }
  118. else
  119. {
  120. [FlurryAnalytics logEvent:event withParameters:props timed:YES];
  121. }
  122. }
  123. -(void)endTimedEvent:(id)args
  124. {
  125. ENSURE_UI_THREAD(endTimedEvent, args);
  126. NSString *event = [args objectAtIndex:0];
  127. NSDictionary *props = nil;
  128. if ([args count] > 1)
  129. {
  130. props = [args objectAtIndex:1];
  131. }
  132. if (props == nil)
  133. {
  134. [FlurryAnalytics endTimedEvent:event withParameters:nil];
  135. }
  136. else
  137. {
  138. [FlurryAnalytics endTimedEvent:event withParameters:props];
  139. }
  140. }
  141. -(void)logAllPageViews:(id)args
  142. {
  143. ENSURE_UI_THREAD(logAllPageViews, args);
  144. [FlurryAnalytics logAllPageViews:[[TiApp app] controller]];
  145. }
  146. -(void)logPageView:(id)args
  147. {
  148. ENSURE_UI_THREAD(logPageView, args);
  149. [FlurryAnalytics logPageView];
  150. }
  151. @end