react-native-test-adx 0.1.2 → 0.1.4
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 +355 -253
- package/lib/module/AdaxonSdk.js +51 -44
- package/lib/module/components/AdaxonProvider.js +13 -3
- package/lib/module/components/InterstitialAd.js +279 -0
- package/lib/module/config/ApiConstants.js +3 -1
- package/lib/module/config/StorageKeys.js +1 -1
- package/lib/module/core/AdaxonClient.js +2 -8
- package/lib/module/hooks/useAdaxon.js +1 -3
- package/lib/module/platform/app.js +44 -3
- package/lib/module/platform/reactNative.js +65 -70
- package/lib/module/services/device/DeviceInfoService.js +59 -10
- package/lib/module/services/event/EventBuilder.js +1 -8
- package/lib/module/services/event/EventService.js +7 -5
- package/lib/module/types/AdaxonConfig.js +1 -3
- package/lib/typescript/src/AdaxonSdk.d.ts +7 -7
- package/lib/typescript/src/components/InterstitialAd.d.ts +10 -0
- package/lib/typescript/src/config/ApiConstants.d.ts +2 -1
- package/lib/typescript/src/core/AdaxonClient.d.ts +0 -1
- package/lib/typescript/src/hooks/useAdaxon.d.ts +1 -3
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/platform/app.d.ts +2 -10
- package/lib/typescript/src/platform/reactNative.d.ts +1 -0
- package/lib/typescript/src/platform/types.d.ts +1 -0
- package/lib/typescript/src/services/device/DeviceInfoService.d.ts +11 -1
- package/lib/typescript/src/services/event/EventBuilder.d.ts +0 -5
- package/lib/typescript/src/types/AdaxonConfig.d.ts +0 -10
- package/lib/typescript/src/types/EventTypes.d.ts +0 -4
- package/package.json +1 -1
- package/lib/module/storage/AnonymousIdService.js +0 -31
- package/lib/typescript/src/storage/AnonymousIdService.d.ts +0 -11
package/README.md
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
# react-native-adaxon
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native / Expo SDK for event tracking and offer recommendations.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```text
|
|
8
|
-
Mobile app → Adaxon SDK → HTTPS → MTS tracker → Kafka → MTS API → MySQL
|
|
9
|
-
```
|
|
5
|
+
**Dependencies:** `react` and `react-native` only. The SDK does not bundle AsyncStorage, NetInfo, or other storage/network libraries.
|
|
10
6
|
|
|
11
7
|
## Install
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
**Production**
|
|
14
10
|
|
|
15
11
|
```sh
|
|
16
12
|
npm install react-native-adaxon
|
|
@@ -20,55 +16,21 @@ yarn add react-native-adaxon
|
|
|
20
16
|
npx expo install react-native-adaxon
|
|
21
17
|
```
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
import { AdaxonProvider, useAdaxon } from 'react-native-adaxon';
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Testing / staging apps
|
|
19
|
+
**Testing / staging**
|
|
28
20
|
|
|
29
21
|
```sh
|
|
30
22
|
npm install react-native-test-adx
|
|
31
23
|
```
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
import { AdaxonProvider, useAdaxon } from 'react-native-test-adx';
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Both packages expose the same API. Only the npm name differs.
|
|
38
|
-
|
|
39
|
-
`expo-secure-store` is **not** required. The SDK does not depend on it.
|
|
40
|
-
|
|
41
|
-
## Quick start (React Native)
|
|
42
|
-
|
|
43
|
-
Wrap the app in `AdaxonProvider`. Screens use `useAdaxon()`.
|
|
25
|
+
Both packages expose the same public API.
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Configuration
|
|
48
|
-
|
|
49
|
-
The SDK owns the tracker host and API paths (`/event/tracking`, `/api/mts/recommendations`, `/click/tracking`). The app only provides credentials.
|
|
50
|
-
|
|
51
|
-
| Field | Required | Default |
|
|
52
|
-
|---|---|---|
|
|
53
|
-
| `appId` | **Yes** | None. MTS app id (`adx_…`). |
|
|
54
|
-
| `sdkKey` | **Yes** | None. Sent as the `x-sdk-key` header. |
|
|
55
|
-
| `storage` | No | In-memory. Queue and anonymous id are lost on app restart. |
|
|
56
|
-
| `timeoutMs` | No | `10000` |
|
|
57
|
-
| `testMode` | No | `false` (`sdk_version` gets a `-test` suffix when true) |
|
|
58
|
-
| `externalUserId` | No | Unset |
|
|
59
|
-
|
|
60
|
-
The SDK detects the device platform and collects device/app fields automatically. Do **not** pass a tracker URL — requests go to the SDK `BASE_URL`.
|
|
27
|
+
## Quick start
|
|
61
28
|
|
|
62
29
|
```tsx
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
type RecommendationOffer,
|
|
68
|
-
} from 'react-native-adaxon';
|
|
69
|
-
import { Button, Text, View } from 'react-native';
|
|
70
|
-
|
|
71
|
-
function App() {
|
|
30
|
+
import { AdaxonProvider, useAdaxon } from 'react-native-adaxon';
|
|
31
|
+
import { Button, Text } from 'react-native';
|
|
32
|
+
|
|
33
|
+
export default function App() {
|
|
72
34
|
return (
|
|
73
35
|
<AdaxonProvider
|
|
74
36
|
configuration={{
|
|
@@ -83,286 +45,426 @@ function App() {
|
|
|
83
45
|
}
|
|
84
46
|
|
|
85
47
|
function HomeScreen() {
|
|
86
|
-
const {
|
|
87
|
-
isInitialized,
|
|
88
|
-
logEvent,
|
|
89
|
-
trackPurchase,
|
|
90
|
-
trackAddToCart,
|
|
91
|
-
loadRecommendations,
|
|
92
|
-
showOffer,
|
|
93
|
-
} = useAdaxon();
|
|
48
|
+
const { isInitialized, initializationError, logEvent } = useAdaxon();
|
|
94
49
|
|
|
95
50
|
if (!isInitialized) {
|
|
96
|
-
return <Text>Initializing
|
|
51
|
+
return <Text>{initializationError ?? 'Initializing…'}</Text>;
|
|
97
52
|
}
|
|
98
53
|
|
|
99
54
|
return (
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
logEvent('level_completed', {
|
|
105
|
-
level_number: 10,
|
|
106
|
-
coins_used: 50,
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
/>
|
|
110
|
-
<Button
|
|
111
|
-
title="Purchase"
|
|
112
|
-
onPress={() =>
|
|
113
|
-
trackPurchase({
|
|
114
|
-
order_id: 'ORD123',
|
|
115
|
-
amount: 999,
|
|
116
|
-
currency: 'INR',
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
/>
|
|
120
|
-
<Button
|
|
121
|
-
title="Add to cart"
|
|
122
|
-
onPress={() =>
|
|
123
|
-
trackAddToCart({
|
|
124
|
-
product_id: 'P123',
|
|
125
|
-
price: 499,
|
|
126
|
-
currency: 'INR',
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
/>
|
|
130
|
-
<Button
|
|
131
|
-
title="Load offers"
|
|
132
|
-
onPress={async () => {
|
|
133
|
-
const offers: RecommendationOffer[] = await loadRecommendations(
|
|
134
|
-
'recommendation_view',
|
|
135
|
-
{ placement: 'home' }
|
|
136
|
-
);
|
|
137
|
-
if (offers[0]) {
|
|
138
|
-
await showOffer(offers[0]);
|
|
139
|
-
}
|
|
140
|
-
}}
|
|
141
|
-
/>
|
|
142
|
-
</View>
|
|
55
|
+
<Button
|
|
56
|
+
title="Track event"
|
|
57
|
+
onPress={() => logEvent('level_completed', { level_number: 10 })}
|
|
58
|
+
/>
|
|
143
59
|
);
|
|
144
60
|
}
|
|
145
61
|
```
|
|
146
62
|
|
|
147
|
-
|
|
63
|
+
Tracking calls do not update React state, so `logEvent` and `track` will not re-render your app.
|
|
148
64
|
|
|
149
|
-
|
|
65
|
+
`AdaxonProvider` is required for full-screen ads (`showAd`).
|
|
150
66
|
|
|
151
|
-
|
|
67
|
+
## Configuration
|
|
152
68
|
|
|
153
|
-
|
|
154
|
-
|---|---|
|
|
155
|
-
| No `storage` | SDK uses built-in in-memory storage. Tracking works. Anonymous id and queued events are lost when the app closes. |
|
|
156
|
-
| A storage adapter | Anonymous id and queued events survive restart. |
|
|
69
|
+
Pass `configuration` to `AdaxonProvider`, or to `Adaxon.initialize()` when not using React.
|
|
157
70
|
|
|
158
|
-
|
|
71
|
+
| Field | Required | Default | Description |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| `appId` | Yes | — | Your MTS app id (`adx_…`) |
|
|
74
|
+
| `sdkKey` | Yes | — | Sent as the `x-sdk-key` header |
|
|
75
|
+
| `storage` | No | In-memory | Persists offline event queue and anonymous id |
|
|
76
|
+
| `timeoutMs` | No | `10000` | HTTP timeout in ms |
|
|
77
|
+
| `testMode` | No | `false` | Sets `sdk_version` to `{version}-test` when true |
|
|
159
78
|
|
|
160
|
-
|
|
79
|
+
Only `appId` and `sdkKey` are required. Do not pass a tracker URL — the SDK owns the host and API paths.
|
|
161
80
|
|
|
162
|
-
|
|
163
|
-
npx expo install expo-secure-store
|
|
164
|
-
```
|
|
81
|
+
The SDK attaches `device`, `app`, `user.anonymous_id`, and network fields automatically. Do not pass them in event calls.
|
|
165
82
|
|
|
166
|
-
|
|
167
|
-
import * as SecureStore from 'expo-secure-store';
|
|
83
|
+
### Persistent storage (optional)
|
|
168
84
|
|
|
85
|
+
By default the SDK uses in-memory storage. Offline events and the anonymous id are lost when the app closes.
|
|
86
|
+
|
|
87
|
+
Pass any object that implements `AdaxonStorageAdapter`:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
169
90
|
<AdaxonProvider
|
|
170
91
|
configuration={{
|
|
171
92
|
appId: 'adx_your_app_id',
|
|
172
93
|
sdkKey: 'your_sdk_key',
|
|
173
94
|
storage: {
|
|
174
|
-
getItem: (key) =>
|
|
175
|
-
setItem: (key, value) =>
|
|
176
|
-
removeItem: (key) =>
|
|
95
|
+
getItem: (key) => myKeyValueStore.get(key),
|
|
96
|
+
setItem: (key, value) => myKeyValueStore.set(key, value),
|
|
97
|
+
removeItem: (key) => myKeyValueStore.delete(key),
|
|
177
98
|
},
|
|
178
99
|
}}
|
|
179
100
|
>
|
|
101
|
+
{/* … */}
|
|
102
|
+
</AdaxonProvider>
|
|
180
103
|
```
|
|
181
104
|
|
|
182
|
-
|
|
105
|
+
---
|
|
183
106
|
|
|
184
|
-
|
|
107
|
+
## Public API reference
|
|
185
108
|
|
|
186
|
-
|
|
109
|
+
Everything below is exported from `react-native-adaxon` / `react-native-test-adx` via `src/index.ts`.
|
|
187
110
|
|
|
188
|
-
|
|
189
|
-
import { Adaxon } from 'react-native-adaxon';
|
|
111
|
+
**React apps:** use `AdaxonProvider` + `useAdaxon()`.
|
|
190
112
|
|
|
191
|
-
|
|
192
|
-
appId: 'adx_your_app_id',
|
|
193
|
-
sdkKey: 'your_sdk_key',
|
|
194
|
-
});
|
|
113
|
+
**Non-React apps:** use the `Adaxon` singleton (`AdaxonSdk.shared`).
|
|
195
114
|
|
|
196
|
-
|
|
115
|
+
### `AdaxonProvider`
|
|
116
|
+
|
|
117
|
+
Initializes the SDK when the app mounts and mounts the interstitial overlay for ads.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { AdaxonProvider } from 'react-native-adaxon';
|
|
121
|
+
|
|
122
|
+
<AdaxonProvider
|
|
123
|
+
configuration={{ appId: 'adx_your_app_id', sdkKey: 'your_sdk_key' }}
|
|
124
|
+
listener={{
|
|
125
|
+
onInitializationComplete: () => console.log('Adaxon ready'),
|
|
126
|
+
onInitializationFailed: (code, message) =>
|
|
127
|
+
console.warn('Adaxon init failed', code, message),
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{/* your app */}
|
|
131
|
+
</AdaxonProvider>
|
|
197
132
|
```
|
|
198
133
|
|
|
199
|
-
|
|
134
|
+
| Prop | Required | Description |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `configuration` | Yes | SDK credentials and optional settings |
|
|
137
|
+
| `listener` | No | Init success/failure callbacks |
|
|
138
|
+
| `children` | Yes | App content |
|
|
200
139
|
|
|
201
|
-
|
|
202
|
-
|---|---|
|
|
203
|
-
| `AdaxonProvider` | Starts the SDK once when the app mounts |
|
|
204
|
-
| `useAdaxon()` | Hook for screens: track, recommendations, offers |
|
|
205
|
-
| `logEvent(name, values)` | Custom or predefined event |
|
|
206
|
-
| `trackPurchase(params)` | Sends `adx_purchase` |
|
|
207
|
-
| `trackAddToCart(params)` | Sends `adx_add_to_cart` |
|
|
208
|
-
| `trackLogin(params)` | Sends `adx_login` |
|
|
209
|
-
| `trackCompleteRegistration(params)` | Sends `adx_complete_registration` |
|
|
210
|
-
| `track` / `trackBatch` | Send immediately. `trackBatch` accepts 1–100 events |
|
|
211
|
-
| `enqueueEvent(name, properties)` | Store an event locally; does not send yet |
|
|
212
|
-
| `processPendingEvents()` | Send queued events in batches of up to 100 |
|
|
213
|
-
| `loadRecommendations(eventName, properties)` | POST `/api/mts/recommendations` |
|
|
214
|
-
| `showOffer(offer)` | Opens the offer URL and tracks `offer_opened` |
|
|
215
|
-
| `setExternalUserId(id)` | Attaches `external_user_id` on later events |
|
|
216
|
-
|
|
217
|
-
Predefined names: `AdxEvent.PURCHASE`, `AdxEvent.ADD_TO_CART`, `AdxEvent.LOGIN`, `AdxEvent.COMPLETE_REGISTRATION`.
|
|
218
|
-
|
|
219
|
-
## Event queue and batch processing
|
|
220
|
-
|
|
221
|
-
`track` and `trackBatch` send immediately. Use `enqueueEvent` / `processPendingEvents` when events should wait in the local queue.
|
|
140
|
+
---
|
|
222
141
|
|
|
223
|
-
|
|
224
|
-
|
|
142
|
+
### `useAdaxon()`
|
|
143
|
+
|
|
144
|
+
Hook that returns init status and all tracking, queue, and ad methods. Must be used inside `AdaxonProvider`.
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
const adaxon = useAdaxon();
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `isInitialized`
|
|
151
|
+
|
|
152
|
+
`boolean` — `true` after the SDK initializes successfully.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
const { isInitialized } = useAdaxon();
|
|
156
|
+
|
|
157
|
+
if (!isInitialized) {
|
|
158
|
+
return <Text>Loading…</Text>;
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### `initializationError`
|
|
163
|
+
|
|
164
|
+
`string | null` — error message when initialization failed; `null` on success or while initializing.
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
const { isInitialized, initializationError } = useAdaxon();
|
|
168
|
+
|
|
169
|
+
if (!isInitialized) {
|
|
170
|
+
return <Text>{initializationError ?? 'Initializing…'}</Text>;
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### `logEvent(eventName, values?, options?)`
|
|
175
|
+
|
|
176
|
+
Track a custom event. `values` are normalized to event properties.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
const { logEvent } = useAdaxon();
|
|
180
|
+
|
|
181
|
+
await logEvent('level_completed', { level_number: 10, coins_used: 50 });
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Event names must match `^[a-zA-Z][a-zA-Z0-9_]*$` and be at most 100 characters.
|
|
185
|
+
|
|
186
|
+
#### `track(eventName, properties?, options?)`
|
|
187
|
+
|
|
188
|
+
Send one event immediately when online. When offline, the event is queued automatically.
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
const { track } = useAdaxon();
|
|
192
|
+
|
|
193
|
+
await track('button_clicked', { button_name: 'checkout' });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `trackBatch(events)`
|
|
197
|
+
|
|
198
|
+
Send 1–100 events in one request when online. When offline, events are queued automatically.
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
const { trackBatch } = useAdaxon();
|
|
202
|
+
|
|
203
|
+
await trackBatch([
|
|
204
|
+
{ eventName: 'screen_view', properties: { screen: 'home' } },
|
|
205
|
+
{ eventName: 'screen_view', properties: { screen: 'settings' } },
|
|
206
|
+
]);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### `enqueueEvent(eventName, properties?, options?)`
|
|
210
|
+
|
|
211
|
+
Store an event locally without sending it. Use `processPendingEvents()` to flush the queue.
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
const { enqueueEvent } = useAdaxon();
|
|
225
215
|
|
|
226
216
|
await enqueueEvent('level_completed', { level_number: 10 });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### `processPendingEvents()`
|
|
220
|
+
|
|
221
|
+
Flush queued events in FIFO order, up to 100 per batch. Returns a `BatchProcessResult`.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
const { processPendingEvents } = useAdaxon();
|
|
225
|
+
|
|
227
226
|
const result = await processPendingEvents();
|
|
228
227
|
// result.status: 'completed' | 'stopped' | 'already_processing'
|
|
228
|
+
// result.eventsProcessed, result.batchesSent, result.failedQueueIds
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
231
|
+
When the device is offline, `track`, `trackBatch`, and `logEvent` queue events automatically. When connectivity returns, pending events flush in the background. On startup, pending events also flush when the network is available.
|
|
232
|
+
|
|
233
|
+
#### `trackPurchase(params, options?)`
|
|
234
|
+
|
|
235
|
+
Track a purchase event (`AdxEvent.PURCHASE`). Maps `amount` → `adx_revenue`, `currency` → `adx_currency`, `product_id`/`content_id` → `adx_content_id`.
|
|
236
|
+
|
|
237
|
+
```tsx
|
|
238
|
+
const { trackPurchase } = useAdaxon();
|
|
239
|
+
|
|
240
|
+
await trackPurchase({
|
|
241
|
+
order_id: 'ORD123',
|
|
242
|
+
amount: 999,
|
|
243
|
+
currency: 'INR',
|
|
244
|
+
product_id: 'P123',
|
|
245
|
+
});
|
|
242
246
|
```
|
|
243
247
|
|
|
244
|
-
|
|
248
|
+
#### `trackAddToCart(params, options?)`
|
|
245
249
|
|
|
246
|
-
|
|
247
|
-
- Events are processed in creation order (FIFO).
|
|
248
|
-
- Each request contains at most **100** events. A queue of 250 is sent as 100 + 100 + 50.
|
|
249
|
-
- Events are removed only after the API confirms success (`success: true`). On network, HTTP, or unknown errors they stay in the queue.
|
|
250
|
-
- Only one processor runs at a time for the same app. A second `processPendingEvents()` call returns `already_processing`.
|
|
251
|
-
- Large queues are read 100 events at a time. The SDK does not load the whole queue into memory.
|
|
252
|
-
- On `Adaxon.initialize()` / `AdaxonProvider` mount, pending events start flushing in the background without blocking startup when the network is available.
|
|
253
|
-
- Pass `removeItem` on the storage adapter so successful events can be deleted. If it is omitted, the SDK writes an empty value instead.
|
|
250
|
+
Track an add-to-cart event (`AdxEvent.ADD_TO_CART`). Maps `price` → `adx_revenue`, `currency` → `adx_currency`, `product_id`/`content_id` → `adx_content_id`.
|
|
254
251
|
|
|
255
|
-
|
|
252
|
+
```tsx
|
|
253
|
+
const { trackAddToCart } = useAdaxon();
|
|
256
254
|
|
|
257
|
-
|
|
255
|
+
await trackAddToCart({
|
|
256
|
+
product_id: 'P123',
|
|
257
|
+
price: 499,
|
|
258
|
+
currency: 'INR',
|
|
259
|
+
quantity: 1,
|
|
260
|
+
});
|
|
261
|
+
```
|
|
258
262
|
|
|
259
|
-
|
|
260
|
-
- Offline: events are stored in the event queue and no API request is made.
|
|
261
|
-
- Offline → online: the batch processor is notified once and pending events are flushed. Duplicate `ONLINE` events do not start extra processors.
|
|
262
|
-
- `isNetworkAvailable()` reports the current state. `destroy()` (and Provider unmount) removes the network listener.
|
|
263
|
+
#### `trackLogin(params?, options?)`
|
|
263
264
|
|
|
264
|
-
|
|
265
|
+
Track a login event (`AdxEvent.LOGIN`).
|
|
265
266
|
|
|
266
|
-
|
|
267
|
+
```tsx
|
|
268
|
+
const { trackLogin } = useAdaxon();
|
|
267
269
|
|
|
268
|
-
|
|
270
|
+
await trackLogin({ method: 'email' });
|
|
271
|
+
```
|
|
269
272
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
273
|
+
#### `trackCompleteRegistration(params?, options?)`
|
|
274
|
+
|
|
275
|
+
Track a registration event (`AdxEvent.COMPLETE_REGISTRATION`).
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
const { trackCompleteRegistration } = useAdaxon();
|
|
279
|
+
|
|
280
|
+
await trackCompleteRegistration({ method: 'google' });
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
#### `showAd()`
|
|
284
|
+
|
|
285
|
+
Show the first eligible offer as a full-screen interstitial. Does nothing if no offer is available.
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
const { showAd } = useAdaxon();
|
|
289
|
+
|
|
290
|
+
await showAd();
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Requires `AdaxonProvider` for the interstitial overlay.
|
|
294
|
+
|
|
295
|
+
Interstitial behavior:
|
|
296
|
+
|
|
297
|
+
- A progress bar runs for about 8 seconds.
|
|
298
|
+
- The close (×) button appears after the bar completes.
|
|
299
|
+
- Tapping the creative opens `offer_url`.
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
### `Adaxon` (imperative API)
|
|
304
|
+
|
|
305
|
+
Use when React is not available. Exposes the same tracking, queue, and ad methods as `useAdaxon()`, plus lifecycle helpers.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
import { Adaxon } from 'react-native-adaxon';
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### `Adaxon.initialize(configuration, listener?)`
|
|
312
|
+
|
|
313
|
+
Initialize the SDK. Required before any other call.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
await Adaxon.initialize({
|
|
317
|
+
appId: 'adx_your_app_id',
|
|
318
|
+
sdkKey: 'your_sdk_key',
|
|
319
|
+
testMode: false,
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### `Adaxon.isInitialized()`
|
|
324
|
+
|
|
325
|
+
Returns whether the SDK has been initialized.
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
if (Adaxon.isInitialized()) {
|
|
329
|
+
await Adaxon.logEvent('app_opened');
|
|
280
330
|
}
|
|
281
331
|
```
|
|
282
332
|
|
|
283
|
-
|
|
333
|
+
#### `Adaxon.isNetworkAvailable()`
|
|
284
334
|
|
|
285
|
-
|
|
335
|
+
Returns whether the SDK considers the device online.
|
|
286
336
|
|
|
287
|
-
```
|
|
288
|
-
{
|
|
289
|
-
|
|
290
|
-
"package_name": "com.example.app",
|
|
291
|
-
"app_version": "2.4.1",
|
|
292
|
-
"sdk_version": "0.1.2"
|
|
293
|
-
}
|
|
337
|
+
```ts
|
|
338
|
+
if (Adaxon.isNetworkAvailable()) {
|
|
339
|
+
await Adaxon.processPendingEvents();
|
|
294
340
|
}
|
|
295
341
|
```
|
|
296
342
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
│ useAdaxon().logEvent(...) or enqueueEvent(...) → processPendingEvents()
|
|
304
|
-
▼
|
|
305
|
-
components/ + hooks/ + state/ React layer (init only)
|
|
306
|
-
▼
|
|
307
|
-
AdaxonSdk.ts Public methods
|
|
308
|
-
▼
|
|
309
|
-
core/AdaxonClient.ts Wires services
|
|
310
|
-
▼
|
|
311
|
-
services/ Validate, build JSON, queue, batch, HTTPS
|
|
312
|
-
▼
|
|
313
|
-
MTS tracker
|
|
343
|
+
#### `Adaxon.destroy()`
|
|
344
|
+
|
|
345
|
+
Tear down the SDK instance. `AdaxonProvider` calls this automatically on unmount.
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
Adaxon.destroy();
|
|
314
349
|
```
|
|
315
350
|
|
|
316
|
-
|
|
351
|
+
#### Tracking, queue, and ads
|
|
352
|
+
|
|
353
|
+
These methods match `useAdaxon()`:
|
|
354
|
+
|
|
355
|
+
| Method | Same as |
|
|
317
356
|
|---|---|
|
|
318
|
-
| `
|
|
319
|
-
| `
|
|
320
|
-
| `
|
|
321
|
-
| `
|
|
322
|
-
| `
|
|
323
|
-
| `
|
|
324
|
-
| `
|
|
325
|
-
| `
|
|
326
|
-
| `
|
|
327
|
-
| `
|
|
328
|
-
|
|
329
|
-
|
|
357
|
+
| `Adaxon.logEvent` | `useAdaxon().logEvent` |
|
|
358
|
+
| `Adaxon.track` | `useAdaxon().track` |
|
|
359
|
+
| `Adaxon.trackBatch` | `useAdaxon().trackBatch` |
|
|
360
|
+
| `Adaxon.enqueueEvent` | `useAdaxon().enqueueEvent` |
|
|
361
|
+
| `Adaxon.processPendingEvents` | `useAdaxon().processPendingEvents` |
|
|
362
|
+
| `Adaxon.trackPurchase` | `useAdaxon().trackPurchase` |
|
|
363
|
+
| `Adaxon.trackAddToCart` | `useAdaxon().trackAddToCart` |
|
|
364
|
+
| `Adaxon.trackLogin` | `useAdaxon().trackLogin` |
|
|
365
|
+
| `Adaxon.trackCompleteRegistration` | `useAdaxon().trackCompleteRegistration` |
|
|
366
|
+
| `Adaxon.showAd` | `useAdaxon().showAd` |
|
|
367
|
+
|
|
368
|
+
Example without React:
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
import { Adaxon } from 'react-native-adaxon';
|
|
330
372
|
|
|
331
|
-
|
|
373
|
+
await Adaxon.initialize({
|
|
374
|
+
appId: 'adx_your_app_id',
|
|
375
|
+
sdkKey: 'your_sdk_key',
|
|
376
|
+
});
|
|
332
377
|
|
|
333
|
-
|
|
334
|
-
|
|
378
|
+
await Adaxon.logEvent('level_completed', { level_number: 10 });
|
|
379
|
+
await Adaxon.trackPurchase({ order_id: 'ORD123', amount: 999, currency: 'INR' });
|
|
380
|
+
await Adaxon.showAd();
|
|
381
|
+
```
|
|
335
382
|
|
|
336
|
-
|
|
383
|
+
Prefer `AdaxonProvider` in React Native apps so init state and interstitials work correctly.
|
|
337
384
|
|
|
338
|
-
|
|
385
|
+
---
|
|
339
386
|
|
|
340
|
-
|
|
387
|
+
### Constants
|
|
341
388
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
389
|
+
#### `AdxEvent`
|
|
390
|
+
|
|
391
|
+
Predefined event name constants.
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
import { AdxEvent } from 'react-native-adaxon';
|
|
395
|
+
|
|
396
|
+
AdxEvent.PURCHASE; // 'adx_purchase'
|
|
397
|
+
AdxEvent.ADD_TO_CART; // 'adx_add_to_cart'
|
|
398
|
+
AdxEvent.LOGIN; // 'adx_login'
|
|
399
|
+
AdxEvent.COMPLETE_REGISTRATION; // 'adx_complete_registration'
|
|
350
400
|
```
|
|
351
401
|
|
|
352
|
-
|
|
402
|
+
#### `AdxParam`
|
|
353
403
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
404
|
+
Predefined property name constants used by commerce helpers.
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
import { AdxParam } from 'react-native-adaxon';
|
|
408
|
+
|
|
409
|
+
AdxParam.REVENUE; // 'adx_revenue'
|
|
410
|
+
AdxParam.CURRENCY; // 'adx_currency'
|
|
411
|
+
AdxParam.CONTENT_ID; // 'adx_content_id'
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
### Errors
|
|
417
|
+
|
|
418
|
+
Failed SDK calls throw `AdaxonSdkError` with a `code`:
|
|
419
|
+
|
|
420
|
+
| Code | Meaning |
|
|
421
|
+
|---|---|
|
|
422
|
+
| `INVALID_CONFIG` | Missing or invalid SDK configuration |
|
|
423
|
+
| `VALIDATION_ERROR` | Invalid event name, properties, or batch |
|
|
424
|
+
| `AUTHENTICATION_ERROR` | Invalid SDK key |
|
|
425
|
+
| `HTTP_ERROR` | Server returned an error |
|
|
426
|
+
| `NETWORK_ERROR` | Network request failed |
|
|
427
|
+
| `TIMEOUT` | Request timed out |
|
|
428
|
+
|
|
429
|
+
```tsx
|
|
430
|
+
import { AdaxonSdkError } from 'react-native-adaxon';
|
|
431
|
+
|
|
432
|
+
try {
|
|
433
|
+
await logEvent('invalid name!', {});
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (error instanceof AdaxonSdkError) {
|
|
436
|
+
console.warn(error.code, error.message);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
360
439
|
```
|
|
361
440
|
|
|
362
|
-
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
### Exported types
|
|
444
|
+
|
|
445
|
+
TypeScript types exported for app integration:
|
|
446
|
+
|
|
447
|
+
| Type | Use |
|
|
363
448
|
|---|---|
|
|
364
|
-
|
|
|
365
|
-
|
|
|
449
|
+
| `AdaxonStorageAdapter` | Custom persistent storage |
|
|
450
|
+
| `AdaxonSdkConfig` | SDK configuration shape |
|
|
451
|
+
| `AdaxonInitializationListener` | Init callbacks for `AdaxonProvider` / `Adaxon.initialize` |
|
|
452
|
+
| `TrackPurchaseParams` | Params for `trackPurchase` |
|
|
453
|
+
| `TrackAddToCartParams` | Params for `trackAddToCart` |
|
|
454
|
+
| `TrackLoginParams` | Params for `trackLogin` / `trackCompleteRegistration` |
|
|
455
|
+
| `EventProperties` | Event property map (`string`, `number`, `boolean`, `null`) |
|
|
456
|
+
| `TrackEventInput` | Single event in `trackBatch` |
|
|
457
|
+
| `TrackEventOptions` | Optional `eventId` / `eventTime` on track calls |
|
|
458
|
+
| `EventIngestionResponse` | Response from track calls |
|
|
459
|
+
| `BatchProcessResult` | Response from `processPendingEvents` |
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## Android
|
|
464
|
+
|
|
465
|
+
Your Adaxon credential `platform` must allow Android (`android` or `react_native`).
|
|
466
|
+
|
|
467
|
+
---
|
|
366
468
|
|
|
367
469
|
## License
|
|
368
470
|
|