@adadapted/react-native-sdk 3.4.0 → 3.5.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/lib/commonjs/api/adadaptedApiRequests.js +9 -9
- package/lib/commonjs/api/adadaptedApiRequests.js.map +1 -1
- package/lib/commonjs/api/adadaptedApiTypes.js.map +1 -1
- package/lib/commonjs/componentTypes/AdZone.js +11 -0
- package/lib/commonjs/componentTypes/AdZone.js.map +1 -0
- package/lib/commonjs/componentTypes/Device.js +22 -0
- package/lib/commonjs/componentTypes/Device.js.map +1 -0
- package/lib/commonjs/componentTypes/Environment.js +34 -0
- package/lib/commonjs/componentTypes/Environment.js.map +1 -0
- package/lib/commonjs/components/AdZone.js +11 -15
- package/lib/commonjs/components/AdZone.js.map +1 -1
- package/lib/commonjs/index.js +96 -116
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/api/adadaptedApiRequests.js +9 -9
- package/lib/module/api/adadaptedApiRequests.js.map +1 -1
- package/lib/module/api/adadaptedApiTypes.js.map +1 -1
- package/lib/module/componentTypes/AdZone.js +7 -0
- package/lib/module/componentTypes/AdZone.js.map +1 -0
- package/lib/module/componentTypes/Device.js +18 -0
- package/lib/module/componentTypes/Device.js.map +1 -0
- package/lib/module/componentTypes/Environment.js +30 -0
- package/lib/module/componentTypes/Environment.js.map +1 -0
- package/lib/module/components/AdZone.js +11 -15
- package/lib/module/components/AdZone.js.map +1 -1
- package/lib/module/index.js +92 -122
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/api/adadaptedApiRequests.d.ts +10 -9
- package/lib/typescript/src/api/adadaptedApiRequests.d.ts.map +1 -1
- package/lib/typescript/src/api/adadaptedApiTypes.d.ts +11 -4
- package/lib/typescript/src/api/adadaptedApiTypes.d.ts.map +1 -1
- package/lib/typescript/src/componentTypes/AdZone.d.ts +95 -0
- package/lib/typescript/src/componentTypes/AdZone.d.ts.map +1 -0
- package/lib/typescript/src/componentTypes/Device.d.ts +80 -0
- package/lib/typescript/src/componentTypes/Device.d.ts.map +1 -0
- package/lib/typescript/src/componentTypes/Environment.d.ts +57 -0
- package/lib/typescript/src/componentTypes/Environment.d.ts.map +1 -0
- package/lib/typescript/src/components/AdZone.d.ts +2 -55
- package/lib/typescript/src/components/AdZone.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +38 -142
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/adadaptedApiRequests.ts +25 -24
- package/src/api/adadaptedApiTypes.ts +11 -5
- package/src/componentTypes/AdZone.ts +97 -0
- package/src/componentTypes/Device.ts +79 -0
- package/src/componentTypes/Environment.ts +58 -0
- package/src/components/AdZone.tsx +33 -111
- package/src/index.tsx +152 -250
|
@@ -3,109 +3,14 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import React, { useEffect, useState } from "react";
|
|
6
|
-
import {
|
|
7
|
-
DeviceEventEmitter,
|
|
8
|
-
Linking,
|
|
9
|
-
StyleSheet,
|
|
10
|
-
View,
|
|
11
|
-
ViewStyle,
|
|
12
|
-
} from "react-native";
|
|
6
|
+
import { DeviceEventEmitter, Linking, StyleSheet, View } from "react-native";
|
|
13
7
|
import * as adadaptedApiRequests from "../api/adadaptedApiRequests";
|
|
14
|
-
import {
|
|
15
|
-
Ad,
|
|
16
|
-
AdActionType,
|
|
17
|
-
DetailedListItem,
|
|
18
|
-
ReportedEventType,
|
|
19
|
-
Zone,
|
|
20
|
-
} from "../api/adadaptedApiTypes";
|
|
8
|
+
import { Ad, AdActionType, ReportedEventType } from "../api/adadaptedApiTypes";
|
|
21
9
|
import { WebView } from "react-native-webview";
|
|
22
|
-
import { ApiEnv, DeviceOS } from "../index";
|
|
23
10
|
import { safeInvoke } from "../util";
|
|
24
11
|
import { ReportAdButton } from "./ReportAdButton";
|
|
12
|
+
import { AdZoneTypes } from "src/componentTypes/AdZone";
|
|
25
13
|
|
|
26
|
-
/**
|
|
27
|
-
* Props interface for {@link AdZone}.
|
|
28
|
-
*/
|
|
29
|
-
interface Props {
|
|
30
|
-
/**
|
|
31
|
-
* The app ID.
|
|
32
|
-
*/
|
|
33
|
-
appId: string;
|
|
34
|
-
/**
|
|
35
|
-
* The session ID.
|
|
36
|
-
*/
|
|
37
|
-
sessionId: string;
|
|
38
|
-
/**
|
|
39
|
-
* The UDID.
|
|
40
|
-
*/
|
|
41
|
-
udid: string;
|
|
42
|
-
/**
|
|
43
|
-
* The touch sensitivity of the Ad Zone in both the X and Y directions.
|
|
44
|
-
* This is used to determine the click/press sensitivity when the
|
|
45
|
-
* Ad Zone is being touched by the user as a regular touch or while
|
|
46
|
-
* scrolling the view. If the amount of touch "drag" distance in either
|
|
47
|
-
* X or Y direction is less than this value, we will treat the action as
|
|
48
|
-
* a click/press on the Ad Zone.
|
|
49
|
-
*/
|
|
50
|
-
xyDragDistanceAllowed: number;
|
|
51
|
-
/**
|
|
52
|
-
* The device OS used for API requests.
|
|
53
|
-
*/
|
|
54
|
-
deviceOs: DeviceOS;
|
|
55
|
-
/**
|
|
56
|
-
* The API environment to use when making an API request.
|
|
57
|
-
*/
|
|
58
|
-
apiEnv: ApiEnv;
|
|
59
|
-
/**
|
|
60
|
-
* The ad zone data.
|
|
61
|
-
*/
|
|
62
|
-
adZoneData: Zone;
|
|
63
|
-
/**
|
|
64
|
-
* Callback that gets triggered when an "add to list" item/items are clicked.
|
|
65
|
-
* @param items - The array of items to "add to list".
|
|
66
|
-
*/
|
|
67
|
-
onAddToListTriggered?(items: DetailedListItem[]): void;
|
|
68
|
-
/**
|
|
69
|
-
* An ad zone that is not visible on screen for the initial render.
|
|
70
|
-
*/
|
|
71
|
-
offScreenAdZone: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Track the ad zone visibility in parent component. (for off-screen ads)
|
|
74
|
-
*/
|
|
75
|
-
isAdZoneVisible?: boolean;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Interface for tracking "touch" coordinates.
|
|
80
|
-
*/
|
|
81
|
-
interface TouchCoordinates {
|
|
82
|
-
/**
|
|
83
|
-
* The X coordinate for the touch.
|
|
84
|
-
*/
|
|
85
|
-
x: number;
|
|
86
|
-
/**
|
|
87
|
-
* The Y coordinate for the touch.
|
|
88
|
-
*/
|
|
89
|
-
y: number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Defines the style typing for the component.
|
|
94
|
-
*/
|
|
95
|
-
interface StyleDef {
|
|
96
|
-
/**
|
|
97
|
-
* Styles for the main View element.
|
|
98
|
-
*/
|
|
99
|
-
mainView: ViewStyle;
|
|
100
|
-
/**
|
|
101
|
-
* Styles for the WebView element.
|
|
102
|
-
*/
|
|
103
|
-
webView: ViewStyle;
|
|
104
|
-
/**
|
|
105
|
-
* Styles for the ReportAdButton.
|
|
106
|
-
*/
|
|
107
|
-
reportAd: ViewStyle;
|
|
108
|
-
}
|
|
109
14
|
/**
|
|
110
15
|
* Timer used for cycling through ads in the zone
|
|
111
16
|
* based on the ad "refresh time" for each ad.
|
|
@@ -117,7 +22,7 @@ let cycleAdTimer: ReturnType<typeof setTimeout> | undefined;
|
|
|
117
22
|
* @param props - properties passed to AdZone.
|
|
118
23
|
* @returns an AdZone JSX Element.
|
|
119
24
|
*/
|
|
120
|
-
export const AdZone = (props: Props): React.ReactElement => {
|
|
25
|
+
export const AdZone = (props: AdZoneTypes.Props): React.ReactElement => {
|
|
121
26
|
/**
|
|
122
27
|
* Tracks the current ad index being shown.
|
|
123
28
|
*/
|
|
@@ -127,10 +32,11 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
127
32
|
/**
|
|
128
33
|
* Tracks the coordinates when the user started touching the Ad View.
|
|
129
34
|
*/
|
|
130
|
-
const [touchStartCoords, setTouchStartCoords] =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
35
|
+
const [touchStartCoords, setTouchStartCoords] =
|
|
36
|
+
useState<AdZoneTypes.TouchCoordinates>({
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
});
|
|
134
40
|
|
|
135
41
|
/**
|
|
136
42
|
* Track ad visibility (for off-screen ads).
|
|
@@ -150,6 +56,7 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
150
56
|
return () => {
|
|
151
57
|
clearTimeout(cycleAdTimer);
|
|
152
58
|
DeviceEventEmitter.removeAllListeners("acknowledge");
|
|
59
|
+
DeviceEventEmitter.removeAllListeners("visibility-event");
|
|
153
60
|
};
|
|
154
61
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
62
|
}, []);
|
|
@@ -177,11 +84,18 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
177
84
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
85
|
}, [isAdZoneVisible]);
|
|
179
86
|
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (props.adZoneData.ads.length > 0) {
|
|
89
|
+
cycleDisplayedAd();
|
|
90
|
+
}
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
}, [props.isContextualAd]);
|
|
93
|
+
|
|
180
94
|
/**
|
|
181
95
|
* Generates all component related styles.
|
|
182
96
|
* @returns the styles needed for the component.
|
|
183
97
|
*/
|
|
184
|
-
function generateStyles(): StyleDef {
|
|
98
|
+
function generateStyles(): AdZoneTypes.StyleDef {
|
|
185
99
|
return StyleSheet.create({
|
|
186
100
|
mainView: {
|
|
187
101
|
width: "100%",
|
|
@@ -326,7 +240,7 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
326
240
|
nextAdIndex = 0;
|
|
327
241
|
}
|
|
328
242
|
|
|
329
|
-
if (!lastAd.impression_tracked && !isAdZoneVisible) {
|
|
243
|
+
if (lastAd && !lastAd.impression_tracked && !isAdZoneVisible) {
|
|
330
244
|
// Send invisible ad impression if ad was not visible before end of timer cycle.
|
|
331
245
|
triggerReportAdEvent(
|
|
332
246
|
lastAd,
|
|
@@ -334,7 +248,7 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
334
248
|
);
|
|
335
249
|
}
|
|
336
250
|
|
|
337
|
-
if (lastAd.impression_tracked) {
|
|
251
|
+
if (lastAd && lastAd.impression_tracked) {
|
|
338
252
|
// Reset ad impression tracking status.
|
|
339
253
|
lastAd.impression_tracked = false;
|
|
340
254
|
}
|
|
@@ -348,7 +262,10 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
348
262
|
function sendAdImpression(): void {
|
|
349
263
|
const ad = props.adZoneData.ads[adIndexShown];
|
|
350
264
|
|
|
351
|
-
if (
|
|
265
|
+
if (
|
|
266
|
+
ad &&
|
|
267
|
+
(ad.impression_tracked === undefined || !ad.impression_tracked)
|
|
268
|
+
) {
|
|
352
269
|
triggerReportAdEvent(ad, ReportedEventType.IMPRESSION);
|
|
353
270
|
ad.impression_tracked = true;
|
|
354
271
|
}
|
|
@@ -367,6 +284,10 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
367
284
|
automaticallyAdjustContentInsets={false}
|
|
368
285
|
style={styles.webView}
|
|
369
286
|
onTouchStart={(e) => {
|
|
287
|
+
triggerReportAdEvent(
|
|
288
|
+
props.adZoneData.ads[adIndexShown],
|
|
289
|
+
ReportedEventType.INTERACTION
|
|
290
|
+
);
|
|
370
291
|
setTouchStartCoords({
|
|
371
292
|
x: e.nativeEvent.pageX,
|
|
372
293
|
y: e.nativeEvent.pageY,
|
|
@@ -374,10 +295,11 @@ export const AdZone = (props: Props): React.ReactElement => {
|
|
|
374
295
|
}}
|
|
375
296
|
onTouchEnd={(e) => {
|
|
376
297
|
if (touchStartCoords) {
|
|
377
|
-
const touchEndCoords: TouchCoordinates =
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
298
|
+
const touchEndCoords: AdZoneTypes.TouchCoordinates =
|
|
299
|
+
{
|
|
300
|
+
x: e.nativeEvent.pageX,
|
|
301
|
+
y: e.nativeEvent.pageY,
|
|
302
|
+
};
|
|
381
303
|
|
|
382
304
|
if (
|
|
383
305
|
Math.abs(
|