react-native-test-adx 0.1.4 → 0.1.6

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.
@@ -68,22 +68,60 @@ export class AdaxonSdk {
68
68
  async trackCompleteRegistration(params = {}, options = {}) {
69
69
  return this.logEvent(AdxEvent.COMPLETE_REGISTRATION, params, options);
70
70
  }
71
- async showAd() {
71
+ async showAd(options = {}) {
72
72
  try {
73
73
  const offers = await this.loadRecommendations(RECOMMENDATION_VIEW_EVENT);
74
- const offer = offers[0];
75
- if (!offer) {
74
+ if (offers.length === 0) {
76
75
  console.warn('[Adaxon] No offer available.');
77
- return;
76
+ return {
77
+ shown: false,
78
+ reason: 'no_offer'
79
+ };
78
80
  }
79
- if (!this.displayInterstitial(offer)) {
80
- console.warn('[Adaxon] Interstitial host is not mounted. Wrap the app in AdaxonProvider.');
81
+ const excluded = new Set(options.excludeOfferIds ?? []);
82
+ const offer = offers.find(item => !excluded.has(item.offer_id));
83
+ if (!offer) {
84
+ console.warn('[Adaxon] No eligible offer available.');
85
+ return {
86
+ shown: false,
87
+ reason: 'no_eligible_offer'
88
+ };
81
89
  }
90
+ return await new Promise(resolve => {
91
+ const displayed = presentInterstitial({
92
+ offer,
93
+ interact: () => {
94
+ options.onOfferClicked?.(offer.offer_id);
95
+ this.openOfferUrl(offer).then(() => dismissInterstitial('click')).catch(error => {
96
+ console.warn('[Adaxon] Failed to open offer URL.', AdaxonSdkError.messageOf(error, 'Failed to open offer.'));
97
+ dismissInterstitial('close');
98
+ });
99
+ },
100
+ onDismiss: dismissReason => {
101
+ resolve({
102
+ shown: true,
103
+ offerId: offer.offer_id,
104
+ dismissReason
105
+ });
106
+ }
107
+ });
108
+ if (!displayed) {
109
+ console.warn('[Adaxon] Interstitial host is not mounted. Wrap the app in AdaxonProvider.');
110
+ resolve({
111
+ shown: false,
112
+ reason: 'not_mounted'
113
+ });
114
+ }
115
+ });
82
116
  } catch (error) {
83
117
  console.warn('[Adaxon] Failed to show ad.', AdaxonSdkError.messageOf(error, 'Failed to show ad.'));
84
118
  if (this.testMode) {
85
119
  throw error;
86
120
  }
121
+ return {
122
+ shown: false,
123
+ reason: 'no_offer'
124
+ };
87
125
  }
88
126
  }
89
127
  isNetworkAvailable() {
@@ -106,16 +144,6 @@ export class AdaxonSdk {
106
144
  });
107
145
  return response.offers;
108
146
  }
109
- displayInterstitial(offer) {
110
- return presentInterstitial({
111
- offer,
112
- interact: () => {
113
- this.openOfferUrl(offer).then(dismissInterstitial).catch(error => {
114
- console.warn('[Adaxon] Failed to open offer URL.', AdaxonSdkError.messageOf(error, 'Failed to open offer.'));
115
- });
116
- }
117
- });
118
- }
119
147
  async openOfferUrl(offer) {
120
148
  const client = this.requireClient();
121
149
  if (!(await reactNativeUrlOpener.canOpenURL(offer.offer_url))) {
@@ -6,15 +6,20 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
6
6
  const CLOSE_EDGE_INSET = 12;
7
7
  const CLOSE_HIT_SIZE = 44;
8
8
  let listener = null;
9
+ let activeSession = null;
9
10
  export function presentInterstitial(session) {
10
11
  if (!listener) {
11
12
  return false;
12
13
  }
14
+ activeSession = session;
13
15
  listener(session);
14
16
  return true;
15
17
  }
16
- export function dismissInterstitial() {
18
+ export function dismissInterstitial(reason = 'close') {
19
+ const ended = activeSession;
20
+ activeSession = null;
17
21
  listener?.(null);
22
+ ended?.onDismiss?.(reason);
18
23
  }
19
24
  const emptySafeAreaInsets = {
20
25
  top: 0,
@@ -66,7 +71,7 @@ export function InterstitialAd() {
66
71
  return;
67
72
  }
68
73
  const onBackPress = () => {
69
- dismissInterstitial();
74
+ dismissInterstitial('back');
70
75
  return true;
71
76
  };
72
77
  const subscription = BackHandler.addEventListener('hardwareBackPress', onBackPress);
@@ -87,7 +92,7 @@ export function InterstitialAd() {
87
92
  children: [/*#__PURE__*/_jsx(Pressable, {
88
93
  accessibilityRole: "button",
89
94
  accessibilityLabel: "Close ad",
90
- onPress: dismissInterstitial,
95
+ onPress: () => dismissInterstitial('close'),
91
96
  style: [styles.closeButton, closeAppearance.button, {
92
97
  top: CLOSE_EDGE_INSET,
93
98
  right: closeRightInset
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
 
3
- import packageJson from '../../package.json';
4
- export const SDK_VERSION = packageJson.version;
3
+ export { SDK_VERSION } from "../sdkVersion.js";
5
4
  export const MEDIATION_PROVIDER = 'mts';
6
- export const BASE_URL = 'http://localhost:3002';
5
+
6
+ //export const BASE_URL = 'http://localhost:3002';
7
+ export const BASE_URL = 'https://mts-tracking.mobupps.com';
7
8
  export const EVENT_TRACKING_PATH = '/event/tracking';
8
9
  export const RECOMMENDATIONS_PATH = '/api/mts/recommendations';
9
10
  export const CLICK_TRACKING_PATH = '/click/tracking';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ /** Keep in sync with package.json "version" (published npm packages ship lib/ only). */
4
+ export const SDK_VERSION = '0.1.6';
@@ -1,8 +1,22 @@
1
1
  import { type TrackAddToCartParams, type TrackCompleteRegistrationParams, type TrackLoginParams, type TrackPurchaseParams } from './services/event/normalizeProperties.js';
2
2
  import type { AdaxonInitializationConfiguration, AdaxonInitializationListener } from './types/AdaxonConfig.js';
3
3
  import type { EventIngestionResponse } from './types/ApiTypes.js';
4
+ import type { InterstitialDismissReason } from './components/InterstitialAd.js';
4
5
  import type { EventProperties, TrackEventInput, TrackEventOptions } from './types/EventTypes.js';
5
6
  import type { BatchProcessResult } from './types/QueuedEvent.js';
7
+ export type ShowAdFailureReason = 'no_offer' | 'no_eligible_offer' | 'not_mounted';
8
+ export type ShowAdOptions = {
9
+ excludeOfferIds?: readonly number[];
10
+ onOfferClicked?: (offerId: number) => void;
11
+ };
12
+ export type ShowAdResult = {
13
+ shown: false;
14
+ reason: ShowAdFailureReason;
15
+ } | {
16
+ shown: true;
17
+ offerId: number;
18
+ dismissReason: InterstitialDismissReason;
19
+ };
6
20
  export declare class AdaxonSdk {
7
21
  static readonly shared: AdaxonSdk;
8
22
  private client;
@@ -18,11 +32,10 @@ export declare class AdaxonSdk {
18
32
  trackAddToCart(params: TrackAddToCartParams, options?: TrackEventOptions): Promise<EventIngestionResponse>;
19
33
  trackLogin(params?: TrackLoginParams, options?: TrackEventOptions): Promise<EventIngestionResponse>;
20
34
  trackCompleteRegistration(params?: TrackCompleteRegistrationParams, options?: TrackEventOptions): Promise<EventIngestionResponse>;
21
- showAd(): Promise<void>;
35
+ showAd(options?: ShowAdOptions): Promise<ShowAdResult>;
22
36
  isNetworkAvailable(): boolean;
23
37
  destroy(): void;
24
38
  private loadRecommendations;
25
- private displayInterstitial;
26
39
  private openOfferUrl;
27
40
  private requireClient;
28
41
  }
@@ -1,10 +1,11 @@
1
1
  import type { RecommendationOffer } from '../types/ApiTypes.js';
2
- interface InterstitialAdSession {
2
+ export type InterstitialDismissReason = 'close' | 'back' | 'click';
3
+ export interface InterstitialAdSession {
3
4
  offer: RecommendationOffer;
4
5
  interact: () => void;
6
+ onDismiss?: (reason: InterstitialDismissReason) => void;
5
7
  }
6
8
  export declare function presentInterstitial(session: InterstitialAdSession): boolean;
7
- export declare function dismissInterstitial(): void;
9
+ export declare function dismissInterstitial(reason?: InterstitialDismissReason): void;
8
10
  export declare function InterstitialAd(): import("react").JSX.Element | null;
9
- export {};
10
11
  //# sourceMappingURL=InterstitialAd.d.ts.map
@@ -1,6 +1,6 @@
1
- export declare const SDK_VERSION: string;
1
+ export { SDK_VERSION } from '../sdkVersion.js';
2
2
  export declare const MEDIATION_PROVIDER = "mts";
3
- export declare const BASE_URL = "http://localhost:3002";
3
+ export declare const BASE_URL = "https://mts-tracking.mobupps.com";
4
4
  export declare const EVENT_TRACKING_PATH = "/event/tracking";
5
5
  export declare const RECOMMENDATIONS_PATH = "/api/mts/recommendations";
6
6
  export declare const CLICK_TRACKING_PATH = "/click/tracking";
@@ -12,6 +12,8 @@ export type { TrackAddToCartParams, TrackCompleteRegistrationParams, TrackLoginP
12
12
  export type { AdaxonInitializationConfiguration, AdaxonInitializationErrorCode, AdaxonInitializationListener, AdaxonSdkConfig, AdaxonStorageAdapter, } from './types/AdaxonConfig.js';
13
13
  export type { ClickAttribution, EventProperties, EventPropertyValue, AdaxonPlatform, TrackEventInput, TrackEventOptions, } from './types/EventTypes.js';
14
14
  export type { EventIngestionResponse } from './types/ApiTypes.js';
15
+ export type { InterstitialDismissReason } from './components/InterstitialAd.js';
16
+ export type { ShowAdFailureReason, ShowAdOptions, ShowAdResult, } from './AdaxonSdk.js';
15
17
  export type { BatchProcessResult } from './types/QueuedEvent.js';
16
18
  export type { AppInfoReader, DeviceInfoReader } from './platform/types.js';
17
19
  export declare const Adaxon: AdaxonSdk;
@@ -0,0 +1,3 @@
1
+ /** Keep in sync with package.json "version" (published npm packages ship lib/ only). */
2
+ export declare const SDK_VERSION = "0.1.6";
3
+ //# sourceMappingURL=sdkVersion.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-test-adx",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Adaxon React Native / Expo SDK for event tracking and offer recommendations.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",