GravityEngineSDK.h 18 KB

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