react-native-mparticle 2.7.13 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SECURITY.md +9 -0
- package/android/build.gradle +65 -10
- package/android/src/main/AndroidManifestNew.xml +3 -0
- package/android/src/main/java/com/mparticle/react/MParticleModule.kt +976 -0
- package/android/src/main/java/com/mparticle/react/MParticlePackage.kt +68 -0
- package/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt +251 -0
- package/android/src/main/java/com/mparticle/react/rokt/RoktLayoutViewManagerImpl.kt +79 -0
- package/android/src/newarch/java/com/mparticle/react/rokt/MPRoktModule.kt +130 -0
- package/android/src/newarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt +22 -0
- package/android/src/oldarch/java/com/mparticle/react/NativeMPRoktSpec.kt +29 -0
- package/android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt +153 -0
- package/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt +79 -0
- package/android/src/oldarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt +34 -0
- package/ios/RNMParticle/RNMPRokt.h +15 -0
- package/ios/RNMParticle/RNMPRokt.mm +247 -0
- package/ios/RNMParticle/RNMParticle.h +6 -1
- package/ios/RNMParticle/RNMParticle.mm +1199 -0
- package/ios/RNMParticle/RoktEventManager.h +16 -0
- package/ios/RNMParticle/RoktEventManager.m +174 -0
- package/ios/RNMParticle/RoktLayoutManager.m +22 -0
- package/ios/RNMParticle/RoktNativeLayoutComponentView.h +18 -0
- package/ios/RNMParticle/RoktNativeLayoutComponentView.mm +50 -0
- package/ios/RNMParticle.xcodeproj/project.pbxproj +29 -6
- package/js/codegenSpecs/NativeMParticle.ts +214 -0
- package/js/codegenSpecs/rokt/NativeMPRokt.ts +32 -0
- package/js/codegenSpecs/rokt/RoktLayoutNativeComponent.ts +29 -0
- package/js/index.tsx +940 -0
- package/js/rokt/rokt-layout-view.android.tsx +133 -0
- package/js/rokt/rokt-layout-view.ios.tsx +121 -0
- package/js/rokt/rokt-layout-view.tsx +15 -0
- package/js/rokt/rokt.ts +87 -0
- package/js/utils/architecture.ts +22 -0
- package/lib/codegenSpecs/NativeMParticle.d.ts +148 -0
- package/lib/codegenSpecs/NativeMParticle.js +5 -0
- package/lib/codegenSpecs/NativeMParticle.js.map +1 -0
- package/lib/codegenSpecs/rokt/NativeMPRokt.d.ts +24 -0
- package/lib/codegenSpecs/rokt/NativeMPRokt.js +5 -0
- package/lib/codegenSpecs/rokt/NativeMPRokt.js.map +1 -0
- package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.d.ts +18 -0
- package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.js +8 -0
- package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.js.map +1 -0
- package/lib/index.d.ts +410 -0
- package/lib/index.js +645 -0
- package/lib/index.js.map +1 -0
- package/lib/rokt/rokt-layout-view.android.d.ts +39 -0
- package/lib/rokt/rokt-layout-view.android.js +109 -0
- package/lib/rokt/rokt-layout-view.android.js.map +1 -0
- package/lib/rokt/rokt-layout-view.d.ts +5 -0
- package/lib/rokt/rokt-layout-view.ios.d.ts +32 -0
- package/lib/rokt/rokt-layout-view.ios.js +84 -0
- package/lib/rokt/rokt-layout-view.ios.js.map +1 -0
- package/lib/rokt/rokt-layout-view.js +12 -0
- package/lib/rokt/rokt-layout-view.js.map +1 -0
- package/lib/rokt/rokt.d.ts +40 -0
- package/lib/rokt/rokt.js +54 -0
- package/lib/rokt/rokt.js.map +1 -0
- package/lib/utils/architecture.d.ts +9 -0
- package/lib/utils/architecture.js +19 -0
- package/lib/utils/architecture.js.map +1 -0
- package/package.json +32 -10
- package/react-native-mparticle.podspec +7 -6
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -8
- package/.github/dependabot.yml +0 -12
- package/.github/workflows/daily.yml +0 -19
- package/.github/workflows/dependabot-automerge.yml +0 -12
- package/.github/workflows/pull-request.yml +0 -60
- package/.github/workflows/release.yml +0 -60
- package/.github/workflows/sonarcloud.yml +0 -16
- package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.5.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradle.properties +0 -53
- package/android/gradlew +0 -160
- package/android/gradlew.bat +0 -90
- package/android/libs/java-json.jar +0 -0
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar +0 -0
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar +0 -0
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar +0 -0
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar +0 -0
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module +0 -204
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom +0 -44
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml +0 -13
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar +0 -0
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar +0 -0
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar +0 -0
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar +0 -0
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module +0 -628
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom +0 -156
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha512 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml +0 -13
- package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.md5 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha1 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha256 +0 -1
- package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha512 +0 -1
- package/android/src/main/java/com/mparticle/react/MParticleModule.java +0 -987
- package/android/src/main/java/com/mparticle/react/MParticlePackage.java +0 -34
- package/android/src/test/java/com/mparticle/react/IdentityApiTest.java +0 -230
- package/android/src/test/java/com/mparticle/react/MParticleUserTest.java +0 -233
- package/android/src/test/java/com/mparticle/react/testutils/MockMParticleUser.java +0 -103
- package/android/src/test/java/com/mparticle/react/testutils/MockMap.java +0 -169
- package/android/src/test/java/com/mparticle/react/testutils/MockReadableArray.java +0 -53
- package/android/src/test/java/com/mparticle/react/testutils/MockWritableMap.java +0 -4
- package/android/src/test/java/com/mparticle/react/testutils/Mutable.java +0 -13
- package/ios/RNMParticle/RNMParticle.m +0 -678
- package/ios/RNMParticle.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RNMParticle.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/RNMParticle.xcodeproj/project.xcworkspace/xcuserdata/bstalnaker.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RNMParticle.xcodeproj/xcuserdata/bstalnaker.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/js/index.js +0 -697
- package/release.sh +0 -6
|
@@ -0,0 +1,1199 @@
|
|
|
1
|
+
#import "RNMParticle.h"
|
|
2
|
+
#import <React/RCTConvert.h>
|
|
3
|
+
#if defined(__has_include) && __has_include(<mParticle_Apple_SDK/mParticle.h>)
|
|
4
|
+
#import <mParticle_Apple_SDK/mParticle.h>
|
|
5
|
+
#elif defined(__has_include) && __has_include(<mParticle_Apple_SDK_NoLocation/mParticle.h>)
|
|
6
|
+
#import <mParticle_Apple_SDK_NoLocation/mParticle.h>
|
|
7
|
+
#else
|
|
8
|
+
#import <mParticle_Apple_SDK/Include/mParticle.h>
|
|
9
|
+
#endif
|
|
10
|
+
#if defined(__has_include) && __has_include(<mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>)
|
|
11
|
+
#import <mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>
|
|
12
|
+
#elif defined(__has_include) && __has_include(<mParticle_Apple_SDK_NoLocation/mParticle_Apple_SDK-Swift.h>)
|
|
13
|
+
#import <mParticle_Apple_SDK_NoLocation/mParticle_Apple_SDK-Swift.h>
|
|
14
|
+
#else
|
|
15
|
+
#import "mParticle_Apple_SDK-Swift.h"
|
|
16
|
+
#endif
|
|
17
|
+
#import <React/RCTConvert.h>
|
|
18
|
+
|
|
19
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
20
|
+
#import <RNMParticle/RNMParticle.h>
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
@interface MParticleUser ()
|
|
24
|
+
|
|
25
|
+
- (void)setUserId:(NSNumber *)userId;
|
|
26
|
+
@end
|
|
27
|
+
|
|
28
|
+
@implementation RNMParticle
|
|
29
|
+
|
|
30
|
+
RCT_EXTERN void RCTRegisterModule(Class);
|
|
31
|
+
|
|
32
|
+
+ (NSString *)moduleName {
|
|
33
|
+
return @"RNMParticle";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
+ (void)load {
|
|
37
|
+
RCTRegisterModule(self);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
RCT_EXPORT_METHOD(upload)
|
|
41
|
+
{
|
|
42
|
+
[[MParticle sharedInstance] upload];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
RCT_EXPORT_METHOD(setLocation:(double)latitude longitude:(double)longitude)
|
|
46
|
+
{
|
|
47
|
+
CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
|
|
48
|
+
[MParticle sharedInstance].location = newLocation;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
RCT_EXPORT_METHOD(setUploadInterval:(double)uploadInterval)
|
|
52
|
+
{
|
|
53
|
+
[[MParticle sharedInstance] setUploadInterval:uploadInterval];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
RCT_EXPORT_METHOD(logEvent:(NSString *)eventName eventType:(double)eventType attributes:(NSDictionary *)attributes)
|
|
57
|
+
{
|
|
58
|
+
[[MParticle sharedInstance] logEvent:eventName eventType:(MPEventType)eventType eventInfo:attributes];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
RCT_EXPORT_METHOD(logScreenEvent:(NSString *)screenName attributes:(NSDictionary *)attributes shouldUploadEvent:(BOOL)shouldUploadEvent)
|
|
62
|
+
{
|
|
63
|
+
[[MParticle sharedInstance] logScreen:screenName eventInfo:attributes shouldUploadEvent:shouldUploadEvent];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
RCT_EXPORT_METHOD(setATTStatus:(double)status withATTStatusTimestampMillis:(nonnull NSNumber *)timestamp)
|
|
67
|
+
{
|
|
68
|
+
[[MParticle sharedInstance] setATTStatus:(MPATTAuthorizationStatus)status withATTStatusTimestampMillis:timestamp];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
RCT_EXPORT_METHOD(setATTStatus:(double)status)
|
|
72
|
+
{
|
|
73
|
+
[[MParticle sharedInstance] setATTStatus:(MPATTAuthorizationStatus)status withATTStatusTimestampMillis:nil];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
RCT_EXPORT_METHOD(setATTStatusWithCustomTimestamp:(double)status timestamp:(double)timestamp)
|
|
77
|
+
{
|
|
78
|
+
[[MParticle sharedInstance] setATTStatus:(MPATTAuthorizationStatus)status withATTStatusTimestampMillis:@(timestamp)];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
RCT_EXPORT_METHOD(setOptOut:(BOOL)optOut)
|
|
82
|
+
{
|
|
83
|
+
[[MParticle sharedInstance] setOptOut:optOut];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
RCT_EXPORT_METHOD(getOptOut:(RCTResponseSenderBlock)completion)
|
|
87
|
+
{
|
|
88
|
+
BOOL optedOut = [[MParticle sharedInstance] optOut];
|
|
89
|
+
completion(@[[NSNumber numberWithBool:optedOut]]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
RCT_EXPORT_METHOD(removeGDPRConsentStateWithPurpose:(NSString *)purpose)
|
|
93
|
+
{
|
|
94
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
95
|
+
|
|
96
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
97
|
+
[consentState removeGDPRConsentStateWithPurpose:purpose];
|
|
98
|
+
user.consentState = consentState;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
RCT_EXPORT_METHOD(removeCCPAConsentState)
|
|
102
|
+
{
|
|
103
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
104
|
+
|
|
105
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
106
|
+
[consentState removeCCPAConsentState];
|
|
107
|
+
user.consentState = consentState;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#if TARGET_OS_IOS == 1
|
|
111
|
+
RCT_EXPORT_METHOD(logPushRegistration:(NSString *)token senderId:(NSString *)senderId)
|
|
112
|
+
{
|
|
113
|
+
// iOS Token
|
|
114
|
+
if (token != nil) {
|
|
115
|
+
NSData* pushTokenData = [token dataUsingEncoding:NSUTF8StringEncoding];
|
|
116
|
+
MParticle* instance = [MParticle sharedInstance];
|
|
117
|
+
instance.pushNotificationToken = pushTokenData;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
RCT_EXPORT_METHOD(isKitActive:(double)kitId callback:(RCTResponseSenderBlock)callback)
|
|
123
|
+
{
|
|
124
|
+
BOOL active = [[MParticle sharedInstance] isKitActive:@(kitId)];
|
|
125
|
+
callback(@[[NSNumber numberWithBool:active]]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
RCT_EXPORT_METHOD(getAttributions:(RCTResponseSenderBlock)callback)
|
|
129
|
+
{
|
|
130
|
+
NSDictionary<NSNumber *, MPAttributionResult *> *attributions = [[MParticle sharedInstance]attributionInfo];
|
|
131
|
+
NSMutableDictionary*dictionary = [[NSMutableDictionary alloc]init];
|
|
132
|
+
for (NSNumber *kitId in attributions) {
|
|
133
|
+
MPAttributionResult *attributionResult = attributions[kitId];
|
|
134
|
+
NSMutableDictionary *attributionDict = [[NSMutableDictionary alloc]initWithCapacity:2];
|
|
135
|
+
if (attributionResult.linkInfo != nil) {
|
|
136
|
+
attributionDict[@"linkParameters"] = attributionResult.linkInfo;
|
|
137
|
+
}
|
|
138
|
+
if (attributionResult.kitCode != nil) {
|
|
139
|
+
attributionDict[@"kitId"] = attributionResult.kitCode;
|
|
140
|
+
}
|
|
141
|
+
dictionary[[kitId stringValue]] = attributionDict;
|
|
142
|
+
}
|
|
143
|
+
callback(@[dictionary]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
RCT_EXPORT_METHOD(setUserAttribute:(NSString *)mpid key:(NSString *)key value:(NSString *)value)
|
|
147
|
+
{
|
|
148
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
149
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
150
|
+
[selectedUser setUserAttribute:key
|
|
151
|
+
value:value];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
RCT_EXPORT_METHOD(setUserAttributeArray:(NSString *)mpid key:(NSString *)key value:(NSArray *)value)
|
|
155
|
+
{
|
|
156
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
157
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
158
|
+
[selectedUser setUserAttributeList:key
|
|
159
|
+
values:value];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
RCT_EXPORT_METHOD(getUserAttributes:(NSString *)mpid callback:(RCTResponseSenderBlock)callback)
|
|
163
|
+
{
|
|
164
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
165
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
166
|
+
callback(@[[NSNull null], [selectedUser userAttributes]]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
RCT_EXPORT_METHOD(setUserTag:(NSString *)mpid tag:(NSString *)tag)
|
|
170
|
+
{
|
|
171
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
172
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
173
|
+
[selectedUser setUserTag:tag];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
RCT_EXPORT_METHOD(removeUserAttribute:(NSString *)mpid key:(NSString *)key)
|
|
177
|
+
{
|
|
178
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
179
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
180
|
+
[selectedUser removeUserAttribute:key];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
RCT_EXPORT_METHOD(incrementUserAttribute:(NSString *)mpid key:(NSString *)key value:(double)value)
|
|
184
|
+
{
|
|
185
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
186
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
187
|
+
[selectedUser incrementUserAttribute:key
|
|
188
|
+
byValue:@(value)];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
RCT_EXPORT_METHOD(identify:(MPIdentityApiRequest *)identityRequest completion:(RCTResponseSenderBlock)completion)
|
|
192
|
+
{
|
|
193
|
+
[[[MParticle sharedInstance] identity] identify:identityRequest completion:^(MPIdentityApiResult * _Nullable apiResult, NSError * _Nullable error) {
|
|
194
|
+
NSMutableDictionary *reactError;
|
|
195
|
+
if (error) {
|
|
196
|
+
reactError = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
197
|
+
MPIdentityHTTPErrorResponse *response = error.userInfo[mParticleIdentityErrorKey];
|
|
198
|
+
|
|
199
|
+
if ([response isKindOfClass:[NSString class]]) {
|
|
200
|
+
[reactError setObject:response forKey:@"message"];
|
|
201
|
+
} else {
|
|
202
|
+
if ([NSNumber numberWithLong:response.httpCode] != nil) {
|
|
203
|
+
[reactError setObject:[NSNumber numberWithLong:response.httpCode] forKey:@"httpCode"];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if ([NSNumber numberWithInt:response.code] != nil) {
|
|
207
|
+
[reactError setObject:[NSNumber numberWithInt:response.code] forKey:@"responseCode"];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (response.message != nil) {
|
|
211
|
+
[reactError setObject:response.message forKey:@"message"];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (apiResult != nil) {
|
|
215
|
+
completion(@[reactError, apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
216
|
+
} else {
|
|
217
|
+
completion(@[reactError, @0]);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
completion(@[[NSNull null], apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
221
|
+
}
|
|
222
|
+
}];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
RCT_EXPORT_METHOD(login:(MPIdentityApiRequest *)identityRequest completion:(RCTResponseSenderBlock)completion)
|
|
226
|
+
{
|
|
227
|
+
[[[MParticle sharedInstance] identity] login:identityRequest completion:^(MPIdentityApiResult * _Nullable apiResult, NSError * _Nullable error) {
|
|
228
|
+
NSMutableDictionary *reactError;
|
|
229
|
+
if (error) {
|
|
230
|
+
reactError = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
231
|
+
MPIdentityHTTPErrorResponse *response = error.userInfo[mParticleIdentityErrorKey];
|
|
232
|
+
|
|
233
|
+
if ([response isKindOfClass:[NSString class]]) {
|
|
234
|
+
[reactError setObject:response forKey:@"message"];
|
|
235
|
+
} else {
|
|
236
|
+
if ([NSNumber numberWithLong:response.httpCode] != nil) {
|
|
237
|
+
[reactError setObject:[NSNumber numberWithLong:response.httpCode] forKey:@"httpCode"];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if ([NSNumber numberWithInt:response.code] != nil) {
|
|
241
|
+
[reactError setObject:[NSNumber numberWithInt:response.code] forKey:@"responseCode"];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (response.message != nil) {
|
|
245
|
+
[reactError setObject:response.message forKey:@"message"];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (apiResult != nil) {
|
|
249
|
+
completion(@[reactError, apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
250
|
+
} else {
|
|
251
|
+
completion(@[reactError, @0]);
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
completion(@[[NSNull null], apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
255
|
+
}
|
|
256
|
+
}];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
RCT_EXPORT_METHOD(logout:(MPIdentityApiRequest *)identityRequest completion:(RCTResponseSenderBlock)completion)
|
|
260
|
+
{
|
|
261
|
+
[[[MParticle sharedInstance] identity] logout:identityRequest completion:^(MPIdentityApiResult * _Nullable apiResult, NSError * _Nullable error) {
|
|
262
|
+
NSMutableDictionary *reactError;
|
|
263
|
+
if (error) {
|
|
264
|
+
reactError = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
265
|
+
MPIdentityHTTPErrorResponse *response = error.userInfo[mParticleIdentityErrorKey];
|
|
266
|
+
|
|
267
|
+
if ([response isKindOfClass:[NSString class]]) {
|
|
268
|
+
[reactError setObject:response forKey:@"message"];
|
|
269
|
+
} else {
|
|
270
|
+
if ([NSNumber numberWithLong:response.httpCode] != nil) {
|
|
271
|
+
[reactError setObject:[NSNumber numberWithLong:response.httpCode] forKey:@"httpCode"];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ([NSNumber numberWithInt:response.code] != nil) {
|
|
275
|
+
[reactError setObject:[NSNumber numberWithInt:response.code] forKey:@"responseCode"];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (response.message != nil) {
|
|
279
|
+
[reactError setObject:response.message forKey:@"message"];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (apiResult != nil) {
|
|
283
|
+
completion(@[reactError, apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
284
|
+
} else {
|
|
285
|
+
completion(@[reactError, @0]);
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
completion(@[[NSNull null], apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
289
|
+
}
|
|
290
|
+
}];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
RCT_EXPORT_METHOD(modify:(MPIdentityApiRequest *)identityRequest completion:(RCTResponseSenderBlock)completion)
|
|
294
|
+
{
|
|
295
|
+
[[[MParticle sharedInstance] identity] modify:identityRequest completion:^(MPIdentityApiResult * _Nullable apiResult, NSError * _Nullable error) {
|
|
296
|
+
NSMutableDictionary *reactError;
|
|
297
|
+
if (error) {
|
|
298
|
+
reactError = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
299
|
+
MPIdentityHTTPErrorResponse *response = error.userInfo[mParticleIdentityErrorKey];
|
|
300
|
+
|
|
301
|
+
if ([response isKindOfClass:[NSString class]]) {
|
|
302
|
+
[reactError setObject:response forKey:@"message"];
|
|
303
|
+
} else {
|
|
304
|
+
if ([NSNumber numberWithLong:response.httpCode] != nil) {
|
|
305
|
+
[reactError setObject:[NSNumber numberWithLong:response.httpCode] forKey:@"httpCode"];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if ([NSNumber numberWithInt:response.code] != nil) {
|
|
309
|
+
[reactError setObject:[NSNumber numberWithInt:response.code] forKey:@"responseCode"];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (response.message != nil) {
|
|
313
|
+
[reactError setObject:response.message forKey:@"message"];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (apiResult != nil) {
|
|
317
|
+
completion(@[reactError, apiResult.user.userId.stringValue, [NSNull null]]);
|
|
318
|
+
} else {
|
|
319
|
+
completion(@[reactError, @0]);
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
completion(@[[NSNull null], apiResult.user.userId.stringValue, [NSNull null]]);
|
|
323
|
+
}
|
|
324
|
+
}];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
RCT_EXPORT_METHOD(aliasUsers:(MPAliasRequest *) aliasRequest completion:(RCTResponseSenderBlock)completion)
|
|
328
|
+
{
|
|
329
|
+
BOOL success = [[[MParticle sharedInstance] identity] aliasUsers:aliasRequest];
|
|
330
|
+
completion(@[[NSNull null], success ? @"true" : @"false"]);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
RCT_EXPORT_METHOD(getCurrentUserWithCompletion:(RCTResponseSenderBlock)callback)
|
|
334
|
+
{
|
|
335
|
+
callback(@[[NSNull null], [[[MParticle sharedInstance] identity] currentUser].userId.stringValue]);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
RCT_EXPORT_METHOD(getUserIdentities:(NSString *)mpid callback:(RCTResponseSenderBlock)callback)
|
|
339
|
+
{
|
|
340
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
341
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
342
|
+
callback(@[[NSNull null], [selectedUser identities]]);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
RCT_EXPORT_METHOD(getFirstSeen:(NSString *)mpid callback:(RCTResponseSenderBlock)callback)
|
|
346
|
+
{
|
|
347
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
348
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
349
|
+
callback(@[[NSNull null], [selectedUser firstSeen]]);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
RCT_EXPORT_METHOD(getLastSeen:(NSString *)mpid callback:(RCTResponseSenderBlock)callback)
|
|
353
|
+
{
|
|
354
|
+
MParticleUser *selectedUser = [[MParticleUser alloc] init];
|
|
355
|
+
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
|
|
356
|
+
callback(@[[NSNull null], [selectedUser lastSeen]]);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
RCT_EXPORT_METHOD(getSession:(RCTResponseSenderBlock)completion)
|
|
360
|
+
{
|
|
361
|
+
MParticleSession *session = [MParticle sharedInstance].currentSession;
|
|
362
|
+
if (session && session.UUID) {
|
|
363
|
+
completion(@[session.UUID]);
|
|
364
|
+
} else {
|
|
365
|
+
completion(@[[NSNull null]]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// New Architecture Protocol Methods - Incompatible types only
|
|
370
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
371
|
+
|
|
372
|
+
- (void)aliasUsers:(JS::NativeMParticle::AliasRequest &)aliasRequest callback:(RCTResponseSenderBlock)callback {
|
|
373
|
+
// Create MPAliasRequest directly from JS struct
|
|
374
|
+
NSString *destinationMpidString = aliasRequest.destinationMpid();
|
|
375
|
+
NSString *sourceMpidString = aliasRequest.sourceMpid();
|
|
376
|
+
NSNumber *destinationMpid = [NSNumber numberWithLong:destinationMpidString.longLongValue];
|
|
377
|
+
NSNumber *sourceMpid = [NSNumber numberWithLong:sourceMpidString.longLongValue];
|
|
378
|
+
|
|
379
|
+
MPAliasRequest *request;
|
|
380
|
+
if (aliasRequest.startTime().has_value() && aliasRequest.endTime().has_value()) {
|
|
381
|
+
NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:aliasRequest.startTime().value() / 1000.0];
|
|
382
|
+
NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:aliasRequest.endTime().value() / 1000.0];
|
|
383
|
+
request = [MPAliasRequest requestWithSourceMPID:sourceMpid destinationMPID:destinationMpid startTime:startDate endTime:endDate];
|
|
384
|
+
} else {
|
|
385
|
+
MParticleUser *destinationUser = [[MParticleUser alloc] init];
|
|
386
|
+
MParticleUser *sourceUser = [[MParticleUser alloc] init];
|
|
387
|
+
destinationUser.userId = destinationMpid;
|
|
388
|
+
sourceUser.userId = sourceMpid;
|
|
389
|
+
request = [MPAliasRequest requestWithSourceUser:sourceUser destinationUser:destinationUser];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
BOOL success = [[[MParticle sharedInstance] identity] aliasUsers:request];
|
|
393
|
+
callback(@[[NSNull null], success ? @"true" : @"false"]);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
- (void)identify:(NSDictionary *)identityRequest callback:(RCTResponseSenderBlock)callback {
|
|
397
|
+
[self performIdentityRequest:identityRequest callback:callback requestType:@"identify"];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
- (void)login:(NSDictionary *)identityRequest callback:(RCTResponseSenderBlock)callback {
|
|
401
|
+
[self performIdentityRequest:identityRequest callback:callback requestType:@"login"];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
- (void)logout:(NSDictionary *)identityRequest callback:(RCTResponseSenderBlock)callback {
|
|
405
|
+
[self performIdentityRequest:identityRequest callback:callback requestType:@"logout"];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
- (void)modify:(NSDictionary *)identityRequest callback:(RCTResponseSenderBlock)callback {
|
|
409
|
+
[self performIdentityRequest:identityRequest callback:callback requestType:@"modify"];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
- (void)logMPEvent:(JS::NativeMParticle::Event &)event {
|
|
413
|
+
// Create MPEvent directly from JS struct
|
|
414
|
+
NSString *eventName = event.name() ?: @"";
|
|
415
|
+
MPEventType eventType = event.type().has_value() ? (MPEventType)event.type().value() : MPEventTypeOther;
|
|
416
|
+
|
|
417
|
+
MPEvent *mpEvent = [[MPEvent alloc] initWithName:eventName type:eventType];
|
|
418
|
+
|
|
419
|
+
if (event.info()) {
|
|
420
|
+
mpEvent.customAttributes = (NSDictionary *)event.info();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (event.duration().has_value()) {
|
|
424
|
+
mpEvent.duration = @(event.duration().value());
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (event.startTime().has_value()) {
|
|
428
|
+
mpEvent.startTime = [NSDate dateWithTimeIntervalSince1970:event.startTime().value() / 1000.0];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (event.endTime().has_value()) {
|
|
432
|
+
mpEvent.endTime = [NSDate dateWithTimeIntervalSince1970:event.endTime().value() / 1000.0];
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (event.category()) {
|
|
436
|
+
mpEvent.category = event.category();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (event.customFlags()) {
|
|
440
|
+
NSDictionary *dictFlags = (NSDictionary *)event.customFlags();
|
|
441
|
+
for (NSString *key in dictFlags) {
|
|
442
|
+
NSString *value = dictFlags[key];
|
|
443
|
+
[mpEvent addCustomFlag:value withKey:key];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
[[MParticle sharedInstance] logEvent:mpEvent];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
- (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
|
|
451
|
+
// Create MPCommerceEvent directly from JS struct
|
|
452
|
+
MPCommerceEvent *mpCommerceEvent = [[MPCommerceEvent alloc] init];
|
|
453
|
+
|
|
454
|
+
if (commerceEvent.productActionType().has_value()) {
|
|
455
|
+
mpCommerceEvent.action = (MPCommerceEventAction)commerceEvent.productActionType().value();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (commerceEvent.promotionActionType().has_value()) {
|
|
459
|
+
mpCommerceEvent.promotionContainer = [[MPPromotionContainer alloc] initWithAction:(MPPromotionAction)commerceEvent.promotionActionType().value() promotion:nil];
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (commerceEvent.products().has_value()) {
|
|
463
|
+
// Convert products array from LazyVector
|
|
464
|
+
auto productsVector = commerceEvent.products().value();
|
|
465
|
+
NSMutableArray *productsArray = [[NSMutableArray alloc] init];
|
|
466
|
+
for (size_t i = 0; i < productsVector.size(); i++) {
|
|
467
|
+
auto productStruct = productsVector[i];
|
|
468
|
+
// Convert JS Product struct to dictionary
|
|
469
|
+
NSMutableDictionary *productDict = [[NSMutableDictionary alloc] init];
|
|
470
|
+
if (productStruct.name()) productDict[@"name"] = productStruct.name();
|
|
471
|
+
if (productStruct.sku()) productDict[@"sku"] = productStruct.sku();
|
|
472
|
+
productDict[@"price"] = @(productStruct.price());
|
|
473
|
+
if (productStruct.quantity().has_value()) productDict[@"quantity"] = @(productStruct.quantity().value());
|
|
474
|
+
if (productStruct.brand()) productDict[@"brand"] = productStruct.brand();
|
|
475
|
+
if (productStruct.couponCode()) productDict[@"couponCode"] = productStruct.couponCode();
|
|
476
|
+
if (productStruct.position().has_value()) productDict[@"position"] = @(productStruct.position().value());
|
|
477
|
+
if (productStruct.category()) productDict[@"category"] = productStruct.category();
|
|
478
|
+
if (productStruct.variant()) productDict[@"variant"] = productStruct.variant();
|
|
479
|
+
if (productStruct.customAttributes()) productDict[@"customAttributes"] = productStruct.customAttributes();
|
|
480
|
+
|
|
481
|
+
MPProduct *product = [self createMPProductFromDict:productDict];
|
|
482
|
+
if (product) {
|
|
483
|
+
[productsArray addObject:product];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
[mpCommerceEvent addProducts:productsArray];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (commerceEvent.transactionAttributes().has_value()) {
|
|
490
|
+
// Create transaction attributes from the struct
|
|
491
|
+
auto transactionAttrs = commerceEvent.transactionAttributes().value();
|
|
492
|
+
MPTransactionAttributes *transaction = [[MPTransactionAttributes alloc] init];
|
|
493
|
+
|
|
494
|
+
if (transactionAttrs.transactionId()) {
|
|
495
|
+
transaction.transactionId = transactionAttrs.transactionId();
|
|
496
|
+
}
|
|
497
|
+
if (transactionAttrs.affiliation()) {
|
|
498
|
+
transaction.affiliation = transactionAttrs.affiliation();
|
|
499
|
+
}
|
|
500
|
+
if (transactionAttrs.revenue().has_value()) {
|
|
501
|
+
transaction.revenue = @(transactionAttrs.revenue().value());
|
|
502
|
+
}
|
|
503
|
+
if (transactionAttrs.shipping().has_value()) {
|
|
504
|
+
transaction.shipping = @(transactionAttrs.shipping().value());
|
|
505
|
+
}
|
|
506
|
+
if (transactionAttrs.tax().has_value()) {
|
|
507
|
+
transaction.tax = @(transactionAttrs.tax().value());
|
|
508
|
+
}
|
|
509
|
+
if (transactionAttrs.couponCode()) {
|
|
510
|
+
transaction.couponCode = transactionAttrs.couponCode();
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
mpCommerceEvent.transactionAttributes = transaction;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (commerceEvent.customAttributes()) {
|
|
517
|
+
mpCommerceEvent.customAttributes = (NSDictionary *)commerceEvent.customAttributes();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
[[MParticle sharedInstance] logEvent:mpCommerceEvent];
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
- (void)addGDPRConsentState:(JS::NativeMParticle::GDPRConsent &)consent purpose:(NSString *)purpose {
|
|
524
|
+
// Create MPGDPRConsent directly from JS struct
|
|
525
|
+
MPGDPRConsent *gdprConsent = [[MPGDPRConsent alloc] init];
|
|
526
|
+
|
|
527
|
+
if (consent.consented().has_value()) {
|
|
528
|
+
gdprConsent.consented = consent.consented().value();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (consent.document()) {
|
|
532
|
+
gdprConsent.document = consent.document();
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (consent.timestamp().has_value()) {
|
|
536
|
+
gdprConsent.timestamp = [NSDate dateWithTimeIntervalSince1970:consent.timestamp().value() / 1000.0];
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (consent.location()) {
|
|
540
|
+
gdprConsent.location = consent.location();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (consent.hardwareId()) {
|
|
544
|
+
gdprConsent.hardwareId = consent.hardwareId();
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
548
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
549
|
+
[consentState addGDPRConsentState:gdprConsent purpose:purpose];
|
|
550
|
+
user.consentState = consentState;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
- (void)setCCPAConsentState:(JS::NativeMParticle::CCPAConsent &)consent {
|
|
554
|
+
// Create MPCCPAConsent directly from JS struct
|
|
555
|
+
MPCCPAConsent *ccpaConsent = [[MPCCPAConsent alloc] init];
|
|
556
|
+
|
|
557
|
+
if (consent.consented().has_value()) {
|
|
558
|
+
ccpaConsent.consented = consent.consented().value();
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (consent.document()) {
|
|
562
|
+
ccpaConsent.document = consent.document();
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (consent.timestamp().has_value()) {
|
|
566
|
+
ccpaConsent.timestamp = [NSDate dateWithTimeIntervalSince1970:consent.timestamp().value() / 1000.0];
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (consent.location()) {
|
|
570
|
+
ccpaConsent.location = consent.location();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (consent.hardwareId()) {
|
|
574
|
+
ccpaConsent.hardwareId = consent.hardwareId();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
578
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
579
|
+
[consentState setCCPAConsentState:ccpaConsent];
|
|
580
|
+
user.consentState = consentState;
|
|
581
|
+
}
|
|
582
|
+
#else
|
|
583
|
+
|
|
584
|
+
RCT_EXPORT_METHOD(logMPEvent:(MPEvent *)event)
|
|
585
|
+
{
|
|
586
|
+
[[MParticle sharedInstance] logEvent:event];
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
RCT_EXPORT_METHOD(logCommerceEvent:(MPCommerceEvent *)commerceEvent)
|
|
590
|
+
{
|
|
591
|
+
[[MParticle sharedInstance] logCommerceEvent:commerceEvent];
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
RCT_EXPORT_METHOD(addGDPRConsentState:(MPGDPRConsent *)gdprConsentState purpose:(NSString *)purpose)
|
|
595
|
+
{
|
|
596
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
597
|
+
|
|
598
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
599
|
+
[consentState addGDPRConsentState:gdprConsentState purpose:purpose];
|
|
600
|
+
user.consentState = consentState;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
RCT_EXPORT_METHOD(setCCPAConsentState:(MPCCPAConsent *)consent)
|
|
604
|
+
{
|
|
605
|
+
MParticleUser *user = [MParticle sharedInstance].identity.currentUser;
|
|
606
|
+
|
|
607
|
+
MPConsentState *consentState = user.consentState ? user.consentState : [[MPConsentState alloc] init];
|
|
608
|
+
[consentState setCCPAConsentState:consent];
|
|
609
|
+
user.consentState = consentState;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
#endif
|
|
613
|
+
|
|
614
|
+
// Helper method to create MPProduct from dictionary
|
|
615
|
+
- (MPProduct *)createMPProductFromDict:(NSDictionary *)productDict {
|
|
616
|
+
NSString *name = productDict[@"name"];
|
|
617
|
+
NSString *sku = productDict[@"sku"];
|
|
618
|
+
NSNumber *price = productDict[@"price"];
|
|
619
|
+
|
|
620
|
+
if (!name || !sku || !price) {
|
|
621
|
+
return nil;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
MPProduct *product = [[MPProduct alloc] initWithName:name sku:sku quantity:@1 price:price];
|
|
625
|
+
|
|
626
|
+
if (productDict[@"quantity"]) {
|
|
627
|
+
product.quantity = productDict[@"quantity"];
|
|
628
|
+
}
|
|
629
|
+
if (productDict[@"brand"]) {
|
|
630
|
+
product.brand = productDict[@"brand"];
|
|
631
|
+
}
|
|
632
|
+
if (productDict[@"couponCode"]) {
|
|
633
|
+
product.couponCode = productDict[@"couponCode"];
|
|
634
|
+
}
|
|
635
|
+
if (productDict[@"position"]) {
|
|
636
|
+
product.position = [productDict[@"position"] integerValue];
|
|
637
|
+
}
|
|
638
|
+
if (productDict[@"category"]) {
|
|
639
|
+
product.category = productDict[@"category"];
|
|
640
|
+
}
|
|
641
|
+
if (productDict[@"variant"]) {
|
|
642
|
+
product.variant = productDict[@"variant"];
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return product;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
- (MPIdentityApiRequest *)MPIdentityApiRequestFromDict:(NSDictionary *)dict {
|
|
649
|
+
if ([dict isKindOfClass:MPIdentityApiRequest.class]) {
|
|
650
|
+
return (MPIdentityApiRequest*)dict;
|
|
651
|
+
}
|
|
652
|
+
MPIdentityApiRequest *request = [MPIdentityApiRequest requestWithEmptyUser];
|
|
653
|
+
|
|
654
|
+
if (dict[@"userIdentities"] && dict[@"userIdentities"] != [NSNull null]) {
|
|
655
|
+
NSDictionary *identities = dict[@"userIdentities"];
|
|
656
|
+
for (NSString *key in identities) {
|
|
657
|
+
MPIdentity identityType = (MPIdentity)[key integerValue];
|
|
658
|
+
NSString *value = identities[key];
|
|
659
|
+
[request setIdentity:value identityType:identityType];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (dict[@"customerId"] && dict[@"customerId"] != [NSNull null]) {
|
|
664
|
+
request.customerId = dict[@"customerId"];
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (dict[@"email"] && dict[@"email"] != [NSNull null]) {
|
|
668
|
+
request.email = dict[@"email"];
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return request;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// Private helper method for identity requests
|
|
675
|
+
- (void)performIdentityRequest:(NSDictionary *)identityRequest callback:(RCTResponseSenderBlock)callback requestType:(NSString *)requestType {
|
|
676
|
+
MPIdentityApiRequest *request = [self MPIdentityApiRequestFromDict:identityRequest];
|
|
677
|
+
|
|
678
|
+
void (^completion)(MPIdentityApiResult * _Nullable, NSError * _Nullable) = ^(MPIdentityApiResult * _Nullable apiResult, NSError * _Nullable error) {
|
|
679
|
+
if (error) {
|
|
680
|
+
NSMutableDictionary *reactError = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
681
|
+
MPIdentityHTTPErrorResponse *response = error.userInfo[mParticleIdentityErrorKey];
|
|
682
|
+
if ([response isKindOfClass:[NSString class]]) {
|
|
683
|
+
[reactError setObject:response forKey:@"message"];
|
|
684
|
+
} else {
|
|
685
|
+
if ([NSNumber numberWithLong:response.httpCode] != nil) {
|
|
686
|
+
[reactError setObject:[NSNumber numberWithLong:response.httpCode] forKey:@"httpCode"];
|
|
687
|
+
}
|
|
688
|
+
if ([NSNumber numberWithInt:response.code] != nil) {
|
|
689
|
+
[reactError setObject:[NSNumber numberWithInt:response.code] forKey:@"responseCode"];
|
|
690
|
+
}
|
|
691
|
+
if (response.message != nil) {
|
|
692
|
+
[reactError setObject:response.message forKey:@"message"];
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (apiResult != nil) {
|
|
696
|
+
if ([requestType isEqualToString:@"modify"]) {
|
|
697
|
+
callback(@[reactError, apiResult.user.userId.stringValue, [NSNull null]]);
|
|
698
|
+
} else {
|
|
699
|
+
callback(@[reactError, apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
700
|
+
}
|
|
701
|
+
} else {
|
|
702
|
+
callback(@[reactError, @0]);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
if ([requestType isEqualToString:@"modify"]) {
|
|
706
|
+
callback(@[[NSNull null], apiResult.user.userId.stringValue, [NSNull null]]);
|
|
707
|
+
} else {
|
|
708
|
+
callback(@[[NSNull null], apiResult.user.userId.stringValue, apiResult.previousUser.userId.stringValue]);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
if ([requestType isEqualToString:@"identify"]) {
|
|
714
|
+
[[[MParticle sharedInstance] identity] identify:request completion:completion];
|
|
715
|
+
} else if ([requestType isEqualToString:@"login"]) {
|
|
716
|
+
[[[MParticle sharedInstance] identity] login:request completion:completion];
|
|
717
|
+
} else if ([requestType isEqualToString:@"logout"]) {
|
|
718
|
+
[[[MParticle sharedInstance] identity] logout:request completion:completion];
|
|
719
|
+
} else if ([requestType isEqualToString:@"modify"]) {
|
|
720
|
+
[[[MParticle sharedInstance] identity] modify:request completion:completion];
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
725
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
726
|
+
return std::make_shared<facebook::react::NativeMParticleSpecJSI>(params);
|
|
727
|
+
}
|
|
728
|
+
#endif
|
|
729
|
+
|
|
730
|
+
@end
|
|
731
|
+
|
|
732
|
+
// RCTConvert category methods for mParticle types
|
|
733
|
+
@implementation RCTConvert (MParticle)
|
|
734
|
+
|
|
735
|
+
+ (MPEvent *)MPEvent:(NSDictionary *)dict {
|
|
736
|
+
MPEvent *event = [[MPEvent alloc] initWithName:dict[@"name"] type:(MPEventType)[dict[@"type"] integerValue]];
|
|
737
|
+
|
|
738
|
+
if (dict[@"info"] && dict[@"info"] != [NSNull null]) {
|
|
739
|
+
event.customAttributes = dict[@"info"];
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (dict[@"duration"] && dict[@"duration"] != [NSNull null]) {
|
|
743
|
+
event.duration = @([dict[@"duration"] doubleValue]);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if (dict[@"startTime"] && dict[@"startTime"] != [NSNull null]) {
|
|
747
|
+
event.startTime = [NSDate dateWithTimeIntervalSince1970:[dict[@"startTime"] doubleValue] / 1000.0];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (dict[@"endTime"] && dict[@"endTime"] != [NSNull null]) {
|
|
751
|
+
event.endTime = [NSDate dateWithTimeIntervalSince1970:[dict[@"endTime"] doubleValue] / 1000.0];
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (dict[@"category"] && dict[@"category"] != [NSNull null]) {
|
|
755
|
+
event.category = dict[@"category"];
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (dict[@"shouldUploadEvent"] && dict[@"shouldUploadEvent"] != [NSNull null]) {
|
|
759
|
+
event.shouldUploadEvent = [dict[@"shouldUploadEvent"] boolValue];
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (dict[@"customFlags"] && dict[@"customFlags"] != [NSNull null]) {
|
|
763
|
+
NSDictionary *dictFlags = (NSDictionary *)dict[@"customFlags"];
|
|
764
|
+
for (NSString *key in dictFlags) {
|
|
765
|
+
NSString *value = dictFlags[key];
|
|
766
|
+
[event addCustomFlag:value withKey:key];
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return event;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
+ (MPCommerceEvent *)MPCommerceEvent:(NSDictionary *)dict {
|
|
774
|
+
MPCommerceEvent *commerceEvent = [[MPCommerceEvent alloc] init];
|
|
775
|
+
|
|
776
|
+
if (dict[@"productActionType"] && dict[@"productActionType"] != [NSNull null]) {
|
|
777
|
+
commerceEvent.action = (MPCommerceEventAction)[dict[@"productActionType"] integerValue];
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
if (dict[@"products"] && dict[@"products"] != [NSNull null]) {
|
|
781
|
+
NSArray *productDicts = dict[@"products"];
|
|
782
|
+
NSMutableArray *products = [[NSMutableArray alloc] init];
|
|
783
|
+
for (NSDictionary *productDict in productDicts) {
|
|
784
|
+
MPProduct *product = [[MPProduct alloc] initWithName:productDict[@"name"]
|
|
785
|
+
sku:productDict[@"sku"]
|
|
786
|
+
quantity:productDict[@"quantity"]
|
|
787
|
+
price:productDict[@"price"]];
|
|
788
|
+
[products addObject:product];
|
|
789
|
+
}
|
|
790
|
+
[commerceEvent addProducts:products];
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
if (dict[@"transactionAttributes"] && dict[@"transactionAttributes"] != [NSNull null]) {
|
|
794
|
+
NSDictionary *transactionDict = dict[@"transactionAttributes"];
|
|
795
|
+
MPTransactionAttributes *transactionAttributes = [[MPTransactionAttributes alloc] init];
|
|
796
|
+
if (transactionDict[@"transactionId"]) {
|
|
797
|
+
transactionAttributes.transactionId = transactionDict[@"transactionId"];
|
|
798
|
+
}
|
|
799
|
+
if (transactionDict[@"revenue"]) {
|
|
800
|
+
transactionAttributes.revenue = transactionDict[@"revenue"];
|
|
801
|
+
}
|
|
802
|
+
if (transactionDict[@"tax"]) {
|
|
803
|
+
transactionAttributes.tax = transactionDict[@"tax"];
|
|
804
|
+
}
|
|
805
|
+
if (transactionDict[@"shipping"]) {
|
|
806
|
+
transactionAttributes.shipping = transactionDict[@"shipping"];
|
|
807
|
+
}
|
|
808
|
+
if (transactionDict[@"couponCode"]) {
|
|
809
|
+
transactionAttributes.couponCode = transactionDict[@"couponCode"];
|
|
810
|
+
}
|
|
811
|
+
if (transactionDict[@"affiliation"]) {
|
|
812
|
+
transactionAttributes.affiliation = transactionDict[@"affiliation"];
|
|
813
|
+
}
|
|
814
|
+
commerceEvent.transactionAttributes = transactionAttributes;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (dict[@"customAttributes"] && dict[@"customAttributes"] != [NSNull null]) {
|
|
818
|
+
commerceEvent.customAttributes = dict[@"customAttributes"];
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (dict[@"shouldUploadEvent"] && dict[@"shouldUploadEvent"] != [NSNull null]) {
|
|
822
|
+
commerceEvent.shouldUploadEvent = [dict[@"shouldUploadEvent"] boolValue];
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return commerceEvent;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
+ (MPGDPRConsent *)MPGDPRConsent:(NSDictionary *)dict {
|
|
829
|
+
BOOL consented = [dict[@"consented"] boolValue];
|
|
830
|
+
MPGDPRConsent *consent = [[MPGDPRConsent alloc] init];
|
|
831
|
+
consent.consented = consented;
|
|
832
|
+
|
|
833
|
+
if (dict[@"document"] && dict[@"document"] != [NSNull null]) {
|
|
834
|
+
consent.document = dict[@"document"];
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
if (dict[@"timestamp"] && dict[@"timestamp"] != [NSNull null]) {
|
|
838
|
+
consent.timestamp = [NSDate dateWithTimeIntervalSince1970:[dict[@"timestamp"] doubleValue] / 1000.0];
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (dict[@"location"] && dict[@"location"] != [NSNull null]) {
|
|
842
|
+
consent.location = dict[@"location"];
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (dict[@"hardwareId"] && dict[@"hardwareId"] != [NSNull null]) {
|
|
846
|
+
consent.hardwareId = dict[@"hardwareId"];
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
return consent;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
+ (MPCCPAConsent *)MPCCPAConsent:(NSDictionary *)dict {
|
|
853
|
+
BOOL consented = [dict[@"consented"] boolValue];
|
|
854
|
+
MPCCPAConsent *consent = [[MPCCPAConsent alloc] init];
|
|
855
|
+
consent.consented = consented;
|
|
856
|
+
|
|
857
|
+
if (dict[@"document"] && dict[@"document"] != [NSNull null]) {
|
|
858
|
+
consent.document = dict[@"document"];
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (dict[@"timestamp"] && dict[@"timestamp"] != [NSNull null]) {
|
|
862
|
+
consent.timestamp = [NSDate dateWithTimeIntervalSince1970:[dict[@"timestamp"] doubleValue] / 1000.0];
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if (dict[@"location"] && dict[@"location"] != [NSNull null]) {
|
|
866
|
+
consent.location = dict[@"location"];
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (dict[@"hardwareId"] && dict[@"hardwareId"] != [NSNull null]) {
|
|
870
|
+
consent.hardwareId = dict[@"hardwareId"];
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return consent;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
+ (MPAliasRequest *)MPAliasRequest:(NSDictionary *)dict {
|
|
877
|
+
NSString *sourceMpidString = dict[@"sourceMpid"];
|
|
878
|
+
NSString *destinationMpidString = dict[@"destinationMpid"];
|
|
879
|
+
NSNumber *sourceMpid = [NSNumber numberWithLong:sourceMpidString.longLongValue];
|
|
880
|
+
NSNumber *destinationMpid = [NSNumber numberWithLong:destinationMpidString.longLongValue];
|
|
881
|
+
|
|
882
|
+
NSDate *startTime = nil;
|
|
883
|
+
NSDate *endTime = nil;
|
|
884
|
+
|
|
885
|
+
if (dict[@"startTime"] && dict[@"startTime"] != [NSNull null]) {
|
|
886
|
+
startTime = [NSDate dateWithTimeIntervalSince1970:[dict[@"startTime"] doubleValue] / 1000.0];
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
if (dict[@"endTime"] && dict[@"endTime"] != [NSNull null]) {
|
|
890
|
+
endTime = [NSDate dateWithTimeIntervalSince1970:[dict[@"endTime"] doubleValue] / 1000.0];
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
return [MPAliasRequest requestWithSourceMPID:sourceMpid destinationMPID:destinationMpid startTime:startTime endTime:endTime];
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
@end
|
|
897
|
+
|
|
898
|
+
typedef NS_ENUM(NSUInteger, MPReactCommerceEventAction) {
|
|
899
|
+
MPReactCommerceEventActionAddToCart = 1,
|
|
900
|
+
MPReactCommerceEventActionRemoveFromCart,
|
|
901
|
+
MPReactCommerceEventActionCheckout,
|
|
902
|
+
MPReactCommerceEventActionCheckoutOptions,
|
|
903
|
+
MPReactCommerceEventActionClick,
|
|
904
|
+
MPReactCommerceEventActionViewDetail,
|
|
905
|
+
MPReactCommerceEventActionPurchase,
|
|
906
|
+
MPReactCommerceEventActionRefund,
|
|
907
|
+
MPReactCommerceEventActionAddToWishList,
|
|
908
|
+
MPReactCommerceEventActionRemoveFromWishlist
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
@interface RCTConvert (MPCommerceEvent)
|
|
912
|
+
|
|
913
|
+
+ (MPCommerceEvent *)MPCommerceEvent:(id)json;
|
|
914
|
+
+ (MPPromotionContainer *)MPPromotionContainer:(id)json;
|
|
915
|
+
+ (MPPromotion *)MPPromotion:(id)json;
|
|
916
|
+
+ (MPTransactionAttributes *)MPTransactionAttributes:(id)json;
|
|
917
|
+
+ (MPProduct *)MPProduct:(id)json;
|
|
918
|
+
+ (MPCommerceEventAction)MPCommerceEventAction:(id)json;
|
|
919
|
+
+ (MPIdentityApiRequest *)MPIdentityApiRequest:(id)json;
|
|
920
|
+
+ (MPIdentityApiResult *)MPIdentityApiResult:(id)json;
|
|
921
|
+
+ (MPAliasRequest *)MPAliasRequest:(id)json;
|
|
922
|
+
+ (MParticleUser *)MParticleUser:(id)json;
|
|
923
|
+
+ (MPEvent *)MPEvent:(id)json;
|
|
924
|
+
+ (MPGDPRConsent *)MPGDPRConsent:(id)json;
|
|
925
|
+
+ (MPCCPAConsent *)MPCCPAConsent:(id)json;
|
|
926
|
+
|
|
927
|
+
@end
|
|
928
|
+
|
|
929
|
+
@implementation RCTConvert (MPCommerceEvent)
|
|
930
|
+
|
|
931
|
+
+ (MPCommerceEvent *)MPCommerceEvent:(id)json {
|
|
932
|
+
BOOL isProductAction = json[@"productActionType"] != nil;
|
|
933
|
+
BOOL isPromotion = json[@"promotionActionType"] != nil;
|
|
934
|
+
BOOL isImpression = json[@"impressions"] != nil;
|
|
935
|
+
|
|
936
|
+
NSAssert(isProductAction || isPromotion || isImpression, @"Invalid commerce event");
|
|
937
|
+
|
|
938
|
+
MPCommerceEvent *commerceEvent = nil;
|
|
939
|
+
if (isProductAction) {
|
|
940
|
+
MPCommerceEventAction action = [RCTConvert MPCommerceEventAction:json[@"productActionType"]];
|
|
941
|
+
commerceEvent = [[MPCommerceEvent alloc] initWithAction:action];
|
|
942
|
+
}
|
|
943
|
+
else if (isPromotion) {
|
|
944
|
+
MPPromotionContainer *promotionContainer = [RCTConvert MPPromotionContainer:json];
|
|
945
|
+
commerceEvent = [[MPCommerceEvent alloc] initWithPromotionContainer:promotionContainer];
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
commerceEvent = [[MPCommerceEvent alloc] initWithImpressionName:nil product:nil];
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
commerceEvent.checkoutOptions = json[@"checkoutOptions"];
|
|
952
|
+
commerceEvent.currency = json[@"currency"];
|
|
953
|
+
commerceEvent.productListName = json[@"productActionListName"];
|
|
954
|
+
commerceEvent.productListSource = json[@"productActionListSource"];
|
|
955
|
+
commerceEvent.screenName = json[@"screenName"];
|
|
956
|
+
commerceEvent.transactionAttributes = [RCTConvert MPTransactionAttributes:json[@"transactionAttributes"]];
|
|
957
|
+
commerceEvent.checkoutStep = [json[@"checkoutStep"] intValue];
|
|
958
|
+
commerceEvent.nonInteractive = [json[@"nonInteractive"] boolValue];
|
|
959
|
+
if (json[@"shouldUploadEvent"] != nil) {
|
|
960
|
+
commerceEvent.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue];
|
|
961
|
+
}
|
|
962
|
+
if (json[@"customAttributes"] != nil) {
|
|
963
|
+
commerceEvent.customAttributes = json[@"customAttributes"];
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
NSMutableArray *products = [NSMutableArray array];
|
|
967
|
+
NSArray *jsonProducts = json[@"products"];
|
|
968
|
+
[jsonProducts enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
969
|
+
MPProduct *product = [RCTConvert MPProduct:obj];
|
|
970
|
+
[products addObject:product];
|
|
971
|
+
}];
|
|
972
|
+
[commerceEvent addProducts:products];
|
|
973
|
+
|
|
974
|
+
NSArray *jsonImpressions = json[@"impressions"];
|
|
975
|
+
[jsonImpressions enumerateObjectsUsingBlock:^(NSDictionary *jsonImpression, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
976
|
+
NSString *listName = jsonImpression[@"impressionListName"];
|
|
977
|
+
NSArray *jsonProducts = jsonImpression[@"products"];
|
|
978
|
+
[jsonProducts enumerateObjectsUsingBlock:^(id _Nonnull jsonProduct, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
979
|
+
MPProduct *product = [RCTConvert MPProduct:jsonProduct];
|
|
980
|
+
[commerceEvent addImpression:product listName:listName];
|
|
981
|
+
}];
|
|
982
|
+
}];
|
|
983
|
+
|
|
984
|
+
return commerceEvent;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
+ (MPPromotionContainer *)MPPromotionContainer:(id)json {
|
|
988
|
+
MPPromotionAction promotionAction = (MPPromotionAction)[json[@"promotionActionType"] intValue];
|
|
989
|
+
MPPromotionContainer *promotionContainer = [[MPPromotionContainer alloc] initWithAction:promotionAction promotion:nil];
|
|
990
|
+
NSArray *jsonPromotions = json[@"promotions"];
|
|
991
|
+
[jsonPromotions enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
992
|
+
MPPromotion *promotion = [RCTConvert MPPromotion:obj];
|
|
993
|
+
[promotionContainer addPromotion:promotion];
|
|
994
|
+
}];
|
|
995
|
+
|
|
996
|
+
return promotionContainer;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
+ (MPPromotion *)MPPromotion:(id)json {
|
|
1000
|
+
MPPromotion *promotion = [[MPPromotion alloc] init];
|
|
1001
|
+
promotion.creative = json[@"creative"];
|
|
1002
|
+
promotion.name = json[@"name"];
|
|
1003
|
+
promotion.position = json[@"position"];
|
|
1004
|
+
promotion.promotionId = json[@"id"];
|
|
1005
|
+
return promotion;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
+ (MPTransactionAttributes *)MPTransactionAttributes:(id)json {
|
|
1009
|
+
MPTransactionAttributes *transactionAttributes = [[MPTransactionAttributes alloc] init];
|
|
1010
|
+
transactionAttributes.affiliation = json[@"affiliation"];
|
|
1011
|
+
transactionAttributes.couponCode = json[@"couponCode"];
|
|
1012
|
+
transactionAttributes.shipping = json[@"shipping"];
|
|
1013
|
+
transactionAttributes.tax = json[@"tax"];
|
|
1014
|
+
transactionAttributes.revenue = json[@"revenue"];
|
|
1015
|
+
transactionAttributes.transactionId = json[@"transactionId"];
|
|
1016
|
+
return transactionAttributes;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
+ (MPProduct *)MPProduct:(id)json {
|
|
1020
|
+
MPProduct *product = [[MPProduct alloc] init];
|
|
1021
|
+
product.brand = json[@"brand"];
|
|
1022
|
+
product.category = json[@"category"];
|
|
1023
|
+
product.couponCode = json[@"couponCode"];
|
|
1024
|
+
product.name = json[@"name"];
|
|
1025
|
+
product.price = json[@"price"];
|
|
1026
|
+
product.sku = json[@"sku"];
|
|
1027
|
+
product.variant = json[@"variant"];
|
|
1028
|
+
product.position = [json[@"position"] intValue];
|
|
1029
|
+
product.quantity = @([json[@"quantity"] intValue]);
|
|
1030
|
+
NSDictionary *jsonAttributes = json[@"customAttributes"];
|
|
1031
|
+
for (NSString *key in jsonAttributes) {
|
|
1032
|
+
NSString *value = jsonAttributes[key];
|
|
1033
|
+
[product setObject:value forKeyedSubscript:key];
|
|
1034
|
+
}
|
|
1035
|
+
return product;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
+ (MPCommerceEventAction)MPCommerceEventAction:(NSNumber *)json {
|
|
1039
|
+
int actionInt = [json intValue];
|
|
1040
|
+
MPCommerceEventAction action;
|
|
1041
|
+
switch (actionInt) {
|
|
1042
|
+
case MPReactCommerceEventActionAddToCart:
|
|
1043
|
+
action = MPCommerceEventActionAddToCart;
|
|
1044
|
+
break;
|
|
1045
|
+
|
|
1046
|
+
case MPReactCommerceEventActionRemoveFromCart:
|
|
1047
|
+
action = MPCommerceEventActionRemoveFromCart;
|
|
1048
|
+
break;
|
|
1049
|
+
|
|
1050
|
+
case MPReactCommerceEventActionCheckout:
|
|
1051
|
+
action = MPCommerceEventActionCheckout;
|
|
1052
|
+
break;
|
|
1053
|
+
|
|
1054
|
+
case MPReactCommerceEventActionCheckoutOptions:
|
|
1055
|
+
action = MPCommerceEventActionCheckoutOptions;
|
|
1056
|
+
break;
|
|
1057
|
+
|
|
1058
|
+
case MPReactCommerceEventActionClick:
|
|
1059
|
+
action = MPCommerceEventActionClick;
|
|
1060
|
+
break;
|
|
1061
|
+
|
|
1062
|
+
case MPReactCommerceEventActionViewDetail:
|
|
1063
|
+
action = MPCommerceEventActionViewDetail;
|
|
1064
|
+
break;
|
|
1065
|
+
|
|
1066
|
+
case MPReactCommerceEventActionPurchase:
|
|
1067
|
+
action = MPCommerceEventActionPurchase;
|
|
1068
|
+
break;
|
|
1069
|
+
|
|
1070
|
+
case MPReactCommerceEventActionRefund:
|
|
1071
|
+
action = MPCommerceEventActionRefund;
|
|
1072
|
+
break;
|
|
1073
|
+
|
|
1074
|
+
case MPReactCommerceEventActionAddToWishList:
|
|
1075
|
+
action = MPCommerceEventActionAddToWishList;
|
|
1076
|
+
break;
|
|
1077
|
+
|
|
1078
|
+
case MPReactCommerceEventActionRemoveFromWishlist:
|
|
1079
|
+
action = MPCommerceEventActionRemoveFromWishlist;
|
|
1080
|
+
break;
|
|
1081
|
+
|
|
1082
|
+
default:
|
|
1083
|
+
action = MPCommerceEventActionAddToCart;
|
|
1084
|
+
NSAssert(NO, @"Invalid commerce event action");
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
return action;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
+ (MPIdentityApiRequest *)MPIdentityApiRequest:(id)json {
|
|
1091
|
+
NSDictionary *dict = json;
|
|
1092
|
+
MPIdentityApiRequest *request = [MPIdentityApiRequest requestWithEmptyUser];
|
|
1093
|
+
|
|
1094
|
+
if (dict[@"userIdentities"] && dict[@"userIdentities"] != [NSNull null]) {
|
|
1095
|
+
NSDictionary *identities = dict[@"userIdentities"];
|
|
1096
|
+
for (NSString *key in identities) {
|
|
1097
|
+
MPIdentity identityType = (MPIdentity)[key integerValue];
|
|
1098
|
+
NSString *value = identities[key];
|
|
1099
|
+
[request setIdentity:value identityType:identityType];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
if (dict[@"customerId"] && dict[@"customerId"] != [NSNull null]) {
|
|
1104
|
+
request.customerId = dict[@"customerId"];
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
if (dict[@"email"] && dict[@"email"] != [NSNull null]) {
|
|
1108
|
+
request.email = dict[@"email"];
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
return request;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
+ (MPIdentityApiResult *)MPIdentityApiResult:(id)json {
|
|
1117
|
+
MPIdentityApiResult *result = [[MPIdentityApiResult alloc] init];
|
|
1118
|
+
id obj = json[@"user"];
|
|
1119
|
+
result.user = [RCTConvert MParticleUser:obj];
|
|
1120
|
+
|
|
1121
|
+
return result;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
+ (MPAliasRequest *)MPAliasRequest:(id)json {
|
|
1125
|
+
NSString *destinationMpidString = json[@"destinationMpid"];
|
|
1126
|
+
NSString *sourceMpidString = json[@"sourceMpid"];
|
|
1127
|
+
NSString *startTime = json[@"startTime"];
|
|
1128
|
+
NSString *endTime = json[@"endTime"];
|
|
1129
|
+
NSNumber *destinationMpid = [NSNumber numberWithLong:destinationMpidString.longLongValue];
|
|
1130
|
+
NSNumber *sourceMpid = [NSNumber numberWithLong:sourceMpidString.longLongValue];
|
|
1131
|
+
NSDate *startDate = nil;
|
|
1132
|
+
NSDate *endDate = nil;
|
|
1133
|
+
|
|
1134
|
+
if (startTime != nil && startTime != [NSNull null]) {
|
|
1135
|
+
startDate = [NSDate dateWithTimeIntervalSince1970:startTime.longLongValue];
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (endTime != nil && endTime != [NSNull null]) {
|
|
1139
|
+
endDate = [NSDate dateWithTimeIntervalSince1970:endTime.longLongValue];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
return [MPAliasRequest requestWithSourceMPID:sourceMpid destinationMPID:destinationMpid startTime:startDate endTime:endDate];
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
+ (MParticleUser *)MParticleUser:(id)json {
|
|
1146
|
+
MParticleUser *user = [[MParticleUser alloc] init];
|
|
1147
|
+
user.userId = json[@"userId"];
|
|
1148
|
+
|
|
1149
|
+
return user;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
+ (MPEvent *)MPEvent:(id)json {
|
|
1153
|
+
MPEvent *event = [[MPEvent alloc] init];
|
|
1154
|
+
|
|
1155
|
+
event.category = json[@"category"];
|
|
1156
|
+
event.duration = json[@"duration"];
|
|
1157
|
+
event.endTime = json[@"endTime"];
|
|
1158
|
+
event.info = json[@"info"];
|
|
1159
|
+
event.name = json[@"name"];
|
|
1160
|
+
event.startTime = json[@"startTime"];
|
|
1161
|
+
[event setType:(MPEventType)[json[@"type"] intValue]];
|
|
1162
|
+
if (json[@"shouldUploadEvent"] != nil) {
|
|
1163
|
+
event.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue];
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
NSDictionary *jsonFlags = json[@"customFlags"];
|
|
1167
|
+
for (NSString *key in jsonFlags) {
|
|
1168
|
+
NSString *value = jsonFlags[key];
|
|
1169
|
+
[event addCustomFlag:value withKey:key];
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
return event;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
+ (MPGDPRConsent *)MPGDPRConsent:(id)json {
|
|
1176
|
+
MPGDPRConsent *mpConsent = [[MPGDPRConsent alloc] init];
|
|
1177
|
+
|
|
1178
|
+
mpConsent.consented = [RCTConvert BOOL:json[@"consented"]];
|
|
1179
|
+
mpConsent.document = json[@"document"];
|
|
1180
|
+
mpConsent.timestamp = [RCTConvert NSDate:json[@"timestamp"]];
|
|
1181
|
+
mpConsent.location = json[@"location"];
|
|
1182
|
+
mpConsent.hardwareId = json[@"hardwareId"];
|
|
1183
|
+
|
|
1184
|
+
return mpConsent;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
+ (MPCCPAConsent *)MPCCPAConsent:(id)json {
|
|
1188
|
+
MPCCPAConsent *mpConsent = [[MPCCPAConsent alloc] init];
|
|
1189
|
+
|
|
1190
|
+
mpConsent.consented = [RCTConvert BOOL:json[@"consented"]];
|
|
1191
|
+
mpConsent.document = json[@"document"];
|
|
1192
|
+
mpConsent.timestamp = [RCTConvert NSDate:json[@"timestamp"]];
|
|
1193
|
+
mpConsent.location = json[@"location"];
|
|
1194
|
+
mpConsent.hardwareId = json[@"hardwareId"];
|
|
1195
|
+
|
|
1196
|
+
return mpConsent;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
@end
|