PPFPTITracker.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PPFPTITracker.m
  3. // PayPalOneTouch
  4. //
  5. // Copyright © 2015 PayPal, Inc. All rights reserved.
  6. //
  7. #import <UIKit/UIKit.h>
  8. #import "PPFPTITracker.h"
  9. #import "PPFPTIData.h"
  10. #if __has_include("PayPalUtils.h")
  11. #import "PPOTDevice.h"
  12. #import "PPOTVersion.h"
  13. #else
  14. #import <PayPalUtils/PPOTDevice.h>
  15. #import <PayPalUtils/PPOTVersion.h>
  16. #endif
  17. static NSString* const kTrackerURLAsNSString = @"https://api-m.paypal.com/v1/tracking/events";
  18. @interface PPFPTITracker ()
  19. @property (nonatomic, copy, readwrite) NSString *deviceUDID;
  20. @property (nonatomic, copy, readwrite) NSString *sessionID;
  21. @property (nonatomic, copy, readwrite) NSURL *trackerURL;
  22. @property (nonatomic, copy, readwrite) NSString *userAgent;
  23. @end
  24. @implementation PPFPTITracker
  25. - (instancetype)initWithDeviceUDID:(NSString *)deviceUDID
  26. sessionID:(NSString *)sessionID
  27. networkAdapterDelegate:(id<PPFPTINetworkAdapterDelegate>)networkAdapterDelegate {
  28. if (self = [super init]) {
  29. self.deviceUDID = deviceUDID;
  30. self.sessionID = sessionID;
  31. self.trackerURL = [NSURL URLWithString:kTrackerURLAsNSString];
  32. self.userAgent = [self computeUserAgent];
  33. self.networkAdapterDelegate = networkAdapterDelegate;
  34. }
  35. return self;
  36. }
  37. - (void)submitEventWithParams:(NSDictionary *)params {
  38. PPFPTIData *data = [[PPFPTIData alloc] initWithParams:params
  39. deviceID:self.deviceUDID
  40. sessionID:self.sessionID
  41. userAgent:self.userAgent
  42. trackerURL:self.trackerURL];
  43. if (self.networkAdapterDelegate) {
  44. [self.networkAdapterDelegate sendRequestWithData:data];
  45. }
  46. }
  47. - (NSString *)computeUserAgent {
  48. NSLocale *currentLocale = [NSLocale currentLocale];
  49. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
  50. NSString *language = [currentLocale objectForKey:NSLocaleLanguageCode];
  51. #ifdef DEBUG
  52. NSString *releaseMode = @"DEBUG";
  53. #else
  54. NSString *releaseMode = @"RELEASE";
  55. #endif
  56. // PayPalSDK/OneTouchCore-iOS 3.2.2-11-g8b1c0e3 (iPhone; CPU iPhone OS 8_4_1; en-US; iPhone (iPhone5,1); iPhone5,1; DEBUG)
  57. return [NSString stringWithFormat:@"PayPalSDK/OneTouchCore-iOS %@ (%@; CPU %@ %@; %@-%@; %@; %@; %@)",
  58. PayPalOTVersion(),
  59. [UIDevice currentDevice].model,
  60. [UIDevice currentDevice].systemName,
  61. [[UIDevice currentDevice].systemVersion stringByReplacingOccurrencesOfString:@"." withString:@"_"],
  62. language,
  63. countryCode,
  64. [PPOTDevice deviceName],
  65. [PPOTDevice hardwarePlatform],
  66. releaseMode
  67. ];
  68. }
  69. @end