GravityEngineSDK.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. #import <Foundation/Foundation.h>
  2. #if TARGET_OS_IOS
  3. #import <UIKit/UIKit.h>
  4. #if __has_include(<GravityEngineSDK/GEAutoTrackPublicHeader.h>)
  5. #import <GravityEngineSDK/GEAutoTrackPublicHeader.h>
  6. #else
  7. #import "GEAutoTrackPublicHeader.h"
  8. #endif
  9. #elif TARGET_OS_OSX
  10. #import <AppKit/AppKit.h>
  11. #endif
  12. #if __has_include(<GravityEngineSDK/GEFirstEventModel.h>)
  13. #import <GravityEngineSDK/GEFirstEventModel.h>
  14. #else
  15. #import "GEFirstEventModel.h"
  16. #endif
  17. #if __has_include(<GravityEngineSDK/GEEditableEventModel.h>)
  18. #import <GravityEngineSDK/GEEditableEventModel.h>
  19. #else
  20. #import "GEEditableEventModel.h"
  21. #endif
  22. #if __has_include(<GravityEngineSDK/GEConfig.h>)
  23. #import <GravityEngineSDK/GEConfig.h>
  24. #else
  25. #import "GEConfig.h"
  26. #endif
  27. #if __has_include(<GravityEngineSDK/GEPresetProperties.h>)
  28. #import <GravityEngineSDK/GEPresetProperties.h>
  29. #else
  30. #import "GEPresetProperties.h"
  31. #endif
  32. NS_ASSUME_NONNULL_BEGIN
  33. /**
  34. GravityEngine API
  35. ## Initialization
  36. ```objective-c
  37. GravityEngineSDK *instance = [GravityEngineSDK startWithAppId:@"YOUR_APPID" withUrl:@"YOUR_SERVER_URL"];
  38. ```
  39. ## Track Event
  40. ```objective-c
  41. instance.track("some_event");
  42. ```
  43. or
  44. ```objective-c
  45. [[GravityEngineSDK sharedInstanceWithAppid:@"YOUR_APPID"] track:@"some_event"];
  46. ```
  47. If you only have one instance in your project, you can also use
  48. ```objective-c
  49. [[GravityEngineSDK sharedInstance] track:@"some_event"];
  50. ```
  51. */
  52. typedef void (^CallbackWithSuccess)(NSDictionary *response);
  53. typedef void (^CallbackWithError)(NSError *error);
  54. @interface GravityEngineSDK : NSObject
  55. #pragma mark - Tracking
  56. /**
  57. Get default instance
  58. @return SDK instance
  59. */
  60. + (nullable GravityEngineSDK
  61. *)
  62. sharedInstance;
  63. /**
  64. Get one instance according to appid or instanceName
  65. @param appid APP ID or instanceName
  66. @return SDK instance
  67. */
  68. + (nullable GravityEngineSDK
  69. *)sharedInstanceWithAppid:(NSString *)
  70. appid;
  71. /**
  72. Initialization method
  73. After the SDK initialization is complete, the saved instance can be obtained through this api
  74. @param config initialization configuration
  75. @return one instance
  76. */
  77. + (GravityEngineSDK *)startWithConfig:(nullable GEConfig
  78. *)
  79. config;
  80. /**
  81. Initialization method
  82. After the SDK initialization is complete, the saved instance can be obtained through this api
  83. @param appId appId
  84. @param url server url
  85. @param config initialization configuration object
  86. @return one instance
  87. */
  88. + (GravityEngineSDK *)startWithAppId:(NSString *)appId withUrl:(NSString *)url withConfig:(nullable GEConfig
  89. *)
  90. config;
  91. #pragma mark - Other API
  92. /**
  93. register GravityEngine
  94. */
  95. - (void)initializeGravityEngineWithClientId:(NSString *)clientId withUserName:(NSString *)userName withVersion:(int)version withAsaEnable:(bool)enableAsa withIdfa:(NSString *)idfa withIdfv:(NSString *)idfv withCaid1:(NSString *)caid1_md5 withCaid2:(NSString *)caid2_md5 withSyncAttribution:(bool)syncAttribution withSuccessCallback:(CallbackWithSuccess)successCallback withErrorCallback:(CallbackWithError)errorCallback;
  96. - (void)initializeGravityEngineWithClientId:(NSString *)clientId withUserName:(NSString *)userName withVersion:(int)version withAsaEnable:(bool)enableAsa withIdfa:(NSString *)idfa withIdfv:(NSString *)idfv withCaid1:(NSString *)caid1_md5 withCaid2:(NSString *)caid2_md5 withSyncAttribution:(bool)syncAttribution withCreateTime:(long)createTimestamp withCompany:(NSString *)company withSuccessCallback:(CallbackWithSuccess)successCallback withErrorCallback:(CallbackWithError)errorCallback;
  97. - (void)queryUserInfoWithSuccessCallback:(void (^)(NSDictionary *_Nonnull
  98. data))successCallback withErrorCallback:(CallbackWithError)errorCallback;
  99. - (void)resetClientID:(NSString *)newClientID withSuccessCallback:(CallbackWithSuccess)successCallback withErrorCallback:(CallbackWithError)errorCallback;
  100. - (void)uploadDeviceInfoWithIdfa:(NSString *)idfa withIdfv:(NSString *)idfv withCaid1:(NSString *)caid1_md5 withCaid2:(NSString *)caid2_md5;
  101. /**
  102. * 上报业务注册事件
  103. *
  104. */
  105. - (void)trackRegisterEvent;
  106. /**
  107. * 上报付费事件
  108. *
  109. * @param payAmount 付费金额 单位为分
  110. * @param payType 货币类型 按照国际标准组织ISO 4217中规范的3位字母,例如CNY人民币、USD美金等
  111. * @param orderId 订单号
  112. * @param payReason 付费原因 例如:购买钻石、办理月卡
  113. * @param payMethod 付费方式 例如:支付宝、微信、银联等
  114. */
  115. - (void)trackPayEventWithAmount:(int)payAmount withPayType:(NSString *)payType withOrderId:(NSString *)orderId withPayReason:(NSString *)payReason withPayMethod:(NSString *)payMethod;
  116. /**
  117. * 上报提现事件
  118. *
  119. * @param payAmount 提现金额 单位为分
  120. * @param payType 货币类型 按照国际标准组织ISO 4217中规范的3位字母,例如CNY人民币、USD美金等
  121. * @param orderId 订单号
  122. * @param payReason 提现原因 例如:用户首次提现、用户抽奖提现
  123. * @param payMethod 提现支付方式 例如:支付宝、微信、银联等
  124. */
  125. - (void)trackWithdrawEvent:(int)payAmount withPayType:(NSString *)payType withOrderId:(NSString *)orderId withPayReason:(NSString *)payReason withPayMethod:(NSString *)payMethod;
  126. /**
  127. * 上报广告事件
  128. *
  129. * @param adUnionType 广告聚合平台类型 (取值为:topon、gromore、admore、self,分别对应Topon、Gromore、Admore、自建聚合)
  130. * @param adPlacementId 广告瀑布流ID
  131. * @param adSourceId 广告源ID
  132. * @param adType 广告类型 (取值为:reward、banner、 native 、interstitial、 splash ,分别对应激励视频广告、横幅广告、信息流广告、插屏广告、开屏广告)
  133. * @param adAdnType 广告平台类型(取值为:csj、gdt、ks、 mint 、baidu,分别对应为穿山甲、优量汇、快手联盟、Mintegral、百度联盟)
  134. * @param ecpm 预估ECPM价格(单位为元)
  135. * @param duration 广告播放时长(单位为秒)
  136. * @param isPlayOver 广告是否播放完毕
  137. */
  138. - (void)trackAdLoadEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType;
  139. - (void)trackAdShowEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType withEcpm:(NSNumber *)ecpm;
  140. - (void)trackAdSkipEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType withEcpm:(NSNumber *)ecpm;
  141. - (void)trackAdClickEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType withEcpm:(NSNumber *)ecpm;
  142. - (void)trackAdPlayStartEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType withEcpm:(NSNumber *)ecpm;
  143. - (void)trackAdPlayEndEventWithUninType:(NSString *)adUnionType withPlacementId:(NSString *)adPlacementId withSourceId:(NSString *)adSourceId withAdType:(NSString *)adType withAdnType:(NSString *)adAdnType withEcpm:(NSNumber *)ecpm withDruation:(NSNumber *)duration withIsPlayOver:(BOOL)isPlayOver;
  144. /**
  145. * 绑定数数账号
  146. *
  147. * @param taAccountId 数数的account_id
  148. * @param taDistinctId 数数的distinct_id
  149. */
  150. - (void)bindTAThirdPlatformWithAccountId:(NSString *)taAccountId withDistinctId:(NSString *)taDistinctId;
  151. #pragma mark - Action Track
  152. /**
  153. Track Events
  154. @param event event name
  155. */
  156. - (void)track:(NSString *)event;
  157. /**
  158. Track Events
  159. @param event event name
  160. @param propertieDict event properties
  161. */
  162. - (void)track:(NSString *)event properties:(nullable NSDictionary
  163. *)
  164. propertieDict;
  165. /**
  166. Track Events
  167. @param event event name
  168. @param propertieDict event properties
  169. @param time event trigger time
  170. */
  171. - (void)track:(NSString *)event properties:(nullable NSDictionary
  172. *)
  173. propertieDict time
  174. :(NSDate *)time __attribute__((deprecated("please use track:properties:time:timeZone: method")));
  175. /**
  176. Track Events
  177. @param event event name
  178. @param propertieDict event properties
  179. @param time event trigger time
  180. @param timeZone event trigger time time zone
  181. */
  182. - (void)track:(NSString *)event properties:(nullable NSDictionary
  183. *)
  184. propertieDict time
  185. :(NSDate *)
  186. time timeZone
  187. :(NSTimeZone *)
  188. timeZone;
  189. /**
  190. Track Events
  191. @param eventModel event Model
  192. */
  193. - (void)trackWithEventModel:(GEEventModel *)eventModel;
  194. /**
  195. Get the events collected in the App Extension and report them
  196. @param appGroupId The app group id required for data sharing
  197. */
  198. - (void)trackFromAppExtensionWithAppGroupId:(NSString *)appGroupId;
  199. #pragma mark -
  200. /**
  201. Timing Events
  202. Record the event duration, call this method to start the timing, stop the timing when the target event is uploaded, and add the attribute #duration to the event properties, in seconds.
  203. */
  204. - (void)timeEvent:(NSString *)event;
  205. /**
  206. Identify
  207. Set the distinct ID to replace the default UUID distinct ID.
  208. */
  209. - (void)identify:(NSString *)distinctId;
  210. /**
  211. Get Distinctid
  212. Get a visitor ID: The #distinct_id value in the reported data.
  213. */
  214. - (NSString *)getDistinctId;
  215. /**
  216. Get sdk version
  217. */
  218. + (NSString *)getSDKVersion;
  219. /**
  220. Login
  221. Set the account ID. Each setting overrides the previous value. Login events will be uploaded.
  222. @param clientId client ID
  223. */
  224. - (void)login:(NSString *)clientId;
  225. /**
  226. Logout with completion
  227. Clearing the account ID and upload user logout events.
  228. */
  229. - (void)logoutWithCompletion:(void (^)(void))completion;
  230. /**
  231. User_Set
  232. Sets the user property, replacing the original value with the new value if the property already exists.
  233. @param properties user properties
  234. */
  235. - (void)user_set:(NSDictionary *)properties;
  236. /**
  237. User_Set
  238. @param properties user properties
  239. @param time event trigger time
  240. */
  241. - (void)user_set:(NSDictionary *)properties withTime:(NSDate * _Nullable)time;
  242. /**
  243. User_Unset
  244. @param propertyName user properties
  245. */
  246. - (void)user_unset:(NSString *)propertyName;
  247. /**
  248. User_Unset
  249. Reset user properties.
  250. @param propertyName user properties
  251. @param time event trigger time
  252. */
  253. - (void)user_unset:(NSString *)propertyName withTime:(NSDate * _Nullable)time;
  254. /**
  255. User_SetOnce
  256. Sets a single user attribute, ignoring the new attribute value if the attribute already exists.
  257. @param properties user properties
  258. */
  259. - (void)user_set_once:(NSDictionary *)properties;
  260. /**
  261. User_SetOnce
  262. @param properties user properties
  263. @param time event trigger time
  264. */
  265. - (void)user_set_once:(NSDictionary *)properties withTime:(NSDate * _Nullable)time;
  266. /**
  267. User_Add
  268. Adds the numeric type user attributes.
  269. @param properties user properties
  270. */
  271. - (void)user_increment:(NSDictionary *)properties;
  272. /**
  273. User_Add
  274. @param properties user properties
  275. @param time event trigger time
  276. */
  277. - (void)user_increment:(NSDictionary *)properties withTime:(NSDate * _Nullable)time;
  278. /**
  279. User_Add
  280. @param propertyName propertyName
  281. @param propertyValue propertyValue
  282. */
  283. - (void)user_increment:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue;
  284. /**
  285. User_Add
  286. @param propertyName propertyName
  287. @param propertyValue propertyValue
  288. @param time event trigger time
  289. */
  290. - (void)user_increment:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue withTime:(NSDate * _Nullable)time;
  291. /**
  292. User_Number_Max
  293. Get max number and save it
  294. @param properties user properties
  295. */
  296. - (void)user_number_max:(NSDictionary *)properties;
  297. /**
  298. User_Number_Max
  299. @param properties user properties
  300. @param time event trigger time
  301. */
  302. - (void)user_number_max:(NSDictionary *)properties withTime:(NSDate * _Nullable)time;
  303. /**
  304. User_Number_Max
  305. @param propertyName propertyName
  306. @param propertyValue propertyValue
  307. */
  308. - (void)user_number_max:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue;
  309. /**
  310. User_Number_Max
  311. @param propertyName propertyName
  312. @param propertyValue propertyValue
  313. @param time event trigger time
  314. */
  315. - (void)user_number_max:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue withTime:(NSDate * _Nullable)time;
  316. /**
  317. User_Number_Min
  318. Get min number and save it
  319. @param properties user properties
  320. */
  321. - (void)user_number_min:(NSDictionary *)properties;
  322. /**
  323. User_Number_Min
  324. @param properties user properties
  325. @param time event trigger time
  326. */
  327. - (void)user_number_min:(NSDictionary *)properties withTime:(NSDate * _Nullable)time;
  328. /**
  329. User_Number_Min
  330. @param propertyName propertyName
  331. @param propertyValue propertyValue
  332. */
  333. - (void)user_number_min:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue;
  334. /**
  335. User_Number_Min
  336. @param propertyName propertyName
  337. @param propertyValue propertyValue
  338. @param time event trigger time
  339. */
  340. - (void)user_number_min:(NSString *)propertyName andPropertyValue:(NSNumber *)propertyValue withTime:(NSDate * _Nullable)time;
  341. /**
  342. User_Delete
  343. Delete the user attributes,This operation is not reversible and should be performed with caution.
  344. */
  345. - (void)user_delete;
  346. /**
  347. User_Delete
  348. @param time event trigger time
  349. */
  350. - (void)user_delete:(NSDate * _Nullable)time;
  351. /**
  352. User_Append
  353. Append a user attribute of the List type.
  354. @param properties user properties
  355. */
  356. - (void)user_append:(NSDictionary
  357. <NSString *, NSArray *> *)
  358. properties;
  359. /**
  360. User_Append
  361. The element appended to the library needs to be done to remove the processing,and then import.
  362. @param properties user properties
  363. @param time event trigger time
  364. */
  365. - (void)user_append:(NSDictionary
  366. <NSString *, NSArray *> *)
  367. properties withTime
  368. :(
  369. NSDate *_Nullable
  370. )
  371. time;
  372. /**
  373. User_UniqAppend
  374. @param properties user properties
  375. */
  376. - (void)user_uniqAppend:(NSDictionary
  377. <NSString *, NSArray *> *)
  378. properties;
  379. /**
  380. User_UniqAppend
  381. @param properties user properties
  382. @param time event trigger time
  383. */
  384. - (void)user_uniqAppend:(NSDictionary
  385. <NSString *, NSArray *> *)
  386. properties withTime
  387. :(
  388. NSDate *_Nullable
  389. )
  390. time;
  391. + (void)setCustomerLibInfoWithLibName:(NSString *)libName libVersion:(NSString *)libVersion;
  392. /**
  393. Static Super Properties
  394. Set the public event attribute, which will be included in every event uploaded after that. The public event properties are saved without setting them each time.
  395. *
  396. */
  397. - (void)setSuperProperties:(NSDictionary *)properties;
  398. /**
  399. Unset Super Property
  400. Clears a public event attribute.
  401. */
  402. - (void)unsetSuperProperty:(NSString *)property;
  403. /**
  404. Clear Super Properties
  405. Clear all public event attributes.
  406. */
  407. - (void)clearSuperProperties;
  408. /**
  409. Get Static Super Properties
  410. Gets the public event properties that have been set.
  411. */
  412. - (NSDictionary *)currentSuperProperties;
  413. /**
  414. Dynamic super properties
  415. Set dynamic public properties. Each event uploaded after that will contain a public event attribute.
  416. */
  417. - (void)registerDynamicSuperProperties:(NSDictionary
  418. <NSString *, id> *(^)(void))
  419. dynamicSuperProperties;
  420. /**
  421. Gets prefabricated properties for all events.
  422. */
  423. - (GEPresetProperties *)getPresetProperties;
  424. /**
  425. Set the network conditions for uploading. By default, the SDK will set the network conditions as 3G, 4G and Wifi to upload data
  426. */
  427. - (void)setNetworkType:(GravityEngineNetworkType)type;
  428. #if TARGET_OS_IOS
  429. /**
  430. Enable Auto-Tracking
  431. @param eventType Auto-Tracking type
  432. */
  433. - (void)enableAutoTrack:(GravityEngineAutoTrackEventType)eventType;
  434. /**
  435. Enable the auto tracking function.
  436. @param eventType Auto-Tracking type
  437. @param properties properties
  438. */
  439. - (void)enableAutoTrack:(GravityEngineAutoTrackEventType)eventType properties:(NSDictionary *)properties;
  440. /**
  441. Enable the auto tracking function.
  442. @param eventType Auto-Tracking type
  443. @param callback callback
  444. In the callback, eventType indicates the type of automatic collection, properties indicates the event properties before storage, and this block can return a dictionary for adding new properties
  445. */
  446. - (void)enableAutoTrack:(GravityEngineAutoTrackEventType)eventType callback:(NSDictionary *(^)(GravityEngineAutoTrackEventType eventType, NSDictionary *properties))callback;
  447. /**
  448. Set and Update the value of a custom property for Auto-Tracking
  449. @param eventType A list of GravityEngineAutoTrackEventType, indicating the types of automatic collection events that need to be enabled
  450. @param properties properties
  451. */
  452. - (void)setAutoTrackProperties:(GravityEngineAutoTrackEventType)eventType properties:(NSDictionary *)properties;
  453. /**
  454. Ignore the Auto-Tracking of a page
  455. @param controllers Ignore the name of the UIViewController
  456. */
  457. - (void)ignoreAutoTrackViewControllers:(NSArray *)controllers;
  458. /**
  459. Ignore the Auto-Tracking of click event
  460. @param aClass ignored controls Class
  461. */
  462. - (void)ignoreViewType:(Class)aClass;
  463. #endif
  464. //MARK: -
  465. /**
  466. Get DeviceId
  467. */
  468. - (NSString *)getDeviceId;
  469. - (NSString *)getCurrentClientId;
  470. /**
  471. H5 is connected with the native APP SDK and used in conjunction with the addWebViewUserAgent interface
  472. @param webView webView
  473. @param request NSURLRequest request
  474. @return YES:Process this request NO: This request has not been processed
  475. */
  476. - (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request;
  477. /**
  478. When connecting data with H5, you need to call this interface to configure UserAgent
  479. */
  480. //- (void)addWebViewUserAgent;
  481. /**
  482. Set Log level
  483. */
  484. + (void)setLogLevel:(GELoggingLevel)level;
  485. /**
  486. Empty the cache queue. When this api is called, the data in the current cache queue will attempt to be reported.
  487. If the report succeeds, local cache data will be deleted.
  488. */
  489. - (void)flush;
  490. - (void)flushWithCompletion:(void (^)(void))completion;
  491. - (void)testTest;
  492. /**
  493. Switch reporting status
  494. @param status GETrackStatus reporting status
  495. */
  496. - (void)setTrackStatus:(GETrackStatus)status;
  497. + (void)calibrateTimeWithNtp:(NSString *)ntpServer;
  498. + (void)calibrateTime:(NSTimeInterval)timestamp;
  499. - (NSString *)getTimeString:(NSDate *)date;
  500. #if TARGET_OS_IOS
  501. - (void)enableThirdPartySharing:(GEThirdPartyShareType)type;
  502. - (void)enableThirdPartySharing:(GEThirdPartyShareType)type customMap:(NSDictionary<NSString *, NSObject *> *)customMap;
  503. #endif
  504. + (nullable NSString
  505. *)
  506. getLocalRegion;
  507. @end
  508. NS_ASSUME_NONNULL_END