@appmetrica/react-native-analytics 3.0.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/LICENSE.md +21 -0
- package/README.md +29 -0
- package/android/build.gradle +89 -0
- package/android/gradle.properties +3 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +139 -0
- package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaPackage.java +28 -0
- package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeStartupParamsListener.java +38 -0
- package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +483 -0
- package/appmetrica-react-native-analytics.podspec +43 -0
- package/ios/AMARNAppMetrica.h +6 -0
- package/ios/AMARNAppMetrica.m +120 -0
- package/ios/AMARNAppMetricaUtils.h +24 -0
- package/ios/AMARNAppMetricaUtils.m +368 -0
- package/ios/AMARNStartupParamsUtils.h +8 -0
- package/ios/AMARNStartupParamsUtils.m +53 -0
- package/lib/commonjs/ecommerce.js +54 -0
- package/lib/commonjs/ecommerce.js.map +1 -0
- package/lib/commonjs/index.js +125 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/revenue.js +16 -0
- package/lib/commonjs/revenue.js.map +1 -0
- package/lib/module/ecommerce.js +47 -0
- package/lib/module/ecommerce.js.map +1 -0
- package/lib/module/index.js +91 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/revenue.js +10 -0
- package/lib/module/revenue.js.map +1 -0
- package/lib/typescript/src/ecommerce.d.ts +58 -0
- package/lib/typescript/src/ecommerce.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +64 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/revenue.d.ts +34 -0
- package/lib/typescript/src/revenue.d.ts.map +1 -0
- package/package.json +130 -0
- package/src/ecommerce.ts +122 -0
- package/src/index.ts +169 -0
- package/src/revenue.ts +36 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
package io.appmetrica.analytics.reactnative;
|
|
2
|
+
|
|
3
|
+
import android.location.Location;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
9
|
+
import com.facebook.react.bridge.ReadableType;
|
|
10
|
+
import io.appmetrica.analytics.AdRevenue;
|
|
11
|
+
import io.appmetrica.analytics.AdType;
|
|
12
|
+
import io.appmetrica.analytics.AppMetricaConfig;
|
|
13
|
+
import io.appmetrica.analytics.PreloadInfo;
|
|
14
|
+
import io.appmetrica.analytics.Revenue;
|
|
15
|
+
import io.appmetrica.analytics.StartupParamsCallback;
|
|
16
|
+
import io.appmetrica.analytics.ecommerce.ECommerceAmount;
|
|
17
|
+
import io.appmetrica.analytics.ecommerce.ECommerceCartItem;
|
|
18
|
+
import io.appmetrica.analytics.ecommerce.ECommerceEvent;
|
|
19
|
+
import io.appmetrica.analytics.ecommerce.ECommerceOrder;
|
|
20
|
+
import io.appmetrica.analytics.ecommerce.ECommercePrice;
|
|
21
|
+
import io.appmetrica.analytics.ecommerce.ECommerceProduct;
|
|
22
|
+
import io.appmetrica.analytics.ecommerce.ECommerceReferrer;
|
|
23
|
+
import io.appmetrica.analytics.ecommerce.ECommerceScreen;
|
|
24
|
+
import java.math.BigDecimal;
|
|
25
|
+
import java.util.ArrayList;
|
|
26
|
+
import java.util.Currency;
|
|
27
|
+
import java.util.HashMap;
|
|
28
|
+
import java.util.List;
|
|
29
|
+
import java.util.Map;
|
|
30
|
+
import java.util.Objects;
|
|
31
|
+
|
|
32
|
+
abstract class Utils {
|
|
33
|
+
|
|
34
|
+
@NonNull
|
|
35
|
+
static AppMetricaConfig toAppMetricaConfig(@NonNull ReadableMap configMap) {
|
|
36
|
+
AppMetricaConfig.Builder builder = AppMetricaConfig.newConfigBuilder(configMap.getString("apiKey"));
|
|
37
|
+
|
|
38
|
+
if (configMap.hasKey("appVersion")) {
|
|
39
|
+
builder.withAppVersion(configMap.getString("appVersion"));
|
|
40
|
+
}
|
|
41
|
+
if (configMap.hasKey("crashReporting")) {
|
|
42
|
+
builder.withCrashReporting(configMap.getBoolean("crashReporting"));
|
|
43
|
+
}
|
|
44
|
+
if (configMap.hasKey("firstActivationAsUpdate")) {
|
|
45
|
+
builder.handleFirstActivationAsUpdate(configMap.getBoolean("firstActivationAsUpdate"));
|
|
46
|
+
}
|
|
47
|
+
if (configMap.hasKey("location")) {
|
|
48
|
+
builder.withLocation(toLocation(configMap.getMap("location")));
|
|
49
|
+
}
|
|
50
|
+
if (configMap.hasKey("locationTracking")) {
|
|
51
|
+
builder.withLocationTracking(configMap.getBoolean("locationTracking"));
|
|
52
|
+
}
|
|
53
|
+
if (configMap.hasKey("logs") && configMap.getBoolean("logs")) {
|
|
54
|
+
builder.withLogs();
|
|
55
|
+
}
|
|
56
|
+
if (configMap.hasKey("maxReportsInDatabaseCount")) {
|
|
57
|
+
builder.withMaxReportsInDatabaseCount(configMap.getInt("maxReportsInDatabaseCount"));
|
|
58
|
+
}
|
|
59
|
+
if (configMap.hasKey("nativeCrashReporting")) {
|
|
60
|
+
builder.withNativeCrashReporting(configMap.getBoolean("nativeCrashReporting"));
|
|
61
|
+
}
|
|
62
|
+
if (configMap.hasKey("preloadInfo")) {
|
|
63
|
+
builder.withPreloadInfo(toPreloadInfo(configMap.getMap("preloadInfo")));
|
|
64
|
+
}
|
|
65
|
+
if (configMap.hasKey("sessionTimeout")) {
|
|
66
|
+
builder.withSessionTimeout(configMap.getInt("sessionTimeout"));
|
|
67
|
+
}
|
|
68
|
+
if (configMap.hasKey("statisticsSending")) {
|
|
69
|
+
builder.withDataSendingEnabled(configMap.getBoolean("statisticsSending"));
|
|
70
|
+
}
|
|
71
|
+
if (configMap.hasKey("sessionsAutoTracking")) {
|
|
72
|
+
builder.withSessionsAutoTrackingEnabled(configMap.getBoolean("sessionsAutoTracking"));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return builder.build();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Nullable
|
|
79
|
+
static Location toLocation(@Nullable ReadableMap locationMap) {
|
|
80
|
+
if (locationMap == null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Location location = new Location("Custom");
|
|
85
|
+
|
|
86
|
+
if (locationMap.hasKey("latitude")) {
|
|
87
|
+
location.setLatitude(locationMap.getDouble("latitude"));
|
|
88
|
+
}
|
|
89
|
+
if (locationMap.hasKey("longitude")) {
|
|
90
|
+
location.setLongitude(locationMap.getDouble("longitude"));
|
|
91
|
+
}
|
|
92
|
+
if (locationMap.hasKey("altitude")) {
|
|
93
|
+
location.setAltitude(locationMap.getDouble("altitude"));
|
|
94
|
+
}
|
|
95
|
+
if (locationMap.hasKey("accuracy")) {
|
|
96
|
+
location.setAccuracy((float) locationMap.getDouble("accuracy"));
|
|
97
|
+
}
|
|
98
|
+
if (locationMap.hasKey("course")) {
|
|
99
|
+
location.setBearing((float) locationMap.getDouble("course"));
|
|
100
|
+
}
|
|
101
|
+
if (locationMap.hasKey("speed")) {
|
|
102
|
+
location.setSpeed((float) locationMap.getDouble("speed"));
|
|
103
|
+
}
|
|
104
|
+
if (locationMap.hasKey("timestamp")) {
|
|
105
|
+
location.setTime((long) locationMap.getDouble("timestamp"));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return location;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Nullable
|
|
112
|
+
private static PreloadInfo toPreloadInfo(@Nullable ReadableMap preloadInfoMap) {
|
|
113
|
+
if (preloadInfoMap == null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
PreloadInfo.Builder builder = PreloadInfo.newBuilder(preloadInfoMap.getString("trackingId"));
|
|
118
|
+
|
|
119
|
+
if (preloadInfoMap.hasKey("additionalInfo")) {
|
|
120
|
+
ReadableMap additionalInfo = preloadInfoMap.getMap("additionalInfo");
|
|
121
|
+
if (additionalInfo != null) {
|
|
122
|
+
for (Map.Entry<String, Object> entry : additionalInfo.toHashMap().entrySet()) {
|
|
123
|
+
Object value = entry.getValue();
|
|
124
|
+
builder.setAdditionalParams(entry.getKey(), value == null ? null : value.toString());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return builder.build();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@NonNull
|
|
133
|
+
static ECommerceScreen toECommerceScreen(@NonNull ReadableMap ecommerceEventMap) {
|
|
134
|
+
ECommerceScreen screen = new ECommerceScreen();
|
|
135
|
+
if (ecommerceEventMap.hasKey("name")) {
|
|
136
|
+
screen.setName(ecommerceEventMap.getString("name"));
|
|
137
|
+
}
|
|
138
|
+
if (ecommerceEventMap.hasKey("searchQuery")) {
|
|
139
|
+
screen.setSearchQuery(ecommerceEventMap.getString("searchQuery"));
|
|
140
|
+
}
|
|
141
|
+
if (ecommerceEventMap.hasKey("payload")) {
|
|
142
|
+
ReadableMap payloadMap = ecommerceEventMap.getMap("payload");
|
|
143
|
+
screen.setPayload(toMapOfStrings(payloadMap));
|
|
144
|
+
}
|
|
145
|
+
if (ecommerceEventMap.hasKey("categoriesPath")) {
|
|
146
|
+
ReadableArray categoriesPathArray = ecommerceEventMap.getArray("categoriesPath");
|
|
147
|
+
screen.setCategoriesPath(toListOfStrings(categoriesPathArray));
|
|
148
|
+
}
|
|
149
|
+
return screen;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Nullable
|
|
153
|
+
static ECommerceAmount toEcommerceAmount(@NonNull ReadableMap amountMap) {
|
|
154
|
+
ReadableType amountType = amountMap.getType("amount");
|
|
155
|
+
String unit = amountMap.getString("unit");
|
|
156
|
+
if (unit != null) {
|
|
157
|
+
if (amountType == ReadableType.Number) {
|
|
158
|
+
return new ECommerceAmount(amountMap.getDouble("amount"), unit);
|
|
159
|
+
} else {
|
|
160
|
+
String amountString = amountMap.getString("amount");
|
|
161
|
+
return new ECommerceAmount(new BigDecimal(amountString), unit);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
Log.w(AppMetricaModule.TAG, "ECommerceAmount unit is null");
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@Nullable
|
|
170
|
+
static ECommercePrice toECommercePrice(@Nullable ReadableMap priceMap) {
|
|
171
|
+
if (priceMap == null) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
ReadableMap amountMap = Objects.requireNonNull(priceMap.getMap("amount"));
|
|
175
|
+
ECommerceAmount amount = toEcommerceAmount(amountMap);
|
|
176
|
+
if (amount == null) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
ECommercePrice price = new ECommercePrice(amount);
|
|
180
|
+
if (priceMap.hasKey("internalComponents")) {
|
|
181
|
+
ReadableArray list = priceMap.getArray("internalComponents");
|
|
182
|
+
if (list != null) {
|
|
183
|
+
List<ECommerceAmount> newlist = new ArrayList<ECommerceAmount>(list.size());
|
|
184
|
+
for (int i = 0; i < list.size(); i++) {
|
|
185
|
+
ECommerceAmount component = toEcommerceAmount(list.getMap(i));
|
|
186
|
+
newlist.add(component);
|
|
187
|
+
}
|
|
188
|
+
price.setInternalComponents(newlist);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return price;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@NonNull
|
|
195
|
+
static ECommerceProduct toECommerceProduct(@NonNull ReadableMap productMap) {
|
|
196
|
+
ECommerceProduct product = new ECommerceProduct(Objects.requireNonNull(productMap.getString("sku")));
|
|
197
|
+
|
|
198
|
+
if (productMap.hasKey("name")) {
|
|
199
|
+
product.setName(productMap.getString("name"));
|
|
200
|
+
}
|
|
201
|
+
if (productMap.hasKey("actualPrice")) {
|
|
202
|
+
ReadableMap priceMap = productMap.getMap("actualPrice");
|
|
203
|
+
product.setActualPrice(toECommercePrice(priceMap));
|
|
204
|
+
}
|
|
205
|
+
if (productMap.hasKey("originalPrice")) {
|
|
206
|
+
ReadableMap priceMap = productMap.getMap("originalPrice");
|
|
207
|
+
product.setOriginalPrice(toECommercePrice(priceMap));
|
|
208
|
+
}
|
|
209
|
+
if (productMap.hasKey("promocodes")) {
|
|
210
|
+
ReadableArray promocodesArray = productMap.getArray("promocodes");
|
|
211
|
+
product.setPromocodes(toListOfStrings(promocodesArray));
|
|
212
|
+
}
|
|
213
|
+
if (productMap.hasKey("categoriesPath")) {
|
|
214
|
+
ReadableArray categoriesArray = productMap.getArray("categoriesPath");
|
|
215
|
+
product.setCategoriesPath(toListOfStrings(categoriesArray));
|
|
216
|
+
}
|
|
217
|
+
if (productMap.hasKey("payload")) {
|
|
218
|
+
ReadableMap payloadMap = productMap.getMap("payload");
|
|
219
|
+
product.setPayload(toMapOfStrings(payloadMap));
|
|
220
|
+
}
|
|
221
|
+
return product;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@Nullable
|
|
225
|
+
static ECommerceReferrer toECommerceReferrer(@Nullable ReadableMap referrerMap) {
|
|
226
|
+
if (referrerMap == null) return null;
|
|
227
|
+
ECommerceReferrer referrer = new ECommerceReferrer();
|
|
228
|
+
if (referrerMap.hasKey("type")) {
|
|
229
|
+
referrer.setType(referrerMap.getString("type"));
|
|
230
|
+
}
|
|
231
|
+
if (referrerMap.hasKey("identifier")) {
|
|
232
|
+
referrer.setIdentifier(referrerMap.getString("identifier"));
|
|
233
|
+
}
|
|
234
|
+
if (referrerMap.hasKey("screen")) {
|
|
235
|
+
ReadableMap screenMap = referrerMap.getMap("screen");
|
|
236
|
+
if (screenMap != null) {
|
|
237
|
+
referrer.setScreen(toECommerceScreen(screenMap));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return referrer;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@Nullable
|
|
244
|
+
static ECommerceCartItem toECommerceCartItem(@Nullable ReadableMap cartItemMap) {
|
|
245
|
+
if (cartItemMap == null) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
ECommerceProduct product = toECommerceProduct(Objects.requireNonNull(cartItemMap.getMap("product")));
|
|
249
|
+
ECommercePrice price = toECommercePrice(Objects.requireNonNull(cartItemMap.getMap("price")));
|
|
250
|
+
if (price == null) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
ReadableType quantityType = cartItemMap.getType("quantity");
|
|
254
|
+
if (quantityType == ReadableType.Number) {
|
|
255
|
+
double quantity = cartItemMap.getDouble("quantity");
|
|
256
|
+
ECommerceCartItem item = new ECommerceCartItem(product, price, quantity);
|
|
257
|
+
if (cartItemMap.hasKey("referrer")) {
|
|
258
|
+
ReadableMap referrer = cartItemMap.getMap("referrer");
|
|
259
|
+
item.setReferrer(toECommerceReferrer(referrer));
|
|
260
|
+
}
|
|
261
|
+
return item;
|
|
262
|
+
} else {
|
|
263
|
+
BigDecimal quantity = new BigDecimal(cartItemMap.getString("quantity"));
|
|
264
|
+
ECommerceCartItem item = new ECommerceCartItem(product, price, quantity);
|
|
265
|
+
if (cartItemMap.hasKey("referrer")) {
|
|
266
|
+
ReadableMap referrer = cartItemMap.getMap("referrer");
|
|
267
|
+
item.setReferrer(toECommerceReferrer(referrer));
|
|
268
|
+
}
|
|
269
|
+
return item;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@NonNull
|
|
274
|
+
static ECommerceOrder toECommerceOrder(@NonNull ReadableMap orderMap) {
|
|
275
|
+
String orderId = orderMap.getString("orderId");
|
|
276
|
+
ReadableArray list = orderMap.getArray("products");
|
|
277
|
+
List<ECommerceCartItem> newlist = new ArrayList<ECommerceCartItem>(Objects.requireNonNull(list).size());
|
|
278
|
+
for (int i = 0; i < list.size(); i++) {
|
|
279
|
+
ECommerceCartItem component = toECommerceCartItem(list.getMap(i));
|
|
280
|
+
newlist.add(component);
|
|
281
|
+
}
|
|
282
|
+
ECommerceOrder order = new ECommerceOrder(Objects.requireNonNull(orderId), newlist);
|
|
283
|
+
if (orderMap.hasKey("payload")) {
|
|
284
|
+
ReadableMap payload = orderMap.getMap("payload");
|
|
285
|
+
order.setPayload(toMapOfStrings(payload));
|
|
286
|
+
}
|
|
287
|
+
return order;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@Nullable
|
|
291
|
+
static ECommerceEvent toECommerceEvent(@NonNull ReadableMap ecommerceEventMap) {
|
|
292
|
+
String type = ecommerceEventMap.getString("ecommerceEvent");
|
|
293
|
+
if (type == null) return null;
|
|
294
|
+
if (type.equals("showSceenEvent")) {
|
|
295
|
+
ReadableMap screenMap = ecommerceEventMap.getMap("ecommerceScreen");
|
|
296
|
+
if (screenMap != null) {
|
|
297
|
+
return ECommerceEvent.showScreenEvent(toECommerceScreen(screenMap));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (type.equals("showProductCardEvent")) {
|
|
301
|
+
ReadableMap cardMap = ecommerceEventMap.getMap("product");
|
|
302
|
+
ReadableMap screenMap = ecommerceEventMap.getMap("ecommerceScreen");
|
|
303
|
+
if (cardMap != null && screenMap != null) {
|
|
304
|
+
return ECommerceEvent.showProductCardEvent(toECommerceProduct(cardMap), toECommerceScreen(screenMap));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (type.equals("showProductDetailsEvent")) {
|
|
308
|
+
ReadableMap productMap = ecommerceEventMap.getMap("product");
|
|
309
|
+
ReadableMap referrerMap = ecommerceEventMap.getMap("referrer");
|
|
310
|
+
if (productMap != null) {
|
|
311
|
+
return ECommerceEvent.showProductDetailsEvent(toECommerceProduct(productMap), toECommerceReferrer(referrerMap));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (type.equals("addCartItemEvent")) {
|
|
315
|
+
ECommerceCartItem cartItem = toECommerceCartItem(ecommerceEventMap.getMap("cartItem"));
|
|
316
|
+
if (cartItem != null) {
|
|
317
|
+
return ECommerceEvent.addCartItemEvent(cartItem);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (type.equals("removeCartItemEvent")) {
|
|
321
|
+
ECommerceCartItem cartItem = toECommerceCartItem(ecommerceEventMap.getMap("cartItem"));
|
|
322
|
+
if (cartItem != null) {
|
|
323
|
+
return ECommerceEvent.removeCartItemEvent(cartItem);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (type.equals("beginCheckoutEvent")) {
|
|
327
|
+
ReadableMap orderMap = ecommerceEventMap.getMap("order");
|
|
328
|
+
if (orderMap != null) {
|
|
329
|
+
return ECommerceEvent.beginCheckoutEvent(toECommerceOrder(orderMap));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (type.equals("purchaseEvent")) {
|
|
333
|
+
ReadableMap orderMap = ecommerceEventMap.getMap("order");
|
|
334
|
+
if (orderMap != null) {
|
|
335
|
+
return ECommerceEvent.purchaseEvent(toECommerceOrder(orderMap));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
@NonNull
|
|
342
|
+
static List<String> toStartupKeyList(@NonNull ReadableArray keys) {
|
|
343
|
+
ArrayList<String> startupKeys = new ArrayList<>();
|
|
344
|
+
for (int i = 0; i < keys.size(); i++) {
|
|
345
|
+
String item = keys.getString(i);
|
|
346
|
+
if (item.equals("appmetrica_device_id_hash")) {
|
|
347
|
+
startupKeys.add(StartupParamsCallback.APPMETRICA_DEVICE_ID_HASH);
|
|
348
|
+
}
|
|
349
|
+
if (item.equals("appmetrica_device_id")) {
|
|
350
|
+
startupKeys.add(StartupParamsCallback.APPMETRICA_DEVICE_ID);
|
|
351
|
+
}
|
|
352
|
+
if (item.equals("appmetrica_uuid")) {
|
|
353
|
+
startupKeys.add(StartupParamsCallback.APPMETRICA_UUID);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return startupKeys;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
@NonNull
|
|
360
|
+
static Revenue toRevenue(@NonNull ReadableMap revenueMap) {
|
|
361
|
+
long price = (long) (revenueMap.getDouble("price") * 1000000);
|
|
362
|
+
String currency = revenueMap.getString("currency");
|
|
363
|
+
Revenue.Builder revenue = Revenue.newBuilder(price, Currency.getInstance(currency));
|
|
364
|
+
if (revenueMap.hasKey("productID")) {
|
|
365
|
+
revenue.withProductID(revenueMap.getString("productID"));
|
|
366
|
+
}
|
|
367
|
+
if (revenueMap.hasKey("payload")) {
|
|
368
|
+
revenue.withPayload(revenueMap.getString("payload"));
|
|
369
|
+
}
|
|
370
|
+
if (revenueMap.hasKey("quantity")) {
|
|
371
|
+
revenue.withQuantity(revenueMap.getInt("quantity"));
|
|
372
|
+
}
|
|
373
|
+
revenue.withReceipt(toReceipt(revenueMap.getMap("receipt")));
|
|
374
|
+
return revenue.build();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@Nullable
|
|
378
|
+
static Revenue.Receipt toReceipt(@Nullable ReadableMap receipt) {
|
|
379
|
+
if (receipt == null) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
Revenue.Receipt.Builder revenueReceipt = Revenue.Receipt.newBuilder();
|
|
383
|
+
if (receipt.hasKey("receiptData")) {
|
|
384
|
+
revenueReceipt.withData(receipt.getString("receiptData"));
|
|
385
|
+
}
|
|
386
|
+
if (receipt.hasKey("signature")) {
|
|
387
|
+
revenueReceipt.withSignature(receipt.getString("signature"));
|
|
388
|
+
}
|
|
389
|
+
return revenueReceipt.build();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@NonNull
|
|
393
|
+
private static AdRevenue.Builder parseAdRevenuePrice(@NonNull ReadableMap revenueMap) {
|
|
394
|
+
ReadableType priceType = revenueMap.getType("price");
|
|
395
|
+
String currency = revenueMap.getString("currency");
|
|
396
|
+
if (priceType == ReadableType.Number) {
|
|
397
|
+
double price = revenueMap.getDouble("price");
|
|
398
|
+
return AdRevenue.newBuilder(price, Currency.getInstance(currency));
|
|
399
|
+
} else {
|
|
400
|
+
String price = revenueMap.getString("price");
|
|
401
|
+
return AdRevenue.newBuilder(new BigDecimal(price), Currency.getInstance(currency));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
@NonNull
|
|
406
|
+
static AdRevenue toAdRevenue(@NonNull ReadableMap revenueMap) {
|
|
407
|
+
AdRevenue.Builder adRevenue = parseAdRevenuePrice(revenueMap);
|
|
408
|
+
if (revenueMap.hasKey("payload")) {
|
|
409
|
+
ReadableMap payloadMap = revenueMap.getMap("payload");
|
|
410
|
+
adRevenue.withPayload(toMapOfStrings(payloadMap));
|
|
411
|
+
}
|
|
412
|
+
if (revenueMap.hasKey("adType")) {
|
|
413
|
+
String type = revenueMap.getString("adType");
|
|
414
|
+
if (type != null) {
|
|
415
|
+
adRevenue.withAdType(toAdType(type));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (revenueMap.hasKey("adNetwork")) {
|
|
419
|
+
adRevenue.withAdNetwork(revenueMap.getString("adNetwork"));
|
|
420
|
+
}
|
|
421
|
+
if (revenueMap.hasKey("adPlacementID")) {
|
|
422
|
+
adRevenue.withAdPlacementId(revenueMap.getString("adPlacementID"));
|
|
423
|
+
}
|
|
424
|
+
if (revenueMap.hasKey("adPlacementName")) {
|
|
425
|
+
adRevenue.withAdPlacementName(revenueMap.getString("adPlacementName"));
|
|
426
|
+
}
|
|
427
|
+
if (revenueMap.hasKey("adUnitID")) {
|
|
428
|
+
adRevenue.withAdUnitId(revenueMap.getString("adUnitID"));
|
|
429
|
+
}
|
|
430
|
+
if (revenueMap.hasKey("adUnitName")) {
|
|
431
|
+
adRevenue.withAdUnitName(revenueMap.getString("adUnitName"));
|
|
432
|
+
}
|
|
433
|
+
if (revenueMap.hasKey("precision")) {
|
|
434
|
+
adRevenue.withPrecision(revenueMap.getString("precision"));
|
|
435
|
+
}
|
|
436
|
+
return adRevenue.build();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
@NonNull
|
|
440
|
+
static AdType toAdType(@NonNull String type) {
|
|
441
|
+
switch (type) {
|
|
442
|
+
case "native":
|
|
443
|
+
return AdType.NATIVE;
|
|
444
|
+
case "banner":
|
|
445
|
+
return AdType.BANNER;
|
|
446
|
+
case "mrec":
|
|
447
|
+
return AdType.MREC;
|
|
448
|
+
case "interstitial":
|
|
449
|
+
return AdType.INTERSTITIAL;
|
|
450
|
+
case "rewarded":
|
|
451
|
+
return AdType.REWARDED;
|
|
452
|
+
default:
|
|
453
|
+
return AdType.OTHER;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
@Nullable
|
|
458
|
+
private static Map<String, String> toMapOfStrings(@Nullable ReadableMap oldMap) {
|
|
459
|
+
if (oldMap == null) {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
HashMap<String, String> newMap = new HashMap<>();
|
|
463
|
+
for (Map.Entry<String, Object> entry : oldMap.toHashMap().entrySet()) {
|
|
464
|
+
if (entry.getValue() instanceof String) {
|
|
465
|
+
newMap.put(entry.getKey(), (String) entry.getValue());
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return newMap;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
@Nullable
|
|
472
|
+
private static List<String> toListOfStrings(@Nullable ReadableArray oldArray) {
|
|
473
|
+
if (oldArray == null) {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
List<Object> list = oldArray.toArrayList();
|
|
477
|
+
List<String> newArray = new ArrayList<String>(list.size());
|
|
478
|
+
for (Object object : list) {
|
|
479
|
+
newArray.add(Objects.toString(object));
|
|
480
|
+
}
|
|
481
|
+
return newArray;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "appmetrica-react-native-analytics"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = package["homepage"]
|
|
11
|
+
s.license = package["license"]
|
|
12
|
+
s.authors = package["author"]
|
|
13
|
+
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
15
|
+
s.source = { :git => "https://github.com/appmetrica/appmetrica-react-native-plugin.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
18
|
+
|
|
19
|
+
s.dependency "AppMetricaAnalytics", "5.4.0"
|
|
20
|
+
|
|
21
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
22
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
23
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
24
|
+
install_modules_dependencies(s)
|
|
25
|
+
else
|
|
26
|
+
s.dependency "React-Core"
|
|
27
|
+
|
|
28
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
29
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
30
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
31
|
+
s.pod_target_xcconfig = {
|
|
32
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
33
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
34
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
35
|
+
}
|
|
36
|
+
s.dependency "React-Codegen"
|
|
37
|
+
s.dependency "RCT-Folly"
|
|
38
|
+
s.dependency "RCTRequired"
|
|
39
|
+
s.dependency "RCTTypeSafety"
|
|
40
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
#import "AMARNAppMetrica.h"
|
|
3
|
+
#import "AMARNAppMetricaUtils.h"
|
|
4
|
+
#import "AMARNStartupParamsUtils.h"
|
|
5
|
+
#import <AppMetricaCrashes/AppMetricaCrashes.h>
|
|
6
|
+
|
|
7
|
+
@implementation AMARNAppMetrica
|
|
8
|
+
|
|
9
|
+
@synthesize methodQueue = _methodQueue;
|
|
10
|
+
|
|
11
|
+
RCT_EXPORT_MODULE(AppMetrica)
|
|
12
|
+
|
|
13
|
+
RCT_EXPORT_METHOD(activate:(NSDictionary *)configDict)
|
|
14
|
+
{
|
|
15
|
+
[[AMAAppMetricaCrashes crashes] setConfiguration:[AMARNAppMetricaUtils crashConfigurationForDictionary:configDict]];
|
|
16
|
+
[AMAAppMetrica activateWithConfiguration:[AMARNAppMetricaUtils configurationForDictionary:configDict]];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
RCT_EXPORT_METHOD(getLibraryApiLevel)
|
|
20
|
+
{
|
|
21
|
+
// It does nothing for iOS
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
RCT_EXPORT_METHOD(getLibraryVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
25
|
+
{
|
|
26
|
+
resolve([AMAAppMetrica libraryVersion]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
RCT_EXPORT_METHOD(pauseSession)
|
|
30
|
+
{
|
|
31
|
+
[AMAAppMetrica pauseSession];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
RCT_EXPORT_METHOD(reportAppOpen:(NSString *)deeplink)
|
|
35
|
+
{
|
|
36
|
+
[AMAAppMetrica trackOpeningURL:[NSURL URLWithString:deeplink]];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
RCT_EXPORT_METHOD(reportError:(NSString *)identifier:(NSString *)message) {
|
|
40
|
+
AMAError *error = [AMAError errorWithIdentifier:identifier message:message parameters:NULL];
|
|
41
|
+
[[AMAAppMetricaCrashes crashes] reportError:error onFailure:nil];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
RCT_EXPORT_METHOD(reportEvent:(NSString *)eventName:(NSDictionary *)attributes)
|
|
45
|
+
{
|
|
46
|
+
if (attributes == nil) {
|
|
47
|
+
[AMAAppMetrica reportEvent:eventName onFailure:^(NSError *error) {
|
|
48
|
+
NSLog(@"error: %@", [error localizedDescription]);
|
|
49
|
+
}];
|
|
50
|
+
} else {
|
|
51
|
+
[AMAAppMetrica reportEvent:eventName parameters:attributes onFailure:^(NSError *error) {
|
|
52
|
+
NSLog(@"error: %@", [error localizedDescription]);
|
|
53
|
+
}];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
RCT_EXPORT_METHOD(requestStartupParams:(NSArray *)identifiers:(RCTResponseSenderBlock)listener)
|
|
58
|
+
{
|
|
59
|
+
AMAIdentifiersCompletionBlock block = ^(NSDictionary<AMAStartupKey,id> * _Nullable identifiers, NSError * _Nullable error) {
|
|
60
|
+
NSDictionary *result = [AMARNStartupParamsUtils toStrartupParamsResult:identifiers];
|
|
61
|
+
NSString *errorStr = [AMARNStartupParamsUtils stringFromRequestStartupParamsError:error];
|
|
62
|
+
listener(@[[self wrap:result], [self wrap:errorStr]]);
|
|
63
|
+
};
|
|
64
|
+
[AMAAppMetrica requestStartupIdentifiersWithKeys:[AMARNStartupParamsUtils toStartupKeys:identifiers] completionQueue:nil completionBlock:block];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
RCT_EXPORT_METHOD(resumeSession)
|
|
68
|
+
{
|
|
69
|
+
[AMAAppMetrica resumeSession];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
RCT_EXPORT_METHOD(sendEventsBuffer)
|
|
73
|
+
{
|
|
74
|
+
[AMAAppMetrica sendEventsBuffer];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
RCT_EXPORT_METHOD(setLocation:(NSDictionary *)locationDict)
|
|
78
|
+
{
|
|
79
|
+
AMAAppMetrica.customLocation = [AMARNAppMetricaUtils locationForDictionary:locationDict];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
RCT_EXPORT_METHOD(setLocationTracking:(BOOL)enabled)
|
|
83
|
+
{
|
|
84
|
+
AMAAppMetrica.locationTrackingEnabled = enabled;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
RCT_EXPORT_METHOD(setDataSendingEnabled:(BOOL)enabled)
|
|
88
|
+
{
|
|
89
|
+
[AMAAppMetrica setDataSendingEnabled:enabled];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
RCT_EXPORT_METHOD(reportECommerce:(NSDictionary *)ecommerceDict)
|
|
93
|
+
{
|
|
94
|
+
[AMAAppMetrica reportECommerce:[AMARNAppMetricaUtils ecommerceForDict:ecommerceDict] onFailure:nil];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
RCT_EXPORT_METHOD(setUserProfileID:(NSString *)userProfileID)
|
|
98
|
+
{
|
|
99
|
+
[AMAAppMetrica setUserProfileID:userProfileID];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
RCT_EXPORT_METHOD(reportRevenue:(NSDictionary *)revenueDict)
|
|
103
|
+
{
|
|
104
|
+
[AMAAppMetrica reportRevenue:[AMARNAppMetricaUtils revenueForDict:revenueDict] onFailure:nil];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
RCT_EXPORT_METHOD(reportAdRevenue:(NSDictionary *)revenueDict)
|
|
108
|
+
{
|
|
109
|
+
[AMAAppMetrica reportAdRevenue:[AMARNAppMetricaUtils adRevenueForDict:revenueDict] onFailure:nil];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- (NSObject *)wrap:(NSObject *)value
|
|
113
|
+
{
|
|
114
|
+
if (value == nil) {
|
|
115
|
+
return [NSNull null];
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
#import <CoreLocation/CoreLocation.h>
|
|
3
|
+
#import <AppMetricaCore/AppMetricaCore.h>
|
|
4
|
+
#import <AppMetricaCrashes/AppMetricaCrashes.h>
|
|
5
|
+
|
|
6
|
+
@interface AMARNAppMetricaUtils : NSObject
|
|
7
|
+
|
|
8
|
+
+ (AMAAppMetricaConfiguration *)configurationForDictionary:(NSDictionary *)configDict;
|
|
9
|
+
+ (AMAAppMetricaCrashesConfiguration *)crashConfigurationForDictionary:(NSDictionary *)crashConfigDict;
|
|
10
|
+
+ (CLLocation *)locationForDictionary:(NSDictionary *)locationDict;
|
|
11
|
+
+ (AMAECommerceScreen *)ecommerceScreenForDict:(NSDictionary *)ecommerceScreenDict;
|
|
12
|
+
+ (AMAECommerceAmount *)ecommerceAmountForDict:(NSDictionary *)ecommerceAmountDict;
|
|
13
|
+
+ (AMAECommercePrice *)ecommercePriceForDict:(NSDictionary *)ecommercePriceDict;
|
|
14
|
+
+ (AMAECommerceReferrer *)ecommerceReferrerForDict:(NSDictionary *)ecommerceReferrerDict;
|
|
15
|
+
+ (AMAECommerceProduct *)ecommerceProductForDict:(NSDictionary *)ecommerceProductDict;
|
|
16
|
+
+ (AMAECommerceCartItem *)ecommerceCartItemForDict:(NSDictionary *)ecommerceCartItemDict;
|
|
17
|
+
+ (AMAECommerceOrder *)ecommerceOrderForDict:(NSDictionary *)ecommerceOrderDict;
|
|
18
|
+
+ (AMAECommerce *)ecommerceForDict:(NSDictionary *)ecommerceDict;
|
|
19
|
+
+ (AMARevenueInfo *)revenueForDict:(NSDictionary *)revenueDict;
|
|
20
|
+
+ (AMAAdRevenueInfo *)adRevenueForDict:(NSDictionary *)revenueDict;
|
|
21
|
+
+ (AMAAdType)toAdType:(NSString *)type;
|
|
22
|
+
+ (NSDictionary *)convertRevenueInfoPayload:(NSString *)payload;
|
|
23
|
+
|
|
24
|
+
@end
|