@attentive-mobile/attentive-react-native-sdk 1.0.5 → 2.0.0-beta.2
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/README.md +126 -0
- package/android/build.gradle +1 -0
- package/android/src/main/kotlin/com/attentivereactnativesdk/AttentiveReactNativeSdkModule.kt +384 -0
- package/android/src/main/kotlin/com/attentivereactnativesdk/AttentiveReactNativeSdkPackage.kt +36 -0
- package/android/src/main/kotlin/com/attentivereactnativesdk/debug/AttentiveDebugHelper.kt +22 -6
- package/attentive-react-native-sdk.podspec +3 -3
- package/ios/AttentiveReactNativeSdk.h +1 -1
- package/ios/AttentiveReactNativeSdk.mm +317 -37
- package/ios/Bridging/ATTNNativeSDK.swift +506 -58
- package/ios/Bridging/AttentiveReactNativeSdk-Bridging-Header.h +3 -0
- package/ios/Bridging/AttentiveSDKManager.swift +83 -0
- package/ios/Podfile +3 -16
- package/lib/commonjs/NativeAttentiveReactNativeSdk.js +14 -0
- package/lib/commonjs/NativeAttentiveReactNativeSdk.js.map +1 -0
- package/lib/commonjs/eventTypes.js.map +1 -1
- package/lib/commonjs/index.js +362 -52
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeAttentiveReactNativeSdk.js +7 -0
- package/lib/module/NativeAttentiveReactNativeSdk.js.map +1 -0
- package/lib/module/eventTypes.js.map +1 -1
- package/lib/module/index.js +345 -50
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeAttentiveReactNativeSdk.d.ts +103 -0
- package/lib/typescript/NativeAttentiveReactNativeSdk.d.ts.map +1 -0
- package/lib/typescript/eventTypes.d.ts +44 -17
- package/lib/typescript/eventTypes.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +276 -41
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +21 -7
- package/src/NativeAttentiveReactNativeSdk.ts +152 -0
- package/src/eventTypes.tsx +57 -20
- package/src/index.tsx +472 -96
- package/android/src/main/java/com/attentivereactnativesdk/AttentiveReactNativeSdkModule.java +0 -310
- package/android/src/main/java/com/attentivereactnativesdk/AttentiveReactNativeSdkPackage.java +0 -28
- package/ios/AttentiveReactNativeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/AttentiveReactNativeSdk.xcodeproj/project.xcworkspace/xcuserdata/zheref.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/AttentiveReactNativeSdk.xcodeproj/xcuserdata/zheref.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/android/src/main/java/com/attentivereactnativesdk/AttentiveReactNativeSdkModule.java
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
package com.attentivereactnativesdk;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
import android.view.ViewGroup;
|
|
6
|
-
import androidx.annotation.NonNull;
|
|
7
|
-
import androidx.annotation.Nullable;
|
|
8
|
-
|
|
9
|
-
import com.attentive.androidsdk.AttentiveConfig;
|
|
10
|
-
import com.attentive.androidsdk.AttentiveEventTracker;
|
|
11
|
-
import com.attentive.androidsdk.UserIdentifiers;
|
|
12
|
-
import com.attentive.androidsdk.creatives.Creative;
|
|
13
|
-
import com.attentive.androidsdk.events.AddToCartEvent;
|
|
14
|
-
import com.attentive.androidsdk.events.CustomEvent;
|
|
15
|
-
import com.attentive.androidsdk.events.Item;
|
|
16
|
-
import com.attentive.androidsdk.events.Order;
|
|
17
|
-
import com.attentive.androidsdk.events.Price;
|
|
18
|
-
import com.attentive.androidsdk.events.ProductViewEvent;
|
|
19
|
-
import com.attentive.androidsdk.events.PurchaseEvent;
|
|
20
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
22
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
23
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
24
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
25
|
-
import com.facebook.react.bridge.UiThreadUtil;
|
|
26
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
27
|
-
import java.math.BigDecimal;
|
|
28
|
-
import java.security.InvalidParameterException;
|
|
29
|
-
import java.util.ArrayList;
|
|
30
|
-
import java.util.Arrays;
|
|
31
|
-
import java.util.Currency;
|
|
32
|
-
import java.util.HashMap;
|
|
33
|
-
import java.util.List;
|
|
34
|
-
import java.util.Locale;
|
|
35
|
-
import java.util.Map;
|
|
36
|
-
import com.attentivereactnativesdk.debug.AttentiveDebugHelper;
|
|
37
|
-
|
|
38
|
-
@ReactModule(name = AttentiveReactNativeSdkModule.NAME)
|
|
39
|
-
public class AttentiveReactNativeSdkModule extends ReactContextBaseJavaModule {
|
|
40
|
-
public static final String NAME = "AttentiveReactNativeSdk";
|
|
41
|
-
private static final String TAG = NAME;
|
|
42
|
-
|
|
43
|
-
private AttentiveConfig attentiveConfig;
|
|
44
|
-
private Creative creative;
|
|
45
|
-
private AttentiveDebugHelper debugHelper;
|
|
46
|
-
|
|
47
|
-
public AttentiveReactNativeSdkModule(ReactApplicationContext reactContext) {
|
|
48
|
-
super(reactContext);
|
|
49
|
-
this.debugHelper = new AttentiveDebugHelper(reactContext);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Override
|
|
53
|
-
@NonNull
|
|
54
|
-
public String getName() {
|
|
55
|
-
return NAME;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@ReactMethod
|
|
59
|
-
public void initialize(ReadableMap config) {
|
|
60
|
-
final String rawMode = config.getString("mode");
|
|
61
|
-
if (rawMode == null) {
|
|
62
|
-
throw new IllegalArgumentException("The 'mode' parameter cannot be null.");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
final String domain = config.getString("attentiveDomain");
|
|
66
|
-
final Boolean skipFatigue = config.hasKey("skipFatigueOnCreatives") ?
|
|
67
|
-
config.getBoolean("skipFatigueOnCreatives") : false;
|
|
68
|
-
|
|
69
|
-
// Initialize debug helper
|
|
70
|
-
final Boolean enableDebuggerFromConfig = config.hasKey("enableDebugger") ?
|
|
71
|
-
config.getBoolean("enableDebugger") : false;
|
|
72
|
-
debugHelper.initialize(enableDebuggerFromConfig);
|
|
73
|
-
|
|
74
|
-
attentiveConfig = new AttentiveConfig.Builder()
|
|
75
|
-
.context(this.getReactApplicationContext())
|
|
76
|
-
.domain(domain)
|
|
77
|
-
.mode(AttentiveConfig.Mode.valueOf(rawMode.toUpperCase(Locale.ROOT)))
|
|
78
|
-
.skipFatigueOnCreatives(skipFatigue)
|
|
79
|
-
.build();
|
|
80
|
-
AttentiveEventTracker.getInstance().initialize(attentiveConfig);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@ReactMethod
|
|
84
|
-
public void triggerCreative() {
|
|
85
|
-
this.triggerCreative(null);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ReactMethod
|
|
89
|
-
public void triggerCreative(@Nullable String creativeId) {
|
|
90
|
-
Log.i(TAG, "Native Attentive module was called to trigger the creative.");
|
|
91
|
-
try {
|
|
92
|
-
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
93
|
-
if (currentActivity != null) {
|
|
94
|
-
ViewGroup rootView =
|
|
95
|
-
(ViewGroup) currentActivity.getWindow().getDecorView().getRootView();
|
|
96
|
-
// The following calls edit the view hierarchy so they must run on the UI thread
|
|
97
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
98
|
-
creative = new Creative(attentiveConfig, rootView);
|
|
99
|
-
creative.trigger(null, creativeId);
|
|
100
|
-
if (debugHelper.isDebuggingEnabled()) {
|
|
101
|
-
Map<String, Object> debugData = new HashMap<>();
|
|
102
|
-
debugData.put("type", "trigger");
|
|
103
|
-
debugData.put("creativeId", creativeId != null ? creativeId : "default");
|
|
104
|
-
debugHelper.showDebugInfo("Creative Triggered", debugData);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
Log.w(TAG, "Could not trigger the Attentive Creative because the current Activity was null");
|
|
109
|
-
}
|
|
110
|
-
} catch (Exception e) {
|
|
111
|
-
Log.e(TAG, "Exception when triggering the creative: " + e);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@ReactMethod
|
|
116
|
-
public void destroyCreative() {
|
|
117
|
-
if (creative != null) {
|
|
118
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
119
|
-
creative.destroy();
|
|
120
|
-
creative = null;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@ReactMethod
|
|
126
|
-
public void updateDomain(String domain) {
|
|
127
|
-
attentiveConfig.changeDomain(domain);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
@ReactMethod
|
|
131
|
-
public void clearUser() {
|
|
132
|
-
attentiveConfig.clearUser();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@ReactMethod
|
|
136
|
-
public void identify(ReadableMap identifiers) {
|
|
137
|
-
UserIdentifiers.Builder idsBuilder = new UserIdentifiers.Builder();
|
|
138
|
-
if (identifiers.hasKey("phone")) {
|
|
139
|
-
idsBuilder.withPhone(identifiers.getString("phone"));
|
|
140
|
-
}
|
|
141
|
-
if (identifiers.hasKey("email")) {
|
|
142
|
-
idsBuilder.withEmail(identifiers.getString("email"));
|
|
143
|
-
}
|
|
144
|
-
if (identifiers.hasKey("klaviyoId")) {
|
|
145
|
-
idsBuilder.withKlaviyoId(identifiers.getString("klaviyoId"));
|
|
146
|
-
}
|
|
147
|
-
if (identifiers.hasKey("shopifyId")) {
|
|
148
|
-
idsBuilder.withShopifyId(identifiers.getString("shopifyId"));
|
|
149
|
-
}
|
|
150
|
-
if (identifiers.hasKey("clientUserId")) {
|
|
151
|
-
idsBuilder.withClientUserId(identifiers.getString("clientUserId"));
|
|
152
|
-
}
|
|
153
|
-
if (identifiers.hasKey("customIdentifiers")) {
|
|
154
|
-
Map<String, String> customIds = new HashMap<>();
|
|
155
|
-
Map<String, Object> rawCustomIds = identifiers.getMap("customIdentifiers").toHashMap();
|
|
156
|
-
for (Map.Entry<String, Object> entry : rawCustomIds.entrySet()) {
|
|
157
|
-
if (entry.getValue() instanceof String) {
|
|
158
|
-
customIds.put(entry.getKey(), (String) entry.getValue());
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
idsBuilder.withCustomIdentifiers(customIds);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
attentiveConfig.identify(idsBuilder.build());
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@ReactMethod
|
|
168
|
-
public void recordProductViewEvent(ReadableMap productViewAttrs) {
|
|
169
|
-
Log.i(TAG, "Sending product viewed event");
|
|
170
|
-
|
|
171
|
-
List<Item> items = buildItems(productViewAttrs.getArray("items"));
|
|
172
|
-
String deeplink = productViewAttrs.getString("deeplink");
|
|
173
|
-
ProductViewEvent productViewEvent = new ProductViewEvent.Builder(items).deeplink(deeplink).build();
|
|
174
|
-
|
|
175
|
-
AttentiveEventTracker.getInstance().recordEvent(productViewEvent);
|
|
176
|
-
|
|
177
|
-
if (debugHelper.isDebuggingEnabled()) {
|
|
178
|
-
Map<String, Object> debugData = new HashMap<>();
|
|
179
|
-
debugData.put("items_count", String.valueOf(items.size()));
|
|
180
|
-
debugData.put("deeplink", deeplink);
|
|
181
|
-
debugData.put("payload", productViewAttrs.toHashMap());
|
|
182
|
-
debugHelper.showDebugInfo("Product View Event", debugData);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
@ReactMethod
|
|
187
|
-
public void recordPurchaseEvent(ReadableMap purchaseAttrs) {
|
|
188
|
-
Log.i(TAG, "Sending purchase event");
|
|
189
|
-
Order order = new Order.Builder(purchaseAttrs.getMap("order").getString("orderId")).build();
|
|
190
|
-
|
|
191
|
-
List<Item> items = buildItems(purchaseAttrs.getArray("items"));
|
|
192
|
-
PurchaseEvent purchaseEvent = new PurchaseEvent.Builder(items, order).build();
|
|
193
|
-
|
|
194
|
-
AttentiveEventTracker.getInstance().recordEvent(purchaseEvent);
|
|
195
|
-
|
|
196
|
-
if (debugHelper.isDebuggingEnabled()) {
|
|
197
|
-
Map<String, Object> debugData = new HashMap<>();
|
|
198
|
-
debugData.put("items_count", String.valueOf(items.size()));
|
|
199
|
-
debugData.put("order_id", order.getOrderId());
|
|
200
|
-
debugData.put("payload", purchaseAttrs.toHashMap());
|
|
201
|
-
debugHelper.showDebugInfo("Purchase Event", debugData);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
@ReactMethod
|
|
206
|
-
public void recordAddToCartEvent(ReadableMap addToCartAttrs) {
|
|
207
|
-
Log.i(TAG, "Sending add to cart event");
|
|
208
|
-
|
|
209
|
-
List<Item> items = buildItems(addToCartAttrs.getArray("items"));
|
|
210
|
-
String deeplink = addToCartAttrs.getString("deeplink");
|
|
211
|
-
AddToCartEvent addToCartEvent = new AddToCartEvent.Builder(items).deeplink(deeplink).build();
|
|
212
|
-
|
|
213
|
-
AttentiveEventTracker.getInstance().recordEvent(addToCartEvent);
|
|
214
|
-
|
|
215
|
-
if (debugHelper.isDebuggingEnabled()) {
|
|
216
|
-
Map<String, Object> debugData = new HashMap<>();
|
|
217
|
-
debugData.put("items_count", String.valueOf(items.size()));
|
|
218
|
-
debugData.put("deeplink", deeplink);
|
|
219
|
-
debugData.put("payload", addToCartAttrs.toHashMap());
|
|
220
|
-
debugHelper.showDebugInfo("Add To Cart Event", debugData);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
@ReactMethod
|
|
225
|
-
public void recordCustomEvent(ReadableMap customEventAttrs) {
|
|
226
|
-
Log.i(TAG, "Sending custom event");
|
|
227
|
-
ReadableMap propertiesRawMap = customEventAttrs.getMap("properties");
|
|
228
|
-
if (propertiesRawMap == null) {
|
|
229
|
-
throw new IllegalArgumentException("The CustomEvent 'properties' field cannot be null.");
|
|
230
|
-
}
|
|
231
|
-
Map<String, String> properties = convertToStringMap(propertiesRawMap.toHashMap());
|
|
232
|
-
CustomEvent customEvent = new CustomEvent.Builder(customEventAttrs.getString("type"), properties).build();
|
|
233
|
-
|
|
234
|
-
AttentiveEventTracker.getInstance().recordEvent(customEvent);
|
|
235
|
-
|
|
236
|
-
if (debugHelper.isDebuggingEnabled()) {
|
|
237
|
-
Map<String, Object> debugData = new HashMap<>();
|
|
238
|
-
debugData.put("event_type", customEventAttrs.getString("type"));
|
|
239
|
-
debugData.put("properties_count", String.valueOf(properties.size()));
|
|
240
|
-
debugData.put("payload", customEventAttrs.toHashMap());
|
|
241
|
-
debugHelper.showDebugInfo("Custom Event", debugData);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
@ReactMethod
|
|
246
|
-
public void invokeAttentiveDebugHelper() {
|
|
247
|
-
debugHelper.invokeDebugHelper();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
@ReactMethod
|
|
251
|
-
public void exportDebugLogs(com.facebook.react.bridge.Promise promise) {
|
|
252
|
-
try {
|
|
253
|
-
String exportContent = debugHelper.exportDebugLogs();
|
|
254
|
-
promise.resolve(exportContent);
|
|
255
|
-
} catch (Exception e) {
|
|
256
|
-
promise.reject("EXPORT_ERROR", "Failed to export debug logs: " + e.getMessage(), e);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
private Map<String, String> convertToStringMap(Map<String, Object> inputMap) {
|
|
262
|
-
Map<String, String> outputMap = new HashMap<>();
|
|
263
|
-
for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
|
|
264
|
-
Object entryValue = entry.getValue();
|
|
265
|
-
if (entryValue == null) {
|
|
266
|
-
throw new InvalidParameterException(String.format("The key '%s' has a null value.", entry.getKey()));
|
|
267
|
-
}
|
|
268
|
-
if (entryValue instanceof String) {
|
|
269
|
-
outputMap.put(entry.getKey(), (String) entry.getValue());
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return outputMap;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private List<Item> buildItems(ReadableArray rawItems) {
|
|
277
|
-
Log.i(TAG, "buildItems method called with rawItems: " + rawItems.toString());
|
|
278
|
-
List<Item> items = new ArrayList<>();
|
|
279
|
-
for (int i = 0; i < rawItems.size(); i++) {
|
|
280
|
-
ReadableMap rawItem = rawItems.getMap(i);
|
|
281
|
-
|
|
282
|
-
ReadableMap priceMap = rawItem.getMap("price");
|
|
283
|
-
Price price = new Price.Builder(new BigDecimal(priceMap.getString("price")), Currency.getInstance(priceMap.getString("currency"))).build();
|
|
284
|
-
|
|
285
|
-
Item.Builder builder = new Item.Builder(rawItem.getString("productId"), rawItem.getString("productVariantId"), price);
|
|
286
|
-
|
|
287
|
-
if (rawItem.hasKey("productImage")) {
|
|
288
|
-
builder.productImage(rawItem.getString("productImage"));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (rawItem.hasKey("name")) {
|
|
292
|
-
builder.name(rawItem.getString("name"));
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (rawItem.hasKey("quantity")) {
|
|
296
|
-
builder.quantity(rawItem.getInt("quantity"));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (rawItem.hasKey("category")) {
|
|
300
|
-
builder.category(rawItem.getString("category"));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
Item item = builder.build();
|
|
304
|
-
items.add(item);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return items;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
}
|
package/android/src/main/java/com/attentivereactnativesdk/AttentiveReactNativeSdkPackage.java
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
package com.attentivereactnativesdk;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.ReactPackage;
|
|
6
|
-
import com.facebook.react.bridge.NativeModule;
|
|
7
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
-
|
|
10
|
-
import java.util.ArrayList;
|
|
11
|
-
import java.util.Collections;
|
|
12
|
-
import java.util.List;
|
|
13
|
-
|
|
14
|
-
public class AttentiveReactNativeSdkPackage implements ReactPackage {
|
|
15
|
-
@NonNull
|
|
16
|
-
@Override
|
|
17
|
-
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
-
modules.add(new AttentiveReactNativeSdkModule(reactContext));
|
|
20
|
-
return modules;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@NonNull
|
|
24
|
-
@Override
|
|
25
|
-
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
-
return Collections.emptyList();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>AttentiveReactNativeSdk.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
</dict>
|
|
14
|
-
</plist>
|