GameAnalytics.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. //
  2. // GameAnalytics.h
  3. // GA-SDK-IOS
  4. //
  5. // Copyright (c) 2015 GameAnalytics. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. /*!
  9. @enum
  10. @discussion
  11. This enum is used to specify flow in resource events
  12. @constant GAResourceFlowTypeSource
  13. Used when adding to a resource currency
  14. @constant GAResourceFlowTypeSink
  15. Used when subtracting from a resource currency
  16. */
  17. typedef enum GAResourceFlowType : NSInteger {
  18. GAResourceFlowTypeSource = 1,
  19. GAResourceFlowTypeSink = 2
  20. } GAResourceFlowType;
  21. /*!
  22. @enum
  23. @discussion
  24. his enum is used to specify status for progression event
  25. @constant GAProgressionStatusStart
  26. User started progression
  27. @constant GAProgressionStatusComplete
  28. User succesfully ended a progression
  29. @constant GAProgressionStatusFail
  30. User failed a progression
  31. */
  32. typedef enum GAProgressionStatus : NSInteger {
  33. GAProgressionStatusStart = 1,
  34. GAProgressionStatusComplete = 2,
  35. GAProgressionStatusFail = 3
  36. } GAProgressionStatus;
  37. /*!
  38. @enum
  39. @discussion
  40. his enum is used to specify severity of an error event
  41. @constant GAErrorSeverityDebug
  42. @constant GAErrorSeverityInfo
  43. @constant GAErrorSeverityWarning
  44. @constant GAErrorSeverityError
  45. @constant GAErrorSeverityCritical
  46. */
  47. typedef enum GAErrorSeverity : NSInteger {
  48. GAErrorSeverityDebug = 1,
  49. GAErrorSeverityInfo = 2,
  50. GAErrorSeverityWarning = 3,
  51. GAErrorSeverityError = 4,
  52. GAErrorSeverityCritical = 5
  53. } GAErrorSeverity;
  54. //Similar to ICommandCenterListener in the GameAnalytics Android library
  55. @protocol GACommandCenterDelegate <NSObject>
  56. @optional
  57. - (void) onCommandCenterUpdated; // Updated everytime when configurations are added
  58. @end
  59. @class GameAnalytics;
  60. @interface GameAnalytics : NSObject
  61. /*!
  62. @method
  63. @abstract Define available 1st custom dimensions
  64. @discussion <i>Example usage:</i>
  65. <pre><code>
  66. NSArray *dimensionArray = @[@"dimA", @"dimB", @"dimC"];<br>
  67. [GameAnalytics configureAvailableCustomDimensions01:dimensionArray];
  68. </code></pre>
  69. @param customDimensions
  70. Must be an array of strings.<br>
  71. Array max length=20, String max length=32)
  72. @availability Available since 2.0.0
  73. @attribute Note! This method must be called before initializing the SDK
  74. */
  75. + (void)configureAvailableCustomDimensions01:(NSArray *)customDimensions;
  76. /*!
  77. @method
  78. @abstract Set available 2nd custom dimensions
  79. @discussion <i>Example usage:</i>
  80. <pre><code>
  81. NSArray *available = @[@"dimD", @"dimE", @"dimF"];<br>
  82. [GameAnalytics configureAvailableCustomDimensions02:dimensionArray;
  83. </code></pre>
  84. @param customDimensions
  85. Must be an array of strings.<br>
  86. (Array max length=20, String max length=32)
  87. @availability Available since 2.0.0
  88. @attribute Note! This method must be called before initializing the SDK
  89. */
  90. + (void)configureAvailableCustomDimensions02:(NSArray *)customDimensions;
  91. /*!
  92. @method
  93. @abstract Set available 3rd custom dimensions
  94. @discussion <i>Example usage:</i>
  95. <pre><code>
  96. NSArray *available = @[@"dimA", @"dimB", @"dimC"];<br>
  97. [GameAnalytics configureAvailableCustomDimensions03:dimensionArray];
  98. </code></pre>
  99. @param customDimensions
  100. Must be an array of strings.<br>
  101. (Array max length=20, String max length=32)
  102. @availability Available since 2.0.0
  103. @attribute Note! This method must be called before initializing the SDK
  104. */
  105. + (void)configureAvailableCustomDimensions03:(NSArray *)customDimensions;
  106. /*!
  107. @method
  108. @abstract Set available resource currencies
  109. @discussion <i>Example usage:</i>
  110. <pre><code>
  111. NSArray *availableCurrencies = @[@"gems", @"gold"];<br>
  112. [GameAnalytics configureAvailableResourceCurrencies:availableCurrencies];
  113. </code></pre>
  114. @param resourceCurrencies
  115. Must be an array of strings.<br>
  116. (Array max length=20, String max length=32)
  117. @availability Available since 2.0.0
  118. @attribute Note! This method must be called before initializing the SDK
  119. */
  120. + (void)configureAvailableResourceCurrencies:(NSArray *)resourceCurrencies;
  121. /*!
  122. @method
  123. @abstract Set available resource item types
  124. @discussion <i>Example usage:</i>
  125. <pre><code>
  126. NSArray *availableItemTypes = @[@"upgrades", @"powerups"];<br>
  127. [GameAnalytics configureAvailableResourceItemTypes:availableItemTypes];
  128. </code></pre>
  129. @param resourceItemTypes
  130. Must be an array of strings.<br>
  131. (Array max length=20, String max length=32)
  132. @availability Available since 2.0.0
  133. @attribute Note! This method must be called before initializing the SDK
  134. */
  135. + (void)configureAvailableResourceItemTypes:(NSArray *)resourceItemTypes;
  136. /*!
  137. @method
  138. @abstract Set app build version
  139. @discussion <i>Example usage:</i>
  140. <pre><code>
  141. [GameAnalytics configureBuild:@"0.0.1"];
  142. </code></pre>
  143. @param build
  144. (String max length=32)
  145. @availability Available since 2.0.0
  146. @attribute Note! This method must be called before initializing the SDK
  147. */
  148. + (void)configureBuild:(NSString *)build;
  149. /*!
  150. @method
  151. @abstract Set a custom unique user_id identifying the user.
  152. @discussion <i>Example usage:</i>
  153. <pre><code>
  154. [GameAnalytics configureUserId:@"24566"];
  155. </code></pre>
  156. @param userId
  157. (String max length=64)
  158. @availability Available since 2.2.0
  159. @attribute Note! This method must be called before initializing the SDK
  160. */
  161. + (void)configureUserId:(NSString *)userId;
  162. /*!
  163. @method
  164. @abstract Set app engine version
  165. @discussion <i>Example usage:</i>
  166. <pre><code>
  167. [GameAnalytics configureEngineVersion:@"unreal 4.8.1"];
  168. </code></pre>
  169. @param engineVersion
  170. (String)
  171. @availability Available since 2.0.0
  172. @attribute Note! This method must be called before initializing the SDK
  173. */
  174. + (void)configureEngineVersion:(NSString *)engineVersion;
  175. /*!
  176. @method
  177. @abstract Configure the game key and secret key before initializing. Used by certain frameworks (like Frabric.io) needing to set the keys during configure phase.
  178. @discussion
  179. <i>Example usage:</i>
  180. <pre><code>
  181. [GameAnalytics configureGameKey:@"123456789ABCDEFGHIJKLMNOPQRSTU" gameSecret:@"123456789ABCDEFGHIJKLMNOPQRSTU12345678"];
  182. </code></pre>
  183. @param gameKey
  184. (String)
  185. @param gameSecret
  186. (String)
  187. @availability Available since 2.0.8
  188. */
  189. + (void)configureGameKey:(NSString *)gameKey
  190. gameSecret:(NSString *)gameSecret;
  191. /*!
  192. @method
  193. @abstract Initialize GameAnalytics SDK
  194. @discussion
  195. <i>Example usage:</i>
  196. <pre><code>
  197. [GameAnalytics initializeWithGameKey:@"123456789ABCDEFGHIJKLMNOPQRSTU" gameSecret:@"123456789ABCDEFGHIJKLMNOPQRSTU12345678"];
  198. </code></pre>
  199. @param gameKey
  200. (String)
  201. @param gameSecret
  202. (String)
  203. @availability Available since 2.0.0
  204. */
  205. + (void)initializeWithGameKey:(NSString *)gameKey
  206. gameSecret:(NSString *)gameSecret;
  207. /*!
  208. @method
  209. @abstract Initialize GameAnalytics SDK when the game key and game secret has been configured earlier.
  210. @discussion <i>Example usage:</i>
  211. <pre><code>
  212. [GameAnalytics initializeWithConfiguredGameKeyAndGameSecret];
  213. </code></pre>
  214. @availability Available since 2.0.8
  215. @attribute Note! This method can only be used if the configureGameKey:gameSecret: method is called before.
  216. */
  217. + (void)initializeWithConfiguredGameKeyAndGameSecret;
  218. /*!
  219. @method
  220. @abstract Add new business event with receipt
  221. @param currency
  222. Currency code in ISO 4217 format. (e.g. USD)
  223. @param amount
  224. Amount in cents (int). (e.g. 99)
  225. @param itemType
  226. Item Type bought. (e.g. Gold Pack)
  227. @param itemId
  228. Item bought. (e.g. 1000 gold)
  229. @param receipt
  230. Transaction receipt string. (Optional, can be nil)
  231. @availability Available since 2.0.0
  232. @attribute Note! This method cannot be called before initialize method has been triggered
  233. */
  234. + (void)addBusinessEventWithCurrency:(NSString *)currency
  235. amount:(NSInteger)amount
  236. itemType:(NSString *)itemType
  237. itemId:(NSString *)itemId
  238. cartType:(NSString *)cartType
  239. receipt:(NSString *)receipt;
  240. /*!
  241. @method
  242. @abstract Add new business event
  243. @param currency
  244. Currency code in ISO 4217 format. (e.g. USD)
  245. @param amount
  246. (Integer) Amount in cents. (e.g. 99)
  247. @param itemType
  248. Item Type bought. (e.g. Gold Pack)
  249. @param itemId
  250. Item bought. (e.g. 1000 gold)
  251. @param autoFetchReceipt
  252. Should the SDK automatically fetch the transaction receipt and add it to the event
  253. @availability Available since 1.0.0
  254. @attribute Note! This method cannot be called before initialize method has been triggered
  255. */
  256. + (void)addBusinessEventWithCurrency:(NSString *)currency
  257. amount:(NSInteger)amount
  258. itemType:(NSString *)itemType
  259. itemId:(NSString *)itemId
  260. cartType:(NSString *)cartType
  261. autoFetchReceipt:(BOOL)autoFetchReceipt;
  262. /*!
  263. @method
  264. @abstract Add new resource event
  265. @param flowType
  266. Add or substract resource.<br> (See. GAResourceFlowType)
  267. @param currency
  268. One of the available currencies set in configureAvailableResourceCurrencies
  269. @param amount
  270. Amount sourced or sinked
  271. @param itemType
  272. One of the available item types set in configureAvailableResourceItemTypes
  273. @param itemId
  274. Item id (string max length=32)
  275. @availability Available since 2.0.0
  276. @attribute Note! This method cannot be called before initialize method has been triggered
  277. */
  278. + (void)addResourceEventWithFlowType:(GAResourceFlowType)flowType
  279. currency:(NSString *)currency
  280. amount:(NSNumber *)amount
  281. itemType:(NSString *)itemType
  282. itemId:(NSString *)itemId;
  283. /*!
  284. @method
  285. @abstract Add new progression event
  286. @param progressionStatus
  287. Status of added progression.<br> (See. GAProgressionStatus)
  288. @param progression01
  289. 1st progression (e.g. world01)
  290. @param progression02
  291. 2nd progression (e.g. level01)
  292. @param progression03
  293. 3rd progression (e.g. phase01)
  294. @availability Available since 1.0.0
  295. @attribute Note! This method cannot be called before initialize method has been triggered
  296. */
  297. + (void)addProgressionEventWithProgressionStatus:(GAProgressionStatus)progressionStatus
  298. progression01:(NSString *)progression01
  299. progression02:(NSString *)progression02
  300. progression03:(NSString *)progression03;
  301. /*!
  302. @method
  303. @abstract Add new progression event with score
  304. @param progressionStatus
  305. Status of added progression.<br> (See. GAProgressionStatus)
  306. @param progression01
  307. 1st progression (e.g. world01)
  308. @param progression02
  309. 2nd progression (e.g. level01)
  310. @param progression03
  311. 3rd progression (e.g. phase01)
  312. @availability Available since 2.0.0
  313. @attribute Note! This method cannot be called before initialize method has been triggered
  314. */
  315. + (void)addProgressionEventWithProgressionStatus:(GAProgressionStatus)progressionStatus
  316. progression01:(NSString *)progression01
  317. progression02:(NSString *)progression02
  318. progression03:(NSString *)progression03
  319. score:(NSInteger)score;
  320. /*!
  321. @method
  322. @abstract Add new design event without a value
  323. @param eventId
  324. String can consist of 1 to 5 segments.<br>
  325. Segments are seperated by ':' and segments can have a max length of 32.<br>
  326. (e.g. segment1:anotherSegment:gold)
  327. @availability Available since 2.0.0
  328. @attribute Note! This method cannot be called before initialize method has been triggered
  329. */
  330. + (void)addDesignEventWithEventId:(NSString *)eventId;
  331. /*!
  332. @method
  333. @abstract Add new design event with a value
  334. @param eventId
  335. String can consist of 1 to 5 segments.<br>
  336. segments are seperated by ':' and segments can have a max length of 32.<br>
  337. (e.g. segment1:anotherSegment:gold)
  338. @param value
  339. Number value of event
  340. @availability Available since 2.0.0
  341. @attribute Note! This method cannot be called before initialize method has been triggered
  342. */
  343. + (void)addDesignEventWithEventId:(NSString *)eventId
  344. value:(NSNumber *)value;
  345. /*!
  346. @method
  347. @abstract Add new error event
  348. @param severity
  349. Severity of error (See. GAErrorSeverity)
  350. @param message
  351. Error message (Optional, can be nil)
  352. @availability Available since 2.0.0
  353. @attribute Note! This method cannot be called before initialize method has been triggered
  354. */
  355. + (void)addErrorEventWithSeverity:(GAErrorSeverity)severity
  356. message:(NSString *)message;
  357. /*!
  358. @method
  359. @abstract Get command center value as string
  360. @param key
  361. The key declared in the webtool
  362. @availability Available since (TBD)
  363. @attribute Note! This method cannot be called before initialize method has been triggered
  364. */
  365. + (NSString *)getCommandCenterValueAsString:(NSString*) key;
  366. /*!
  367. @method
  368. @abstract Get command center value as string
  369. @param key
  370. The key declared in the webtool
  371. @param defaultValue
  372. Fallback default value for when the method does not find a value under the specified key
  373. @availability Available since (TBD)
  374. @attribute Note! This method cannot be called before initialize method has been triggered
  375. */
  376. + (NSString *) getCommandCenterValueAsString:(NSString *) key
  377. defaultValue:(NSString *)defaultValue;
  378. /*!
  379. @method
  380. @abstract Get command center configurations
  381. @availability Available since (TBD)
  382. @attribute For internal use.
  383. */
  384. + (NSString *) getCommandCenterConfigurations;
  385. /*!
  386. @method
  387. @abstract Use this to set the delegate for the Command Center to retreive information about the status of loading configurations
  388. @availability Available since (TBD)
  389. */
  390. + (void) setCommandCenterDelegate:(id)newDelegate;
  391. /*!
  392. @method
  393. @abstract Call for checking if command center values are loaded and ready
  394. @availability Available since (TBD)
  395. @attribute Note! This method should not be called before initialize method has been triggered
  396. */
  397. + (BOOL) isCommandCenterReady;
  398. /*!
  399. @method
  400. @abstract Enable info logging to console
  401. @param flag
  402. Enable or disable info log mode
  403. @availability Available since 2.0.0
  404. */
  405. + (void)setEnabledInfoLog:(BOOL)flag;
  406. /*!
  407. @method
  408. @abstract Enable verbose info logging of analytics. Will output event JSON data to console.
  409. @param flag
  410. Enable or disable verbose info log mode
  411. @availability Available since 2.0.0
  412. */
  413. + (void)setEnabledVerboseLog:(BOOL)flag;
  414. /*!
  415. @method
  416. @abstract Enable manual session handling.
  417. This will disable the automatic session stop/start when the app goes to background/foreground and it is then needed to call endSession & startSession manually.
  418. Remember to call endSession when the app is going to background.
  419. The first session will always be started automatically when initialize is called.
  420. @param flag
  421. Enable or disable manual session handling.
  422. @availability Available since 2.2.2
  423. */
  424. + (void)setEnabledManualSessionHandling:(BOOL)flag;
  425. /*!
  426. @method
  427. @abstract Start a new session.
  428. - if sdk is initialized
  429. - if manual session handling is enabled
  430. If a current session is currently active then it will end this session and start a new.
  431. @availability Available since 2.2.2
  432. */
  433. + (void)startSession;
  434. /*!
  435. @method
  436. @abstract End an active session.
  437. - if sdk is initialized
  438. - manual session handling is enabled
  439. - a session is active
  440. @availability Available since 2.2.2
  441. */
  442. + (void)endSession;
  443. /*!
  444. @method
  445. @abstract Set 1st custom dimension
  446. @param dimension01
  447. One of the available dimension values set in configureAvailableCustomDimensions01<br>
  448. Will persist cross session. Set to nil to reset.
  449. @availability Available since 2.0.0
  450. @attribute Note! Must be called after setAvailableCustomDimensions01WithCustomDimensions
  451. */
  452. + (void)setCustomDimension01:(NSString *)dimension01;
  453. /*!
  454. @method
  455. @abstract Set 2nd custom dimension
  456. @param dimension02
  457. One of the available dimension values set in configureAvailableCustomDimensions02<br>
  458. Will persist cross session. Set to nil to reset.
  459. @availability Available since 2.0.0
  460. @attribute Note! Must be called after setAvailableCustomDimensions02
  461. */
  462. + (void)setCustomDimension02:(NSString *)dimension02;
  463. /*!
  464. @method
  465. @abstract Set 3rd custom dimension
  466. @param dimension03
  467. One of the available dimension values set in configureAvailableCustomDimensions03<br>
  468. Will persist cross session. Set to nil to reset.
  469. @availability Available since 2.0.0
  470. @attribute Note! Must be called after setAvailableCustomDimensions03W
  471. */
  472. + (void)setCustomDimension03:(NSString *)dimension03;
  473. /*!
  474. @method
  475. @abstract Set user facebook id
  476. @param facebookId
  477. Facebook id of user (Persists cross session)
  478. @availability Available since 2.0.0
  479. */
  480. + (void)setFacebookId:(NSString *)facebookId;
  481. /*!
  482. @method
  483. @abstract Set user gender
  484. @param gender
  485. Gender of user (Persists cross session)<br>
  486. Must be one of (male / female)
  487. @availability Available since 2.0.0
  488. */
  489. + (void)setGender:(NSString *)gender;
  490. /*!
  491. @method
  492. @abstract Set user birth year
  493. @param birthYear
  494. Birth year of user (Persists cross session)
  495. @availability Available since 2.0.0
  496. */
  497. + (void)setBirthYear:(NSInteger)birthYear;
  498. @end