plotline-engage 3.2.3 → 4.0.1
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/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativeplotline/RNPlotline.java +59 -0
- package/index.d.ts +2 -0
- package/index.js +48 -1
- package/ios/RNPlotline.h +4 -4
- package/ios/RNPlotline.m +15 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -9,16 +9,25 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
9
9
|
|
|
10
10
|
import androidx.annotation.NonNull;
|
|
11
11
|
|
|
12
|
+
import com.facebook.react.bridge.Arguments;
|
|
12
13
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
13
14
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
14
15
|
import com.facebook.react.bridge.ReactMethod;
|
|
15
16
|
import com.facebook.react.bridge.ReadableMap;
|
|
16
17
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
17
18
|
import com.facebook.react.bridge.ReadableType;
|
|
19
|
+
import com.facebook.react.bridge.WritableMap;
|
|
20
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
18
21
|
|
|
19
22
|
import org.json.JSONObject;
|
|
20
23
|
import org.json.JSONException;
|
|
21
24
|
|
|
25
|
+
import java.util.HashMap;
|
|
26
|
+
import java.util.Iterator;
|
|
27
|
+
import java.util.Map;
|
|
28
|
+
|
|
29
|
+
import so.plotline.insights.Listeners.PlotlineEventsListener;
|
|
30
|
+
import so.plotline.insights.Listeners.PlotlineRedirectListener;
|
|
22
31
|
import so.plotline.insights.Plotline;
|
|
23
32
|
|
|
24
33
|
public class RNPlotline extends ReactContextBaseJavaModule {
|
|
@@ -40,6 +49,56 @@ public class RNPlotline extends ReactContextBaseJavaModule {
|
|
|
40
49
|
final Activity activity = getCurrentActivity();
|
|
41
50
|
Plotline.init(activity, apiKey, userId, endpoint);
|
|
42
51
|
Plotline.setFramework("REACT_NATIVE");
|
|
52
|
+
Plotline.setPlotlineEventsListener((eventName, eventProperties) -> {
|
|
53
|
+
try {
|
|
54
|
+
WritableMap writableMap = Arguments.createMap();
|
|
55
|
+
Iterator<String> iterator = eventProperties.keys();
|
|
56
|
+
|
|
57
|
+
while (iterator.hasNext()) {
|
|
58
|
+
String key = iterator.next();
|
|
59
|
+
Object value = eventProperties.get(key);
|
|
60
|
+
|
|
61
|
+
if (value instanceof String) {
|
|
62
|
+
writableMap.putString(key, (String) value);
|
|
63
|
+
} else if (value instanceof Integer) {
|
|
64
|
+
writableMap.putInt(key, (Integer) value);
|
|
65
|
+
} else if (value instanceof Double) {
|
|
66
|
+
writableMap.putDouble(key, (Double) value);
|
|
67
|
+
} else if (value instanceof Boolean) {
|
|
68
|
+
writableMap.putBoolean(key, (Boolean) value);
|
|
69
|
+
} else {
|
|
70
|
+
writableMap.putString(key, value.toString());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
WritableMap event = Arguments.createMap();
|
|
75
|
+
event.putString("eventName", eventName);
|
|
76
|
+
event.putMap("properties", writableMap);
|
|
77
|
+
|
|
78
|
+
getReactApplicationContext()
|
|
79
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
80
|
+
.emit("PlotlineEvents", event);
|
|
81
|
+
|
|
82
|
+
} catch (Exception e) {
|
|
83
|
+
e.printStackTrace();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
Plotline.setPlotlineRedirectListener(redirectKeyValues -> {
|
|
88
|
+
try {
|
|
89
|
+
WritableMap writableMap = Arguments.createMap();
|
|
90
|
+
|
|
91
|
+
for (Map.Entry<String, String> entry : redirectKeyValues.entrySet()) {
|
|
92
|
+
writableMap.putString(entry.getKey(), entry.getValue());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getReactApplicationContext()
|
|
96
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
97
|
+
.emit("PlotlineRedirect", writableMap);
|
|
98
|
+
} catch (Exception e) {
|
|
99
|
+
e.printStackTrace();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
43
102
|
}
|
|
44
103
|
|
|
45
104
|
@ReactMethod
|
package/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ declare class plotline {
|
|
|
12
12
|
trackPage(pageId: string): void;
|
|
13
13
|
debug(): void;
|
|
14
14
|
notifyScroll(): void;
|
|
15
|
+
setPlotlineEventsListener(listener: (eventName: string, properties: {[key: string]: any}) => void): void;
|
|
16
|
+
setPlotlineRedirectListener(listener: (keyValuePairs: {[key: string]: any}) => void): void;
|
|
15
17
|
logout(): void;
|
|
16
18
|
}
|
|
17
19
|
declare class ScrollView extends React.Component<ScrollViewProps> {
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { NativeModules } from 'react-native';
|
|
2
|
+
import { NativeModules, DeviceEventEmitter, Platform, NativeEventEmitter } from 'react-native';
|
|
3
3
|
import { ScrollView as RNScrollView, FlatList as RNFlatList} from 'react-native';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
const { RNPlotline } = NativeModules;
|
|
@@ -7,6 +7,25 @@ const { RNPlotline } = NativeModules;
|
|
|
7
7
|
class plotline {
|
|
8
8
|
constructor() {
|
|
9
9
|
this.throttledNotifyScroll = this.throttle(this.handleScroll, 250);
|
|
10
|
+
this.plotlineEventsListener = null;
|
|
11
|
+
this.plotlineRedirectListener = null;
|
|
12
|
+
|
|
13
|
+
if (Platform.OS === 'android') {
|
|
14
|
+
this.plotlineEventsSubscription = DeviceEventEmitter.addListener('PlotlineEvents', (event) => {
|
|
15
|
+
this._notifyEvent(event.eventName, event.properties);
|
|
16
|
+
});
|
|
17
|
+
this.plotlineRedirectSubscription = DeviceEventEmitter.addListener('PlotlineRedirect', (keyValuePairs) => {
|
|
18
|
+
this._notifyRedirect(keyValuePairs);
|
|
19
|
+
});
|
|
20
|
+
} else if (Platform.OS === 'ios') {
|
|
21
|
+
const myNativeEventEmitterModule = new NativeEventEmitter(NativeModules.RNPlotline);
|
|
22
|
+
this.plotlineEventsSubscription = myNativeEventEmitterModule.addListener('PlotlineEvents', (event) => {
|
|
23
|
+
this._notifyEvent(event.eventName, event.properties);
|
|
24
|
+
});
|
|
25
|
+
this.plotlineRedirectSubscription = myNativeEventEmitterModule.addListener('PlotlineRedirect', (keyValuePairs) => {
|
|
26
|
+
this._notifyRedirect(keyValuePairs);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
10
29
|
}
|
|
11
30
|
|
|
12
31
|
throttle(func, limit) {
|
|
@@ -65,7 +84,35 @@ class plotline {
|
|
|
65
84
|
this.throttledNotifyScroll();
|
|
66
85
|
}
|
|
67
86
|
|
|
87
|
+
setPlotlineEventsListener(plotlineEventsListener) {
|
|
88
|
+
this.plotlineEventsListener = plotlineEventsListener;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setPlotlineRedirectListener(plotlineRedirectListener) {
|
|
92
|
+
this.plotlineRedirectListener = plotlineRedirectListener;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_notifyEvent(eventName, properties) {
|
|
96
|
+
if (this.plotlineEventsListener) {
|
|
97
|
+
this.plotlineEventsListener(eventName, properties);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_notifyRedirect(keyValuePairs) {
|
|
102
|
+
if (this.plotlineRedirectListener) {
|
|
103
|
+
this.plotlineRedirectListener(keyValuePairs);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
68
107
|
logout() {
|
|
108
|
+
if (this.plotlineEventsSubscription) {
|
|
109
|
+
this.plotlineEventsSubscription.remove();
|
|
110
|
+
this.plotlineEventsSubscription = null;
|
|
111
|
+
}
|
|
112
|
+
if (this.plotlineRedirectSubscription) {
|
|
113
|
+
this.plotlineRedirectSubscription.remove();
|
|
114
|
+
this.plotlineRedirectSubscription = null;
|
|
115
|
+
}
|
|
69
116
|
RNPlotline.logout();
|
|
70
117
|
}
|
|
71
118
|
}
|
package/ios/RNPlotline.h
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
1
|
#if __has_include("RCTBridgeModule.h")
|
|
3
2
|
#import "RCTBridgeModule.h"
|
|
3
|
+
#import "RCTEventEmitter.h"
|
|
4
4
|
#else
|
|
5
|
+
#import <React/RCTEventEmitter.h>
|
|
5
6
|
#import <React/RCTBridgeModule.h>
|
|
6
7
|
#endif
|
|
7
8
|
|
|
8
|
-
@interface RNPlotline :
|
|
9
|
+
@interface RNPlotline : RCTEventEmitter <RCTBridgeModule>
|
|
9
10
|
|
|
10
|
-
@end
|
|
11
|
-
|
|
11
|
+
@end
|
package/ios/RNPlotline.m
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
#import "RNPlotline.h"
|
|
3
3
|
#import <Plotline/Plotline-Swift.h>
|
|
4
|
+
#import <React/RCTEventEmitter.h>
|
|
4
5
|
|
|
5
6
|
@implementation RNPlotline
|
|
6
7
|
|
|
8
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
9
|
+
return @[@"PlotlineEvents",@"PlotlineRedirect"];
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
RCT_EXPORT_METHOD(init:(NSString *)apiKey userId:(NSString *)userId endpoint:(NSString *)endpoint)
|
|
8
13
|
{
|
|
9
14
|
if (endpoint != nil) {
|
|
@@ -12,6 +17,16 @@ RCT_EXPORT_METHOD(init:(NSString *)apiKey userId:(NSString *)userId endpoint:(NS
|
|
|
12
17
|
[Plotline initializeWithApiKey:apiKey userId:userId];
|
|
13
18
|
}
|
|
14
19
|
[Plotline setPlotlineFrameworkWithFramework:@"REACT_NATIVE"];
|
|
20
|
+
[Plotline setPlotlineEventsListenerWithListener:^(NSString *eventName, NSDictionary *eventProperties) {
|
|
21
|
+
NSDictionary *event = @{
|
|
22
|
+
@"eventName": eventName,
|
|
23
|
+
@"properties": eventProperties
|
|
24
|
+
};
|
|
25
|
+
[self sendEventWithName:@"PlotlineEvents" body:event];
|
|
26
|
+
}];
|
|
27
|
+
[Plotline setPlotlineRedirectListenerWithListener:^(NSDictionary<NSString *, NSString *> * redirectKeyValues) {
|
|
28
|
+
[self sendEventWithName:@"PlotlineRedirect" body:redirectKeyValues];
|
|
29
|
+
}];
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
RCT_EXPORT_METHOD(track:(NSString *)eventName properties: (NSDictionary *) properties)
|