apps-sdk 1.1.67 → 1.1.69

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/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Legal} from "./src/libraries";
2
2
  import PayWall from "./src/components/PayWall";
3
+ import AdaptyOnboarding from "./src/components/AdaptyOnboarding";
3
4
 
4
5
  class AppsSDK {
5
6
  constructor() {
@@ -56,10 +57,11 @@ export default {
56
57
  mixpanel: MixPanel,
57
58
  tracking: TrackingTransparency,
58
59
  paywall: PayWall,
60
+ adaptyOnboarding: AdaptyOnboarding,
59
61
  notifications: NotificationsPush,
60
62
  voice: Voice,
61
63
  adapty: Adapty,
62
64
  homeActions: HomeActions,
63
65
  facebook: Facebook,
64
66
  legal: Legal,
65
- }
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.1.67",
3
+ "version": "1.1.69",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,208 @@
1
+ import React from 'react';
2
+ import { Modal } from 'react-native';
3
+ import { AdaptyOnboardingView } from 'react-native-adapty/dist/ui';
4
+ import { View } from "react-native";
5
+ import Adapty from '../libraries/Adapty';
6
+ import * as config from '../../config';
7
+
8
+ class AdaptyOnboarding extends React.Component {
9
+ constructor(props) {
10
+ super(props);
11
+ this.state = {
12
+ onboarding: null,
13
+ isLoading: true,
14
+ };
15
+ this.remoteConfig = null;
16
+ this.currentStep = 0;
17
+ this.totalSteps = 0;
18
+ }
19
+
20
+ componentDidMount() {
21
+ const { placementID, lang } = this.props;
22
+ this.loadOnboarding(placementID, lang);
23
+ }
24
+
25
+ async componentDidUpdate(prevProps) {
26
+ if (this.props.visible && !prevProps.visible) {
27
+ const { placementID, lang } = this.props;
28
+ await this.loadOnboarding(placementID, lang);
29
+ }
30
+ }
31
+
32
+ loadOnboarding = async (placementID, lang) => {
33
+ try {
34
+ this.setState({ isLoading: true });
35
+ const onboarding = await Adapty.getOnboardingForPlacement(placementID, lang);
36
+
37
+ if (onboarding) {
38
+ this.remoteConfig = onboarding.remoteConfig || {};
39
+
40
+ if (this.props.onRemoteConfigLoaded && this.remoteConfig) {
41
+ config.DEBUG_MODE && console.log('Remote config loaded:', this.remoteConfig);
42
+ this.props.onRemoteConfigLoaded(this.remoteConfig);
43
+ }
44
+
45
+ this.setState({ onboarding, isLoading: false });
46
+ } else {
47
+ console.log('Onboarding not found for placement:', placementID, 'and language:', lang);
48
+ this.setState({ isLoading: false });
49
+ if (this.props.onError) {
50
+ this.props.onError(new Error('Onboarding not found'), this.remoteConfig);
51
+ }
52
+ }
53
+ } catch (error) {
54
+ console.log('Error loading onboarding:', error);
55
+ this.setState({ isLoading: false });
56
+ if (this.props.onError) {
57
+ this.props.onError(error, this.remoteConfig);
58
+ }
59
+ }
60
+ }
61
+
62
+ // --------------------------------------- Event Handlers ---------------------------------------
63
+ handleCustom = (actionId, meta) => {
64
+ config.DEBUG_MODE && console.log('Onboarding custom AdaptyOnboarding:', actionId, meta);
65
+
66
+ if (this.props.onCustom) {
67
+ this.props.onCustom(actionId, meta, this.remoteConfig);
68
+ }
69
+ }
70
+
71
+ handleClose = (actionId, meta) => {
72
+ const isLastStep = this.totalSteps > 0 && this.currentStep === this.totalSteps - 1;
73
+
74
+ config.DEBUG_MODE && console.log('Onboarding close attempt AdaptyOnboarding:', {actionId, meta, currentStep: this.currentStep, totalSteps: this.totalSteps, isLastStep });
75
+
76
+ if (this.props.onClose) {
77
+ this.props.onClose(actionId, meta, this.remoteConfig);
78
+ }
79
+
80
+ return true;
81
+ }
82
+
83
+ handleModalDismiss = () => {
84
+ config.DEBUG_MODE && console.log('AdaptyOnboarding Modal fully dismissed');
85
+
86
+ // Reset state after modal is fully dismissed
87
+ this.currentStep = 0;
88
+ this.totalSteps = 0;
89
+
90
+ // Notify parent that modal is fully closed
91
+ if (this.props.onModalDismissed) {
92
+ this.props.onModalDismissed();
93
+ }
94
+ }
95
+
96
+ handleStateUpdated = (action, meta) => {
97
+ if (meta && typeof meta === 'object') {
98
+ this.currentStep = meta.screen_index ?? this.currentStep;
99
+ this.totalSteps = meta.total_screens ?? this.totalSteps;
100
+
101
+ config.DEBUG_MODE && console.log('State updated AdaptyOnboarding:', {action, meta, currentStep: this.currentStep, totalSteps: this.totalSteps});
102
+ }
103
+
104
+ if (this.props.onStateUpdated) {
105
+ this.props.onStateUpdated(action, meta, this.remoteConfig);
106
+ }
107
+ }
108
+
109
+ handleError = (error) => {
110
+ console.log('Onboarding error:', error);
111
+
112
+ // Check if it's a WebResource ORB error (common on Android)
113
+ const isORBError = error?.message?.includes('ERR_BLOCKED_BY_ORB');
114
+
115
+ if (isORBError) {
116
+ config.DEBUG_MODE && console.log('WebResource ORB error detected - non-critical, continuing');
117
+ // Don't propagate ORB errors as they don't break functionality
118
+ return false; // Continue
119
+ }
120
+
121
+ if (this.props.onError) {
122
+ this.props.onError(error, this.remoteConfig);
123
+ }
124
+ return true;
125
+ }
126
+
127
+ handleAnalytics = (event, data) => {
128
+ config.DEBUG_MODE && console.log('Onboarding analytics AdaptyOnboarding:', event, data);
129
+
130
+ if (this.props.onAnalytics) {
131
+ this.props.onAnalytics(event, data, this.remoteConfig);
132
+ }
133
+ }
134
+
135
+ handlePaywall = (actionId, meta) => {
136
+ config.DEBUG_MODE && console.log('Onboarding paywall AdaptyOnboarding:', actionId, meta);
137
+
138
+ if (this.props.onPaywall) {
139
+ this.props.onPaywall(actionId, meta, this.remoteConfig);
140
+ }
141
+ }
142
+
143
+ handleFinishedLoading = (meta) => {
144
+ config.DEBUG_MODE && console.log('Onboarding finished loading AdaptyOnboarding:', meta);
145
+
146
+ if (this.props.onFinishedLoading) {
147
+ this.props.onFinishedLoading(meta, this.remoteConfig);
148
+ }
149
+ }
150
+ // --------------------------------------- Event Handlers ---------------------------------------
151
+
152
+ render() {
153
+ const { visible } = this.props;
154
+ const { onboarding, isLoading } = this.state;
155
+
156
+ if (!visible) {
157
+ return null;
158
+ }
159
+
160
+ const content = (
161
+ <View style={styles.container}>
162
+ {!isLoading && onboarding ? (
163
+ <AdaptyOnboardingView
164
+ onboarding={onboarding}
165
+ style={styles.onboardingView}
166
+ eventHandlers={{
167
+ onAnalytics: this.handleAnalytics,
168
+ onClose: this.handleClose,
169
+ onCustom: this.handleCustom,
170
+ onPaywall: this.handlePaywall,
171
+ onStateUpdated: this.handleStateUpdated,
172
+ onFinishedLoading: this.handleFinishedLoading,
173
+ onError: this.handleError,
174
+ }}
175
+ />
176
+ ) : null}
177
+ </View>
178
+ );
179
+
180
+ return (
181
+ <Modal
182
+ visible={visible}
183
+ animationType="slide"
184
+ presentationStyle="fullScreen"
185
+ onRequestClose={() => {
186
+ config.DEBUG_MODE && console.log('Modal onRequestClose prevented');
187
+ return false;
188
+ }}
189
+ onDismiss={this.handleModalDismiss}
190
+ >
191
+ {content}
192
+ </Modal>
193
+ );
194
+ }
195
+ }
196
+
197
+ const styles = {
198
+ container: {
199
+ backgroundColor: '#000',
200
+ width: '100%',
201
+ height: '100%',
202
+ },
203
+ onboardingView: {
204
+ flex: 1,
205
+ },
206
+ }
207
+
208
+ export default AdaptyOnboarding;
@@ -59,6 +59,11 @@ class Adapty {
59
59
  config.DEBUG_MODE && console.log('Getting paywall for placement:', placementID, 'and language:', lang, 'paywall:', paywall);
60
60
  if (paywall) {
61
61
  const paywallView = await this.createPaywallView(paywall);
62
+
63
+ if (!paywallView) {
64
+ return;
65
+ }
66
+
62
67
  paywallView.registerEventHandlers({
63
68
  onCloseButtonPress: eventHandlers.onCloseButtonPress || (() => { return true; }),
64
69
  onAndroidSystemBack: eventHandlers.onAndroidSystemBack || (() => { paywallView.dismiss(); return true; }),
@@ -75,14 +80,11 @@ class Adapty {
75
80
  onCustomAction: eventHandlers.onCustomAction || (() => { }),
76
81
  });
77
82
  await paywallView.present();
78
- return paywallView;
79
83
  } else {
80
84
  console.warn('Error showing paywall: paywall not found for placement', placementID, 'and language', lang);
81
- return null;
82
85
  }
83
86
  } catch (error) {
84
87
  console.error('Error showing paywall:', error);
85
- return null;
86
88
  }
87
89
  }
88
90
 
@@ -104,9 +106,11 @@ class Adapty {
104
106
  }
105
107
  } else {
106
108
  console.warn('Error preloading paywall: paywall not found for placement', placementID, 'and language', lang);
109
+ return null;
107
110
  }
108
111
  } catch (error) {
109
112
  console.error('Error preloading paywall:', error);
113
+ return null;
110
114
  }
