XSCollector.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // XSCollector.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XSCollector.h"
  9. #import "TalkingDataGA.h"
  10. #import "TalkingDataAppCpa.h"
  11. @interface XSCollector ()
  12. @property (nonatomic, strong) NSString* uid;
  13. @property (nonatomic, strong) TDGAAccount* account;
  14. @end
  15. @implementation XSCollector
  16. - (instancetype)initWithAppId:(id)appId gameId:(id)gameId {
  17. self = [super init];
  18. [TalkingDataAppCpa setVerboseLogDisabled];
  19. [TalkingDataGA setVerboseLogDisabled];
  20. [TalkingDataAppCpa init:appId withChannelId:gameId];
  21. [TalkingDataGA onStart:gameId withChannelId:@"AppStore"];
  22. return self;
  23. }
  24. XSCollector* sdk_XSCollector_shared;
  25. + (void)setShared:(XSCollector*)tracker {
  26. sdk_XSCollector_shared = tracker;
  27. }
  28. + (XSCollector*)shared {
  29. return sdk_XSCollector_shared;
  30. }
  31. /// Get the unique identifier of talking data.
  32. - (NSString*)identifer {
  33. return [TalkingDataAppCpa getDeviceId];
  34. }
  35. /// Register a user for data analyzer.
  36. - (void)registerWithAccount:(NSString*)account name:(NSString*)name {
  37. self.uid = account;
  38. self.account = [TDGAAccount setAccount:account];
  39. [self.account setAccountName:name];
  40. [TalkingDataAppCpa onRegister:account];
  41. }
  42. /// Login a user for data analyzer.
  43. - (void)loginWithAccount:(NSString*)account name:(NSString*)name {
  44. self.uid = account;
  45. self.account = [TDGAAccount setAccount:account];
  46. [self.account setAccountName:name];
  47. [self.account setAccountType:kAccountRegistered];
  48. [TalkingDataAppCpa onLogin:account];
  49. }
  50. /// Update account.
  51. - (void)reportWithAccount:(NSString*)account name:(NSString*)name level:(NSInteger)level server:(NSString*)server {
  52. if (self.uid.length == 0) {
  53. return;
  54. }
  55. TDGAAccount* fa = [TDGAAccount setAccount:self.uid];
  56. [fa setLevel:(int)level];
  57. [fa setAccountName:name];
  58. [fa setGameServer:server];
  59. [fa setAccountType:kAccountRegistered];
  60. [TalkingDataAppCpa onCreateRole:name];
  61. }
  62. @end