AnalyticsUmeng.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /****************************************************************************
  2. Copyright (c) 2012-2013 cocos2d-x.org
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #import "AnalyticsUmeng.h"
  21. #import "MobClick.h"
  22. #define OUTPUT_LOG(...) if (self.debug) NSLog(__VA_ARGS__);
  23. @implementation AnalyticsUmeng
  24. @synthesize debug = __debug;
  25. - (void) startSession: (NSString*) appKey
  26. {
  27. OUTPUT_LOG(@"Umeng startSession invoked");
  28. [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"];
  29. [MobClick startWithAppkey:appKey];
  30. }
  31. - (void) stopSession
  32. {
  33. OUTPUT_LOG(@"Umeng stopSession in umeng not available on iOS");
  34. }
  35. - (void) setSessionContinueMillis: (long) millis
  36. {
  37. OUTPUT_LOG(@"Umeng setSessionContinueMillis in umeng not available on iOS");
  38. }
  39. - (void) setCaptureUncaughtException: (BOOL) isEnabled
  40. {
  41. OUTPUT_LOG(@"Umeng setCaptureUncaughtException invoked");
  42. [MobClick setCrashReportEnabled:isEnabled];
  43. }
  44. - (void) setDebugMode: (BOOL) isDebugMode
  45. {
  46. OUTPUT_LOG(@"Umeng setDebugMode invoked");
  47. self.debug = isDebugMode;
  48. [MobClick setLogEnabled:isDebugMode];
  49. }
  50. - (void) logError: (NSString*) errorId withMsg:(NSString*) message
  51. {
  52. OUTPUT_LOG(@"logError in umeng not available on iOS");
  53. }
  54. - (void) logEvent: (NSString*) eventId
  55. {
  56. OUTPUT_LOG(@"Umeng logEvent invoked");
  57. [MobClick event:eventId];
  58. }
  59. - (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap
  60. {
  61. OUTPUT_LOG(@"Umeng logEventWithParam invoked");
  62. if (paramMap != nil) {
  63. [MobClick event:eventId attributes:paramMap];
  64. } else {
  65. [MobClick event:eventId];
  66. }
  67. }
  68. - (void) logTimedEventBegin: (NSString*) eventId
  69. {
  70. OUTPUT_LOG(@"Umeng logTimedEventBegin invoked");
  71. [MobClick beginEvent:eventId];
  72. }
  73. - (void) logTimedEventEnd: (NSString*) eventId
  74. {
  75. OUTPUT_LOG(@"Umeng logTimedEventEnd invoked");
  76. [MobClick endEvent:eventId];
  77. }
  78. - (NSString*) getSDKVersion
  79. {
  80. return @"2.2.0";
  81. }
  82. - (NSString*) getPluginVersion
  83. {
  84. return @"0.2.0";
  85. }
  86. - (void) updateOnlineConfig
  87. {
  88. OUTPUT_LOG(@"Umeng updateOnlineConfig invoked");
  89. [MobClick updateOnlineConfig];
  90. }
  91. - (NSString*) getConfigParams: (NSString*) key
  92. {
  93. OUTPUT_LOG(@"Umeng getConfigParams invoked (%@)", key);
  94. return [MobClick getConfigParams:key];
  95. }
  96. - (void) logEventWithLabel: (NSMutableDictionary*) params
  97. {
  98. OUTPUT_LOG(@"Umeng logEventWithLabel invoked (%@)", [params debugDescription]);
  99. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  100. NSString* label = (NSString*) [params objectForKey:@"Param2"];
  101. if (label) {
  102. [MobClick event:eventId label:label];
  103. } else {
  104. [MobClick event:eventId];
  105. }
  106. }
  107. - (void) logEventWithDuration: (NSMutableDictionary*) params
  108. {
  109. OUTPUT_LOG(@"Umeng logEventWithDuration invoked(%@)", [params debugDescription]);
  110. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  111. NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"];
  112. int numDur = [duration intValue];
  113. [MobClick event:eventId durations:numDur];
  114. }
  115. - (void) logEventWithDurationLabel:(NSMutableDictionary*) params
  116. {
  117. OUTPUT_LOG(@"Umeng logEventWithDurationLabel invoked(%@)", [params debugDescription]);
  118. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  119. NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"];
  120. NSString* label = (NSString*) [params objectForKey:@"Param3"];
  121. int numDur = [duration intValue];
  122. if (! label) {
  123. [MobClick event:eventId durations:numDur];
  124. } else {
  125. [MobClick event:eventId label:label durations:numDur];
  126. }
  127. }
  128. - (void) logEventWithDurationParams: (NSMutableDictionary*) params
  129. {
  130. OUTPUT_LOG(@"Umeng logEventWithDurationParams invoked(%@)", [params debugDescription]);
  131. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  132. NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"];
  133. NSMutableDictionary* paramMap = (NSMutableDictionary*) [params objectForKey:@"Param3"];
  134. int numDur = [duration intValue];
  135. if (! paramMap) {
  136. [MobClick event:eventId durations:numDur];
  137. } else {
  138. [MobClick event:eventId attributes:paramMap durations:numDur];
  139. }
  140. }
  141. - (void) logTimedEventWithLabelBegin: (NSMutableDictionary*) params
  142. {
  143. OUTPUT_LOG(@"Umeng logTimedEventWithLabelBegin invoked(%@)", [params debugDescription]);
  144. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  145. NSString* label = (NSString*) [params objectForKey:@"Param2"];
  146. if (! label) {
  147. [MobClick beginEvent:eventId];
  148. } else {
  149. [MobClick beginEvent:eventId label:label];
  150. }
  151. }
  152. - (void) logTimedEventWithLabelEnd: (NSMutableDictionary*) params
  153. {
  154. OUTPUT_LOG(@"Umeng logTimedEventWithLabelEnd invoked(%@)", [params debugDescription]);
  155. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  156. NSString* label = (NSString*) [params objectForKey:@"Param2"];
  157. if (! label) {
  158. [MobClick endEvent:eventId];
  159. } else {
  160. [MobClick endEvent:eventId label:label];
  161. }
  162. }
  163. - (void) logTimedKVEventBegin: (NSMutableDictionary*) params
  164. {
  165. OUTPUT_LOG(@"Umeng logTimedKVEventBegin invoked(%@)", [params debugDescription]);
  166. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  167. NSString* label = (NSString*) [params objectForKey:@"Param2"];
  168. NSMutableDictionary* paramMap = (NSMutableDictionary*) [params objectForKey:@"Param3"];
  169. if (! label || ! paramMap) {
  170. [MobClick beginEvent:eventId];
  171. } else {
  172. [MobClick beginEvent:eventId primarykey:label attributes:paramMap];
  173. }
  174. }
  175. - (void) logTimedKVEventEnd: (NSMutableDictionary*) params
  176. {
  177. OUTPUT_LOG(@"Umeng logTimedKVEventEnd invoked(%@)", [params debugDescription]);
  178. NSString* eventId = (NSString*) [params objectForKey:@"Param1"];
  179. NSString* label = (NSString*) [params objectForKey:@"Param2"];
  180. if (! label) {
  181. [MobClick endEvent:eventId];
  182. } else {
  183. [MobClick endEvent:eventId primarykey:label];
  184. }
  185. }
  186. - (void) startSessionWithParams: (NSMutableDictionary*) params
  187. {
  188. OUTPUT_LOG(@"Umeng startSessionWithParams invoked(%@)", [params debugDescription]);
  189. NSString* appKey = (NSString*) [params objectForKey:@"Param1"];
  190. NSNumber* policy = (NSNumber*) [params objectForKey:@"Param2"];
  191. NSString* channelId = (NSString*) [params objectForKey:@"Param3"];
  192. int nPolicy = [policy intValue];
  193. [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"];
  194. [MobClick startWithAppkey:appKey reportPolicy:(ReportPolicy)nPolicy channelId:channelId];
  195. }
  196. - (void) checkUpdate
  197. {
  198. OUTPUT_LOG(@"Umeng checkUpdate invoked");
  199. [MobClick checkUpdate];
  200. }
  201. @end