111
115
  }
112
116
 
@@ -295,4 +299,4 @@ class Adapty {
295
299
  }
296
300
  }
297
301
 
298
- export default new Adapty();
302
+ export default new Adapty();
@@ -146,6 +146,70 @@ class Facebook {
146
146
  getApplicationId() {
147
147
  return this.appId;
148
148
  }
149
+
150
+ async getCampaignData() {
151
+ if (!this.isInitialized) {
152
+ console.log('Facebook is not initialized');
153
+ return null;
154
+ }
155
+
156
+ try {
157
+ // Import AppLink from react-native-fbsdk-next
158
+ const { AppLink } = await import('react-native-fbsdk-next');
159
+
160
+ config.DEBUG_MODE && console.log('Fetching deferred app link data from Meta...');
161
+
162
+ // Fetch deferred app link - this returns the URL or null
163
+ const deferredAppLink = await AppLink.fetchDeferredAppLink();
164
+
165
+ if (deferredAppLink) {
166
+ config.DEBUG_MODE && console.log('Deferred app link received:', deferredAppLink);
167
+
168
+ // Parse the URL to extract campaign parameters
169
+ const campaignData = this.parseCampaignUrl(deferredAppLink);
170
+
171
+ config.DEBUG_MODE && console.log('Parsed campaign data:', campaignData);
172
+
173
+ return {
174
+ url: deferredAppLink,
175
+ ...campaignData
176
+ };
177
+ } else {
178
+ config.DEBUG_MODE && console.log('No deferred app link data available');
179
+ return null;
180
+ }
181
+ } catch (error) {
182
+ console.error('Error fetching campaign data from Meta:', error);
183
+ Networking.sendEvent('other', 'facebook_campaign_data_error', { error: error.message });
184
+ return null;
185
+ }
186
+ }
187
+
188
+
189
+ parseCampaignUrl(url) {
190
+ try {
191
+ const urlObj = new URL(url);
192
+ const params = {};
193
+
194
+ // Extract all query parameters
195
+ urlObj.searchParams.forEach((value, key) => {
196
+ params[key] = value;
197
+ });
198
+
199
+ return {
200
+ params,
201
+ host: urlObj.host,
202
+ path: urlObj.pathname,
203
+ protocol: urlObj.protocol
204
+ };
205
+ } catch (error) {
206
+ console.error('Error parsing campaign URL:', error);
207
+ return {
208
+ params: {},
209
+ raw_url: url
210
+ };
211
+ }
212
+ }
149
213
  }
