GravityEngineSDK.h 18 KB

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