@adadapted/react-native-sdk 3.1.9 → 3.1.11
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/.project +1 -1
- package/android/.settings/org.eclipse.buildship.core.prefs +1 -1
- package/android/bin/.project +1 -1
- package/android/bin/.settings/org.eclipse.buildship.core.prefs +1 -1
- package/lib/commonjs/api/adadaptedApiRequests.js +10 -24
- package/lib/commonjs/api/adadaptedApiRequests.js.map +1 -1
- package/lib/commonjs/api/adadaptedApiRequests.mock.js +11 -21
- package/lib/commonjs/api/adadaptedApiRequests.mock.js.map +1 -1
- package/lib/commonjs/api/adadaptedApiTypes.js +1 -30
- package/lib/commonjs/api/adadaptedApiTypes.js.map +1 -1
- package/lib/commonjs/components/AdZone.js +21 -47
- package/lib/commonjs/components/AdZone.js.map +1 -1
- package/lib/commonjs/index.js +127 -182
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/util.js +4 -2
- package/lib/commonjs/util.js.map +1 -1
- package/lib/module/api/adadaptedApiRequests.js +9 -8
- package/lib/module/api/adadaptedApiRequests.js.map +1 -1
- package/lib/module/api/adadaptedApiRequests.mock.js +12 -11
- package/lib/module/api/adadaptedApiRequests.mock.js.map +1 -1
- package/lib/module/api/adadaptedApiTypes.js +6 -11
- package/lib/module/api/adadaptedApiTypes.js.map +1 -1
- package/lib/module/components/AdZone.js +20 -35
- package/lib/module/components/AdZone.js.map +1 -1
- package/lib/module/index.js +130 -159
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/util.js +4 -1
- package/lib/module/util.js.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -0
- package/package.json +11 -10
- package/src/index.tsx +26 -5
package/lib/module/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* The AdadaptedReactNativeSdk package/module definition.
|
|
5
4
|
*/
|
|
@@ -11,53 +10,49 @@ import { AdZone } from "./components/AdZone";
|
|
|
11
10
|
import { safeInvoke } from "./util";
|
|
12
11
|
import packageJson from "../package.json";
|
|
13
12
|
import base64 from "react-native-base64";
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Enum representing possible device operating systems.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
export let DeviceOS;
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
20
|
* Enum defining the different API environments.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
22
|
(function (DeviceOS) {
|
|
24
23
|
DeviceOS["ANDROID"] = "android";
|
|
25
24
|
DeviceOS["IOS"] = "ios";
|
|
26
25
|
})(DeviceOS || (DeviceOS = {}));
|
|
27
|
-
|
|
28
26
|
export let ApiEnv;
|
|
27
|
+
|
|
29
28
|
/**
|
|
30
29
|
* Enum defining the different API environments for List Manager.
|
|
31
30
|
*/
|
|
32
|
-
|
|
33
31
|
(function (ApiEnv) {
|
|
34
32
|
ApiEnv["Prod"] = "https://ads.adadapted.com";
|
|
35
33
|
ApiEnv["Dev"] = "https://sandbox.adadapted.com";
|
|
36
34
|
ApiEnv["Mock"] = "MOCK_DATA";
|
|
37
35
|
})(ApiEnv || (ApiEnv = {}));
|
|
38
|
-
|
|
39
36
|
export let ListManagerApiEnv;
|
|
37
|
+
|
|
40
38
|
/**
|
|
41
39
|
* Enum defining the different API environments for the Payload Server.
|
|
42
40
|
*/
|
|
43
|
-
|
|
44
41
|
(function (ListManagerApiEnv) {
|
|
45
42
|
ListManagerApiEnv["Prod"] = "https://ec.adadapted.com";
|
|
46
43
|
ListManagerApiEnv["Dev"] = "https://sandec.adadapted.com";
|
|
47
44
|
ListManagerApiEnv["Mock"] = "MOCK_DATA";
|
|
48
45
|
})(ListManagerApiEnv || (ListManagerApiEnv = {}));
|
|
49
|
-
|
|
50
46
|
export let PayloadApiEnv;
|
|
47
|
+
|
|
51
48
|
/**
|
|
52
49
|
* Interface defining inputs to the {@link Sdk.initialize} method.
|
|
53
50
|
*/
|
|
54
|
-
|
|
55
51
|
(function (PayloadApiEnv) {
|
|
56
52
|
PayloadApiEnv["Prod"] = "https://payload.adadapted.com";
|
|
57
53
|
PayloadApiEnv["Dev"] = "https://sandpayload.adadapted.com";
|
|
58
54
|
PayloadApiEnv["Mock"] = "MOCK_DATA";
|
|
59
55
|
})(PayloadApiEnv || (PayloadApiEnv = {}));
|
|
60
|
-
|
|
61
56
|
/**
|
|
62
57
|
* Class that acts as the AdAdapted SDK for react-native.
|
|
63
58
|
*/
|
|
@@ -143,6 +138,14 @@ export class AdadaptedReactNativeSdk {
|
|
|
143
138
|
* @param payloads - All payloads the client must go through.
|
|
144
139
|
*/
|
|
145
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Deeplink event listener.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* AppState event listener.
|
|
147
|
+
*/
|
|
148
|
+
|
|
146
149
|
/**
|
|
147
150
|
* Gets the Session ID.
|
|
148
151
|
* @returns the Session ID.
|
|
@@ -150,87 +153,68 @@ export class AdadaptedReactNativeSdk {
|
|
|
150
153
|
getSessionId() {
|
|
151
154
|
return this.sessionId;
|
|
152
155
|
}
|
|
156
|
+
|
|
153
157
|
/**
|
|
154
158
|
* Gets the Device Info object.
|
|
155
159
|
* @returns the Device Info object.
|
|
156
160
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
161
|
getDeviceInfo() {
|
|
160
162
|
return this.deviceInfo;
|
|
161
163
|
}
|
|
164
|
+
|
|
162
165
|
/**
|
|
163
166
|
* Gets the list of available Ad Zones.
|
|
164
167
|
* @returns all available ad zones.
|
|
165
168
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
169
|
getAdZones() {
|
|
169
170
|
return this.adZones;
|
|
170
171
|
}
|
|
172
|
+
|
|
171
173
|
/**
|
|
172
174
|
* @inheritDoc
|
|
173
175
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
176
|
constructor() {
|
|
177
177
|
_defineProperty(this, "appId", "");
|
|
178
|
-
|
|
179
178
|
_defineProperty(this, "apiEnv", void 0);
|
|
180
|
-
|
|
181
179
|
_defineProperty(this, "listManagerApiEnv", void 0);
|
|
182
|
-
|
|
183
180
|
_defineProperty(this, "payloadApiEnv", void 0);
|
|
184
|
-
|
|
185
181
|
_defineProperty(this, "deviceOs", void 0);
|
|
186
|
-
|
|
187
182
|
_defineProperty(this, "sessionId", void 0);
|
|
188
|
-
|
|
189
183
|
_defineProperty(this, "deviceInfo", void 0);
|
|
190
|
-
|
|
191
184
|
_defineProperty(this, "sessionInfo", void 0);
|
|
192
|
-
|
|
193
185
|
_defineProperty(this, "adZones", void 0);
|
|
194
|
-
|
|
195
186
|
_defineProperty(this, "xyAdZoneDragDistanceAllowed", void 0);
|
|
196
|
-
|
|
197
187
|
_defineProperty(this, "onAdZonesRefreshed", void 0);
|
|
198
|
-
|
|
199
188
|
_defineProperty(this, "refreshAdZonesTimer", void 0);
|
|
200
|
-
|
|
201
189
|
_defineProperty(this, "keywordInterceptSearchValue", void 0);
|
|
202
|
-
|
|
203
190
|
_defineProperty(this, "keywordIntercepts", void 0);
|
|
204
|
-
|
|
205
191
|
_defineProperty(this, "onAddToListTriggered", void 0);
|
|
206
|
-
|
|
207
192
|
_defineProperty(this, "onOutOfAppPayloadAvailable", void 0);
|
|
208
|
-
|
|
193
|
+
_defineProperty(this, "deepLinkOnEventListener", void 0);
|
|
194
|
+
_defineProperty(this, "AppStateOnEventListener", void 0);
|
|
209
195
|
this.apiEnv = ApiEnv.Prod;
|
|
210
196
|
this.listManagerApiEnv = ListManagerApiEnv.Prod;
|
|
211
197
|
this.payloadApiEnv = PayloadApiEnv.Prod;
|
|
212
|
-
|
|
213
|
-
|
|
198
|
+
this.onAdZonesRefreshed = () => {
|
|
199
|
+
// Defaulting to empty method.
|
|
214
200
|
};
|
|
215
|
-
|
|
216
|
-
|
|
201
|
+
this.onAddToListTriggered = () => {
|
|
202
|
+
// Defaulting to empty method.
|
|
217
203
|
};
|
|
218
|
-
|
|
219
|
-
|
|
204
|
+
this.onOutOfAppPayloadAvailable = () => {
|
|
205
|
+
// Defaulting to empty method.
|
|
220
206
|
};
|
|
221
|
-
|
|
222
207
|
this.keywordInterceptSearchValue = "";
|
|
223
208
|
this.initialize = this.initialize.bind(this);
|
|
224
209
|
this.unmount = this.unmount.bind(this);
|
|
225
210
|
this.handleAppStateChange = this.handleAppStateChange.bind(this);
|
|
226
211
|
this.handleDeepLink = this.handleDeepLink.bind(this);
|
|
227
212
|
}
|
|
213
|
+
|
|
228
214
|
/**
|
|
229
215
|
* Gets the users device info.
|
|
230
216
|
* @returns a Promise of void.
|
|
231
217
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
218
|
getDeviceInformation() {
|
|
235
219
|
return new Promise(resolve => {
|
|
236
220
|
NativeModules.AdadaptedReactNativeSdk.getDeviceInfo().then(response => {
|
|
@@ -238,16 +222,14 @@ export class AdadaptedReactNativeSdk {
|
|
|
238
222
|
});
|
|
239
223
|
});
|
|
240
224
|
}
|
|
225
|
+
|
|
241
226
|
/**
|
|
242
227
|
* Creates all Ad Zone Info objects based on provided Ad Zones.
|
|
243
228
|
* @param adZones - The object of available zones.
|
|
244
229
|
* @returns the array of Ad Zone Info objects.
|
|
245
230
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
231
|
generateAdZones(adZones) {
|
|
249
232
|
const adZoneInfoList = [];
|
|
250
|
-
|
|
251
233
|
for (const adZoneId in adZones) {
|
|
252
234
|
if (Object.prototype.hasOwnProperty.call(adZones, adZoneId)) {
|
|
253
235
|
adZoneInfoList.push({
|
|
@@ -268,15 +250,13 @@ export class AdadaptedReactNativeSdk {
|
|
|
268
250
|
});
|
|
269
251
|
}
|
|
270
252
|
}
|
|
271
|
-
|
|
272
253
|
return adZoneInfoList;
|
|
273
254
|
}
|
|
255
|
+
|
|
274
256
|
/**
|
|
275
257
|
* Triggered when session data is initialized or refreshed. Creates
|
|
276
258
|
* a timer based on the session data refresh value.
|
|
277
259
|
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
260
|
onRefreshAdZones() {
|
|
281
261
|
// Get the amount of time we will wait until a refresh occurs.
|
|
282
262
|
// We are setting a minimum refresh time of 5 minutes, so if a
|
|
@@ -289,26 +269,28 @@ export class AdadaptedReactNativeSdk {
|
|
|
289
269
|
uid: this.deviceInfo.udid
|
|
290
270
|
}, this.deviceOs, this.apiEnv).then(response => {
|
|
291
271
|
this.sessionInfo = response.data;
|
|
292
|
-
this.adZones = this.generateAdZones(response.data.zones);
|
|
293
|
-
// the session data has been refreshed.
|
|
272
|
+
this.adZones = this.generateAdZones(response.data.zones);
|
|
294
273
|
|
|
295
|
-
|
|
274
|
+
// Call the user defined callback indicating
|
|
275
|
+
// the session data has been refreshed.
|
|
276
|
+
this.onAdZonesRefreshed();
|
|
296
277
|
|
|
278
|
+
// Start the timer again based on the new session data.
|
|
297
279
|
this.onRefreshAdZones();
|
|
298
280
|
}).catch(err => {
|
|
299
|
-
console.error(err);
|
|
300
|
-
// attempt to refresh the session data.
|
|
281
|
+
console.error(err);
|
|
301
282
|
|
|
283
|
+
// Start the timer again so we can make another
|
|
284
|
+
// attempt to refresh the session data.
|
|
302
285
|
this.onRefreshAdZones();
|
|
303
286
|
});
|
|
304
287
|
}, timerMs);
|
|
305
288
|
}
|
|
289
|
+
|
|
306
290
|
/**
|
|
307
291
|
* Trigger an API request to get all possible
|
|
308
292
|
* keyword intercepts for the session.
|
|
309
293
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
294
|
getKeywordIntercepts() {
|
|
313
295
|
adadaptedApiRequests.getKeywordIntercepts({
|
|
314
296
|
aid: this.appId,
|
|
@@ -319,16 +301,14 @@ export class AdadaptedReactNativeSdk {
|
|
|
319
301
|
this.performKeywordSearch("mil");
|
|
320
302
|
});
|
|
321
303
|
}
|
|
304
|
+
|
|
322
305
|
/**
|
|
323
306
|
* Gets the Keyword Intercept Term based on the provided term ID.
|
|
324
307
|
* @param termId - The term ID to get the term object for.
|
|
325
308
|
* @returns the term if it was found based on the provided term ID.
|
|
326
309
|
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
310
|
getKeywordInterceptTerm(termId) {
|
|
330
311
|
let term;
|
|
331
|
-
|
|
332
312
|
if (this.keywordIntercepts && termId) {
|
|
333
313
|
for (const termObj of this.keywordIntercepts.terms) {
|
|
334
314
|
if (termObj.term_id === termId) {
|
|
@@ -336,18 +316,17 @@ export class AdadaptedReactNativeSdk {
|
|
|
336
316
|
}
|
|
337
317
|
}
|
|
338
318
|
}
|
|
339
|
-
|
|
340
319
|
return term;
|
|
341
320
|
}
|
|
321
|
+
|
|
342
322
|
/**
|
|
343
323
|
* Gets the current unix timestamp.
|
|
344
324
|
* @returns the current unix timestamp.
|
|
345
325
|
*/
|
|
346
|
-
|
|
347
|
-
|
|
348
326
|
getCurrentUnixTimestamp() {
|
|
349
327
|
return Math.round(new Date().getTime() / 1000);
|
|
350
328
|
}
|
|
329
|
+
|
|
351
330
|
/**
|
|
352
331
|
* Gets all data needed to make a List Manager API request.
|
|
353
332
|
* @param eventSource - The event source.
|
|
@@ -356,11 +335,8 @@ export class AdadaptedReactNativeSdk {
|
|
|
356
335
|
* @param listName - The list associated to the items, if any.
|
|
357
336
|
* @returns the data required for the request.
|
|
358
337
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
338
|
getListManagerApiRequestData(eventSource, eventName, itemNames, listName) {
|
|
362
339
|
const eventList = [];
|
|
363
|
-
|
|
364
340
|
for (const itemName of itemNames) {
|
|
365
341
|
eventList.push({
|
|
366
342
|
event_source: eventSource,
|
|
@@ -372,7 +348,6 @@ export class AdadaptedReactNativeSdk {
|
|
|
372
348
|
}
|
|
373
349
|
});
|
|
374
350
|
}
|
|
375
|
-
|
|
376
351
|
return {
|
|
377
352
|
session_id: this.sessionId,
|
|
378
353
|
app_id: this.appId,
|
|
@@ -380,26 +355,22 @@ export class AdadaptedReactNativeSdk {
|
|
|
380
355
|
events: eventList
|
|
381
356
|
};
|
|
382
357
|
}
|
|
358
|
+
|
|
383
359
|
/**
|
|
384
360
|
* Takes the deep link URL and extracts out the payload items data to
|
|
385
361
|
* send to the client for adding to a user's list.
|
|
386
362
|
* @param event - The event containing URL related info.
|
|
387
363
|
*/
|
|
388
|
-
|
|
389
|
-
|
|
390
364
|
handleDeepLink(event) {
|
|
391
365
|
const searchStr = "data=";
|
|
392
366
|
const dataIndex = event["url"].indexOf(searchStr);
|
|
393
|
-
|
|
394
367
|
if (dataIndex !== -1) {
|
|
395
368
|
const encodedData = event.url.substr(dataIndex + searchStr.length);
|
|
396
369
|
const payloadData = JSON.parse(base64.decode(encodedData));
|
|
397
370
|
const payloadId = payloadData["payload_id"];
|
|
398
371
|
const itemDataList = payloadData["detailed_list_items"];
|
|
399
|
-
|
|
400
372
|
if (itemDataList && itemDataList.length > 0) {
|
|
401
373
|
const finalItemList = [];
|
|
402
|
-
|
|
403
374
|
for (const itemData of itemDataList) {
|
|
404
375
|
finalItemList.push({
|
|
405
376
|
payload_id: payloadId,
|
|
@@ -413,29 +384,27 @@ export class AdadaptedReactNativeSdk {
|
|
|
413
384
|
product_sku: itemData["product_sku"]
|
|
414
385
|
}]
|
|
415
386
|
});
|
|
416
|
-
}
|
|
417
|
-
|
|
387
|
+
}
|
|
418
388
|
|
|
389
|
+
// Send the items to the client, so they can add them to the list.
|
|
419
390
|
safeInvoke(this.onOutOfAppPayloadAvailable, finalItemList);
|
|
420
391
|
}
|
|
421
392
|
}
|
|
422
393
|
}
|
|
394
|
+
|
|
423
395
|
/**
|
|
424
396
|
* Triggered when the state of the app changes.
|
|
425
397
|
* @param state - The current state of the app.
|
|
426
398
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
399
|
handleAppStateChange(state) {
|
|
430
400
|
if (state === "active") {
|
|
431
401
|
this.getPayloadItemData();
|
|
432
402
|
}
|
|
433
403
|
}
|
|
404
|
+
|
|
434
405
|
/**
|
|
435
406
|
* Gets all available Payload server item data for the user.
|
|
436
407
|
*/
|
|
437
|
-
|
|
438
|
-
|
|
439
408
|
getPayloadItemData() {
|
|
440
409
|
adadaptedApiRequests.retrievePayloadContent({
|
|
441
410
|
app_id: this.appId,
|
|
@@ -443,7 +412,6 @@ export class AdadaptedReactNativeSdk {
|
|
|
443
412
|
udid: this.deviceInfo.udid
|
|
444
413
|
}, this.payloadApiEnv).then(response => {
|
|
445
414
|
const finalItemList = [];
|
|
446
|
-
|
|
447
415
|
for (const payload of response.data.payloads) {
|
|
448
416
|
for (const itemData of payload.detailed_list_items) {
|
|
449
417
|
finalItemList.push({
|
|
@@ -459,33 +427,34 @@ export class AdadaptedReactNativeSdk {
|
|
|
459
427
|
}]
|
|
460
428
|
});
|
|
461
429
|
}
|
|
462
|
-
}
|
|
463
|
-
|
|
430
|
+
}
|
|
464
431
|
|
|
432
|
+
// Send the items to the client, so they can add them to the list.
|
|
465
433
|
safeInvoke(this.onOutOfAppPayloadAvailable, finalItemList);
|
|
466
|
-
}).catch(() => {
|
|
434
|
+
}).catch(() => {
|
|
435
|
+
// Do nothing.
|
|
467
436
|
});
|
|
468
437
|
}
|
|
438
|
+
|
|
469
439
|
/**
|
|
470
440
|
* Initializes the session for the AdAdapted API and sets up the SDK.
|
|
471
441
|
* @param props - The props used to initialize the SDK.
|
|
472
442
|
* @returns a Promise of void.
|
|
473
443
|
*/
|
|
474
|
-
|
|
475
|
-
|
|
476
444
|
initialize(props) {
|
|
477
445
|
// Set the app ID.
|
|
478
|
-
this.appId = props.appId;
|
|
479
|
-
// If the apiEnv value is not provided, production will be used as default.
|
|
446
|
+
this.appId = props.appId;
|
|
480
447
|
|
|
448
|
+
// Set the API environment based on the provided override value.
|
|
449
|
+
// If the apiEnv value is not provided, production will be used as default.
|
|
481
450
|
if (props.apiEnv) {
|
|
482
451
|
this.apiEnv = props.apiEnv;
|
|
483
452
|
} else {
|
|
484
453
|
this.apiEnv = ApiEnv.Prod;
|
|
485
|
-
}
|
|
486
|
-
// the user provides for the props.apiEnv value.
|
|
487
|
-
|
|
454
|
+
}
|
|
488
455
|
|
|
456
|
+
// Base the List Manager API environment off what
|
|
457
|
+
// the user provides for the props.apiEnv value.
|
|
489
458
|
if (props.apiEnv) {
|
|
490
459
|
if (props.apiEnv === ApiEnv.Prod) {
|
|
491
460
|
this.listManagerApiEnv = ListManagerApiEnv.Prod;
|
|
@@ -494,44 +463,42 @@ export class AdadaptedReactNativeSdk {
|
|
|
494
463
|
}
|
|
495
464
|
} else {
|
|
496
465
|
this.listManagerApiEnv = ListManagerApiEnv.Prod;
|
|
497
|
-
}
|
|
498
|
-
|
|
466
|
+
}
|
|
499
467
|
|
|
468
|
+
// The ad zone touch drag sensitivity setting.
|
|
500
469
|
if (props.xyDragDistanceAllowed) {
|
|
501
470
|
this.xyAdZoneDragDistanceAllowed = props.xyDragDistanceAllowed;
|
|
502
|
-
}
|
|
503
|
-
// globally for use when the method needs to be triggered.
|
|
504
|
-
|
|
471
|
+
}
|
|
505
472
|
|
|
473
|
+
// If the callback for onAdZonesRefreshed was provided, set it
|
|
474
|
+
// globally for use when the method needs to be triggered.
|
|
506
475
|
if (props.onAdZonesRefreshed) {
|
|
507
476
|
this.onAdZonesRefreshed = props.onAdZonesRefreshed;
|
|
508
|
-
}
|
|
509
|
-
// globally for use when the method needs to be triggered.
|
|
510
|
-
|
|
477
|
+
}
|
|
511
478
|
|
|
479
|
+
// If the callback for onAddToListTriggered was provided, set it
|
|
480
|
+
// globally for use when the method needs to be triggered.
|
|
512
481
|
if (props.onAddToListTriggered) {
|
|
513
482
|
this.onAddToListTriggered = props.onAddToListTriggered;
|
|
514
|
-
}
|
|
515
|
-
// globally for use when the method needs to be triggered.
|
|
516
|
-
|
|
483
|
+
}
|
|
517
484
|
|
|
485
|
+
// If the callback for onOutOfAppPayloadAvailable was provided, set it
|
|
486
|
+
// globally for use when the method needs to be triggered.
|
|
518
487
|
if (props.onOutOfAppPayloadAvailable) {
|
|
519
488
|
this.onOutOfAppPayloadAvailable = props.onOutOfAppPayloadAvailable;
|
|
520
489
|
}
|
|
521
|
-
|
|
522
490
|
return new Promise((resolve, reject) => {
|
|
523
491
|
this.getDeviceInformation().then(deviceInfoObj => {
|
|
524
492
|
const deviceInfo = JSON.parse(deviceInfoObj);
|
|
525
493
|
this.deviceInfo = deviceInfo;
|
|
526
|
-
this.deviceOs = deviceInfo.systemName === "ios" ? DeviceOS.IOS : DeviceOS.ANDROID;
|
|
527
|
-
|
|
494
|
+
this.deviceOs = deviceInfo.systemName === "ios" ? DeviceOS.IOS : DeviceOS.ANDROID;
|
|
495
|
+
// Pass custom advertiserId - ios only
|
|
528
496
|
if (Platform.OS === "ios") {
|
|
529
497
|
if (!(props.advertiserId === undefined)) {
|
|
530
498
|
deviceInfo.udid = props.advertiserId;
|
|
531
499
|
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
500
|
+
}
|
|
501
|
+
// Pass device info along with API call
|
|
535
502
|
adadaptedApiRequests.initializeSession({
|
|
536
503
|
app_id: this.appId,
|
|
537
504
|
udid: deviceInfo.udid,
|
|
@@ -553,14 +520,17 @@ export class AdadaptedReactNativeSdk {
|
|
|
553
520
|
NativeModules.AdadaptedReactNativeSdk.storeCurrentSessionId(response.data.session_id);
|
|
554
521
|
this.sessionId = response.data.session_id;
|
|
555
522
|
this.sessionInfo = response.data;
|
|
556
|
-
this.adZones = this.generateAdZones(response.data.zones);
|
|
523
|
+
this.adZones = this.generateAdZones(response.data.zones);
|
|
557
524
|
|
|
558
|
-
|
|
525
|
+
// Start the session data refresh timer.
|
|
526
|
+
this.onRefreshAdZones();
|
|
527
|
+
|
|
528
|
+
// Get all possible keyword intercept values.
|
|
559
529
|
// We don't need to wait for this to complete
|
|
560
530
|
// prior to resolving initialization of the SDK.
|
|
531
|
+
this.getKeywordIntercepts();
|
|
561
532
|
|
|
562
|
-
|
|
563
|
-
|
|
533
|
+
// Intercept an initial deep link here, if needed.
|
|
564
534
|
Linking.getInitialURL().then(url => {
|
|
565
535
|
if (url) {
|
|
566
536
|
// Pass in as an object so it mimics the "url"
|
|
@@ -569,14 +539,19 @@ export class AdadaptedReactNativeSdk {
|
|
|
569
539
|
url
|
|
570
540
|
});
|
|
571
541
|
}
|
|
572
|
-
});
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// Make the initial call to the Payload data server to see if
|
|
573
545
|
// the user has any outstanding items to be added to list.
|
|
546
|
+
this.getPayloadItemData();
|
|
547
|
+
|
|
548
|
+
// Initialize an event listener to intercept deep links while the app is running.
|
|
574
549
|
|
|
575
|
-
this.
|
|
550
|
+
this.deepLinkOnEventListener = Linking.addEventListener("url", this.handleDeepLink);
|
|
576
551
|
|
|
577
|
-
|
|
552
|
+
// Initialize an event listener to intercept App state changes.
|
|
578
553
|
|
|
579
|
-
AppState.addEventListener("change", this.handleAppStateChange);
|
|
554
|
+
this.AppStateOnEventListener = AppState.addEventListener("change", this.handleAppStateChange);
|
|
580
555
|
resolve();
|
|
581
556
|
}).catch(err => {
|
|
582
557
|
reject(err);
|
|
@@ -586,19 +561,17 @@ export class AdadaptedReactNativeSdk {
|
|
|
586
561
|
});
|
|
587
562
|
});
|
|
588
563
|
}
|
|
564
|
+
|
|
589
565
|
/**
|
|
590
566
|
* Searches through available ad keywords based on provided search term.
|
|
591
567
|
* @param searchTerm - The search term used to match against
|
|
592
568
|
* available keyword intercepts.
|
|
593
569
|
* @returns all keyword intercept terms that matched the search term.
|
|
594
570
|
*/
|
|
595
|
-
|
|
596
|
-
|
|
597
571
|
performKeywordSearch(searchTerm) {
|
|
598
572
|
const finalResultListStartsWith = [];
|
|
599
573
|
const finalResultListContains = [];
|
|
600
574
|
this.keywordInterceptSearchValue = searchTerm;
|
|
601
|
-
|
|
602
575
|
if (!this.deviceInfo || !this.sessionId) {
|
|
603
576
|
console.error("AdAdapted SDK has not been initialized.");
|
|
604
577
|
} else if (!this.keywordIntercepts) {
|
|
@@ -606,8 +579,9 @@ export class AdadaptedReactNativeSdk {
|
|
|
606
579
|
} else if (searchTerm && searchTerm.trim() && searchTerm.trim().length >= this.keywordIntercepts.min_match_length) {
|
|
607
580
|
searchTerm = searchTerm.trim();
|
|
608
581
|
const finalEventsList = [];
|
|
609
|
-
const currentTs = this.getCurrentUnixTimestamp();
|
|
582
|
+
const currentTs = this.getCurrentUnixTimestamp();
|
|
610
583
|
|
|
584
|
+
// Search for matching terms.
|
|
611
585
|
for (const termObj of this.keywordIntercepts.terms) {
|
|
612
586
|
if (termObj.term.toLowerCase().startsWith(searchTerm.toLowerCase())) {
|
|
613
587
|
// If the term starts with the search term,
|
|
@@ -622,13 +596,14 @@ export class AdadaptedReactNativeSdk {
|
|
|
622
596
|
created_at: currentTs
|
|
623
597
|
});
|
|
624
598
|
}
|
|
625
|
-
}
|
|
626
|
-
|
|
599
|
+
}
|
|
627
600
|
|
|
601
|
+
// Sort the final results by priority.
|
|
628
602
|
finalResultListStartsWith.sort((a, b) => a.priority > b.priority ? 1 : -1);
|
|
629
|
-
finalResultListContains.sort((a, b) => a.priority > b.priority ? 1 : -1);
|
|
630
|
-
// we need to report the "not_matched" event.
|
|
603
|
+
finalResultListContains.sort((a, b) => a.priority > b.priority ? 1 : -1);
|
|
631
604
|
|
|
605
|
+
// If there are no events to report at this point,
|
|
606
|
+
// we need to report the "not_matched" event.
|
|
632
607
|
if (finalEventsList.length === 0) {
|
|
633
608
|
finalEventsList.push({
|
|
634
609
|
term_id: "",
|
|
@@ -638,26 +613,28 @@ export class AdadaptedReactNativeSdk {
|
|
|
638
613
|
event_type: ReportedEventType.NOT_MATCHED,
|
|
639
614
|
created_at: currentTs
|
|
640
615
|
});
|
|
641
|
-
}
|
|
642
|
-
// all terms that matched the users search.
|
|
643
|
-
|
|
616
|
+
}
|
|
644
617
|
|
|
618
|
+
// Send up the "matched" event for the keyword search for
|
|
619
|
+
// all terms that matched the users search.
|
|
645
620
|
adadaptedApiRequests.reportInterceptEvent({
|
|
646
621
|
app_id: this.appId,
|
|
647
622
|
udid: this.deviceInfo.udid,
|
|
648
623
|
session_id: this.sessionId,
|
|
649
624
|
events: finalEventsList
|
|
650
|
-
}, this.deviceOs, this.apiEnv).then(() => {
|
|
625
|
+
}, this.deviceOs, this.apiEnv).then(() => {
|
|
626
|
+
// Do nothing with the response for now...
|
|
651
627
|
});
|
|
652
|
-
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// The returned list will keep all terms found by matching the
|
|
653
631
|
// beginning of the term string at the beginning of the list. All
|
|
654
632
|
// terms found that didn't match the beginning of the string, but
|
|
655
633
|
// still contained the search term will be concatenated to the end
|
|
656
634
|
// of the list.
|
|
657
|
-
|
|
658
|
-
|
|
659
635
|
return finalResultListStartsWith.concat(finalResultListContains);
|
|
660
636
|
}
|
|
637
|
+
|
|
661
638
|
/**
|
|
662
639
|
* Client must trigger this method when a Keyword Intercept Term has
|
|
663
640
|
* been "selected" by the user.
|
|
@@ -665,11 +642,8 @@ export class AdadaptedReactNativeSdk {
|
|
|
665
642
|
* accuracy in client reports.
|
|
666
643
|
* @param termId - The term ID to trigger the event for.
|
|
667
644
|
*/
|
|
668
|
-
|
|
669
|
-
|
|
670
645
|
reportKeywordInterceptTermSelected(termId) {
|
|
671
646
|
const termObj = this.getKeywordInterceptTerm(termId);
|
|
672
|
-
|
|
673
647
|
if (!this.deviceInfo || !this.sessionId) {
|
|
674
648
|
console.error("AdAdapted SDK has not been initialized.");
|
|
675
649
|
} else if (!this.keywordIntercepts) {
|
|
@@ -689,10 +663,12 @@ export class AdadaptedReactNativeSdk {
|
|
|
689
663
|
event_type: ReportedEventType.SELECTED,
|
|
690
664
|
created_at: this.getCurrentUnixTimestamp()
|
|
691
665
|
}]
|
|
692
|
-
}, this.deviceOs, this.apiEnv).then(() => {
|
|
666
|
+
}, this.deviceOs, this.apiEnv).then(() => {
|
|
667
|
+
// Do nothing with the response for now...
|
|
693
668
|
});
|
|
694
669
|
}
|
|
695
670
|
}
|
|
671
|
+
|
|
696
672
|
/**
|
|
697
673
|
* Client must trigger this method when a Keyword Intercept Term has
|
|
698
674
|
* been "presented" to the user. All terms that satisfy a search don't
|
|
@@ -702,19 +678,14 @@ export class AdadaptedReactNativeSdk {
|
|
|
702
678
|
* accuracy in client reports.
|
|
703
679
|
* @param termIds - The term IDs list to trigger the event for.
|
|
704
680
|
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
681
|
reportKeywordInterceptTermsPresented(termIds) {
|
|
708
682
|
const termObjs = [];
|
|
709
|
-
|
|
710
683
|
for (const termId of termIds) {
|
|
711
684
|
const termObj = this.getKeywordInterceptTerm(termId);
|
|
712
|
-
|
|
713
685
|
if (termObj) {
|
|
714
686
|
termObjs.push(termObj);
|
|
715
687
|
}
|
|
716
688
|
}
|
|
717
|
-
|
|
718
689
|
if (!this.deviceInfo || !this.sessionId) {
|
|
719
690
|
console.error("AdAdapted SDK has not been initialized.");
|
|
720
691
|
} else if (!this.keywordIntercepts) {
|
|
@@ -724,7 +695,6 @@ export class AdadaptedReactNativeSdk {
|
|
|
724
695
|
} else {
|
|
725
696
|
const termEvents = [];
|
|
726
697
|
const currentTs = this.getCurrentUnixTimestamp();
|
|
727
|
-
|
|
728
698
|
for (const termObj of termObjs) {
|
|
729
699
|
termEvents.push({
|
|
730
700
|
term_id: termObj.term_id,
|
|
@@ -735,62 +705,61 @@ export class AdadaptedReactNativeSdk {
|
|
|
735
705
|
created_at: currentTs
|
|
736
706
|
});
|
|
737
707
|
}
|
|
738
|
-
|
|
739
708
|
adadaptedApiRequests.reportInterceptEvent({
|
|
740
709
|
app_id: this.appId,
|
|
741
710
|
udid: this.deviceInfo.udid,
|
|
742
711
|
session_id: this.sessionId,
|
|
743
712
|
events: termEvents
|
|
744
|
-
}, this.deviceOs, this.apiEnv).then(() => {
|
|
713
|
+
}, this.deviceOs, this.apiEnv).then(() => {
|
|
714
|
+
// Do nothing with the response for now...
|
|
745
715
|
});
|
|
746
716
|
}
|
|
747
717
|
}
|
|
718
|
+
|
|
748
719
|
/**
|
|
749
720
|
* Client must trigger this method when any items
|
|
750
721
|
* are added to a list for reports we provide to the client.
|
|
751
722
|
* @param itemNames - The items to report.
|
|
752
723
|
* @param listName - The list to associate the items with, if any.
|
|
753
724
|
*/
|
|
754
|
-
|
|
755
|
-
|
|
756
725
|
reportItemsAddedToList(itemNames, listName) {
|
|
757
726
|
const requestData = this.getListManagerApiRequestData(ListManagerEventSource.APP, ListManagerEventName.ADDED_TO_LIST, itemNames, listName);
|
|
758
|
-
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
727
|
+
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
728
|
+
// Do nothing.
|
|
759
729
|
});
|
|
760
730
|
}
|
|
731
|
+
|
|
761
732
|
/**
|
|
762
733
|
* Client must trigger this method when any items
|
|
763
734
|
* are crossed off a list for reports we provide to the client.
|
|
764
735
|
* @param itemNames - The items to report.
|
|
765
736
|
* @param listName - The list the items are associated with, if any.
|
|
766
737
|
*/
|
|
767
|
-
|
|
768
|
-
|
|
769
738
|
reportItemsCrossedOffList(itemNames, listName) {
|
|
770
739
|
const requestData = this.getListManagerApiRequestData(ListManagerEventSource.APP, ListManagerEventName.CROSSED_OFF_LIST, itemNames, listName);
|
|
771
|
-
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
740
|
+
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
741
|
+
// Do nothing.
|
|
772
742
|
});
|
|
773
743
|
}
|
|
744
|
+
|
|
774
745
|
/**
|
|
775
746
|
* Client must trigger this method when any items
|
|
776
747
|
* are deleted from a list for reports we provide to the client.
|
|
777
748
|
* @param itemNames - The items to report.
|
|
778
749
|
* @param listName - The list the items are associated with, if any.
|
|
779
750
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
782
751
|
reportItemsDeletedFromList(itemNames, listName) {
|
|
783
752
|
const requestData = this.getListManagerApiRequestData(ListManagerEventSource.APP, ListManagerEventName.DELETED_FROM_LIST, itemNames, listName);
|
|
784
|
-
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
753
|
+
adadaptedApiRequests.reportListManagerEvents(requestData, this.deviceOs, this.listManagerApiEnv).then().catch(() => {
|
|
754
|
+
// Do nothing.
|
|
785
755
|
});
|
|
786
756
|
}
|
|
757
|
+
|
|
787
758
|
/**
|
|
788
759
|
* Client must trigger this method when any items
|
|
789
760
|
* are deleted from a list for reports we provide to the client.
|
|
790
761
|
* @param payloadId - The payload ID that we want to acknowledge.
|
|
791
762
|
*/
|
|
792
|
-
|
|
793
|
-
|
|
794
763
|
markPayloadContentAcknowledged(payloadId) {
|
|
795
764
|
adadaptedApiRequests.reportPayloadContentStatus({
|
|
796
765
|
app_id: this.appId,
|
|
@@ -801,16 +770,16 @@ export class AdadaptedReactNativeSdk {
|
|
|
801
770
|
status: PayloadStatus.DELIVERED,
|
|
802
771
|
event_timestamp: this.getCurrentUnixTimestamp()
|
|
803
772
|
}]
|
|
804
|
-
}, this.payloadApiEnv).then().catch(() => {
|
|
773
|
+
}, this.payloadApiEnv).then().catch(() => {
|
|
774
|
+
// Do nothing.
|
|
805
775
|
});
|
|
806
776
|
}
|
|
777
|
+
|
|
807
778
|
/**
|
|
808
779
|
* Client must trigger this method when any items
|
|
809
780
|
* are deleted from a list for reports we provide to the client.
|
|
810
781
|
* @param payloadId - The payload ID that we want to acknowledge.
|
|
811
782
|
*/
|
|
812
|
-
|
|
813
|
-
|
|
814
783
|
markPayloadContentRejected(payloadId) {
|
|
815
784
|
adadaptedApiRequests.reportPayloadContentStatus({
|
|
816
785
|
app_id: this.appId,
|
|
@@ -821,24 +790,26 @@ export class AdadaptedReactNativeSdk {
|
|
|
821
790
|
status: PayloadStatus.REJECTED,
|
|
822
791
|
event_timestamp: this.getCurrentUnixTimestamp()
|
|
823
792
|
}]
|
|
824
|
-
}, this.payloadApiEnv).then().catch(() => {
|
|
793
|
+
}, this.payloadApiEnv).then().catch(() => {
|
|
794
|
+
// Do nothing.
|
|
825
795
|
});
|
|
826
796
|
}
|
|
797
|
+
|
|
827
798
|
/**
|
|
828
799
|
* Performs all clean up tasks for the SDK. Call this method when
|
|
829
800
|
* the component that references this SDK will "unmount", otherwise you
|
|
830
801
|
* can experience memory leaks.
|
|
831
802
|
*/
|
|
832
|
-
|
|
833
|
-
|
|
834
803
|
unmount() {
|
|
835
804
|
if (this.refreshAdZonesTimer) {
|
|
836
805
|
clearTimeout(this.refreshAdZonesTimer);
|
|
837
806
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
807
|
+
if (this.deepLinkOnEventListener) {
|
|
808
|
+
this.deepLinkOnEventListener.remove();
|
|
809
|
+
}
|
|
810
|
+
if (this.AppStateOnEventListener) {
|
|
811
|
+
this.AppStateOnEventListener.remove();
|
|
812
|
+
}
|
|
841
813
|
}
|
|
842
|
-
|
|
843
814
|
}
|
|
844
815
|
//# sourceMappingURL=index.js.map
|