150
214
 
151
- export default new Facebook();
215
+ export default new Facebook();
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare module 'apps-sdk' {
2
2
  import { Component } from 'react';
3
- import {SpeechResultsEvent} from "@react-native-voice/voice";
3
+ import { SpeechResultsEvent } from "@react-native-voice/voice";
4
4
 
5
5
  export interface SessionData {
6
6
  app: {
@@ -213,15 +213,34 @@ declare module 'apps-sdk' {
213
213
  };
214
214
 
215
215
  type OnboardingEventHandlers = {
216
- onAnalytics?: (event: any, meta: any) => void;
217
- onClose?: (actionId: string, meta: any) => Promise<boolean> | boolean;
218
- onCustom?: (actionId: string, meta: any) => void;
219
- onPaywall?: (actionId: string, meta: any) => void;
220
- onStateUpdated?: (action: any, meta: any) => void;
221
- onFinishedLoading?: (meta: any) => void;
222
- onError?: (error: any) => void;
216
+ onAnalytics?: (event: any, meta: any, remoteConfig?: any) => void;
217
+ onClose?: (actionId: string, meta: any, remoteConfig?: any) => Promise<boolean> | boolean;
218
+ onCustom?: (actionId: string, meta: any, remoteConfig?: any) => void;
219
+ onPaywall?: (actionId: string, meta: any, remoteConfig?: any) => void;
220
+ onStateUpdated?: (action: any, meta: any, remoteConfig?: any) => void;
221
+ onFinishedLoading?: (meta: any, remoteConfig?: any) => void;
222
+ onError?: (error: any, remoteConfig?: any) => void;
223
+ onRemoteConfigLoaded?: (remoteConfig: any) => void;
224
+ onModalDismissed?: () => void;
223
225
  };
224
226
 
227
+ export interface AdaptyOnboardingProps {
228
+ visible: boolean;
229
+ placementID: string;
230
+ lang: string;
231
+ onAnalytics?: (event: any, meta: any, remoteConfig?: any) => void;
232
+ onClose?: (actionId: string, meta: any, remoteConfig?: any) => Promise<boolean> | boolean;
233
+ onCustom?: (actionId: string, meta: any, remoteConfig?: any) => void;
234
+ onPaywall?: (actionId: string, meta: any, remoteConfig?: any) => void;
235
+ onStateUpdated?: (action: any, meta: any, remoteConfig?: any) => void;
236
+ onFinishedLoading?: (meta: any, remoteConfig?: any) => void;
237
+ onError?: (error: any, remoteConfig?: any) => boolean | void;
238
+ onRemoteConfigLoaded?: (remoteConfig: any) => void;
239
+ onModalDismissed?: () => void;
240
+ }
241
+
242
+ export class AdaptyOnboarding extends Component<AdaptyOnboardingProps, {}> { }
243
+
225
244
  export class Adapty {
226
245
  initialize(apiKey: string): Promise<void>;
227
246
  getPaywallForPlacement(placementID: string, lang: string): Promise<any>;
@@ -284,6 +303,7 @@ declare module 'apps-sdk' {
284
303
  session : Session;
285
304
  utils : Utils;
286
305
  paywall : PayWall;
306
+ adaptyOnboarding : typeof AdaptyOnboarding;
287
307
  rating : Rating;
288
308
  adjust : AdJust;
289
309
  mixpanel : MixPanel;
@@ -299,4 +319,4 @@ declare module 'apps-sdk' {
299
319
 
300
320
  const Core: AppsSDK;
301
321
  export default Core;
302
- }
322
+ }