You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AmplitudeModule.m 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright @ 2018-present 8x8, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <React/RCTBridgeModule.h>
  17. #import "Amplitude.h"
  18. @interface AmplitudeModule : NSObject<RCTBridgeModule>
  19. @end
  20. @implementation AmplitudeModule
  21. RCT_EXPORT_MODULE(Amplitude)
  22. + (BOOL)requiresMainQueueSetup {
  23. return NO;
  24. }
  25. RCT_EXPORT_METHOD(init:(NSString*)instanceName API_KEY:(NSString*)apiKey) {
  26. [[Amplitude instanceWithName:instanceName] initializeApiKey:apiKey];
  27. }
  28. RCT_EXPORT_METHOD(setUserId:(NSString*)instanceName userId: (NSString *) userId) {
  29. [[Amplitude instanceWithName:instanceName] setUserId:userId];
  30. }
  31. RCT_EXPORT_METHOD(setUserProperties:(NSString*)instanceName userPropsString:(NSDictionary*)userProps) {
  32. if (userProps != nil) {
  33. [[Amplitude instanceWithName:instanceName] setUserProperties:userProps];
  34. }
  35. }
  36. RCT_EXPORT_METHOD(logEvent:(NSString*)instanceName eventType:(NSString*)eventType eventPropsString:(NSString*)eventPropsString) {
  37. NSError *error;
  38. NSData *eventPropsData = [eventPropsString dataUsingEncoding:NSUTF8StringEncoding];
  39. NSDictionary *eventProperties = [NSJSONSerialization JSONObjectWithData:eventPropsData
  40. options:NSJSONReadingMutableContainers
  41. error:&error];
  42. if (eventProperties == nil) {
  43. NSLog(@"[Amplitude handler] Error parsing event properties: %@", error);
  44. } else {
  45. [[Amplitude instanceWithName:instanceName] logEvent:eventType withEventProperties:eventProperties];
  46. }
  47. }
  48. @end