apps-sdk 1.0.187 → 1.0.189

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.187",
3
+ "version": "1.0.189",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,7 @@
1
1
  import { adapty } from 'react-native-adapty';
2
2
  import * as config from '../../config';
3
3
  import {Session} from "./index";
4
+ import {createPaywallView} from "react-native-adapty/dist/ui";
4
5
 
5
6
  class Adapty {
6
7
  async initialize(apiKey = null) {
@@ -15,6 +16,7 @@ class Adapty {
15
16
  diskStorageSizeLimit: 100 * 1024 * 1024, // 100MB
16
17
  },
17
18
  });
19
+ const profile = await adapty.getProfile();
18
20
  } catch (error) {
19
21
  console.error('Error initializing Adapty:', error);
20
22
  }
@@ -22,10 +24,63 @@ class Adapty {
22
24
 
23
25
  async getPaywallForPlacement(placementID, lang) {
24
26
  try {
25
- config.DEBUG_MODE && console.log('Getting paywall for placement:', placementID, 'and language:', lang);
26
27
  return await adapty.getPaywall(placementID, lang);
27
28
  } catch (error) {
28
- console.error('Error getting paywall:', error);
29
+ return null;
30
+ }
31
+ }
32
+
33
+ async isActivated() {
34
+ try {
35
+ return await adapty.isActivated();
36
+ } catch (error) {
37
+ console.error('Error getting Adapty activation status:', error);
38
+ return false;
39
+ }
40
+ }
41
+
42
+ async createPaywallView(paywall) {
43
+ try {
44
+ return await createPaywallView(paywall);
45
+ } catch (error) {
46
+ console.error('Error creating paywall view:', error);
47
+ return null;
48
+ }
49
+ }
50
+
51
+ async showPaywall(placementID, lang, eventHandlers = {}) {
52
+ try {
53
+ const paywall = await this.getPaywallForPlacement(placementID, lang);
54
+ config.DEBUG_MODE && console.log('Getting paywall for placement:', placementID, 'and language:', lang, 'paywall:', paywall);
55
+ if (paywall) {
56
+ const paywallView = await this.createPaywallView(paywall);
57
+ paywallView.registerEventHandlers({
58
+ onCloseButtonPress: eventHandlers.onCloseButtonPress || (() => { return true; }),
59
+ onAndroidSystemBack: eventHandlers.onAndroidSystemBack || (() => { paywallView.dismiss(); return true; }),
60
+ onPurchaseCompleted: eventHandlers.onPurchaseCompleted || (() => { paywallView.dismiss(); return true; }),
61
+ onPurchaseStarted: eventHandlers.onPurchaseStarted || (() => { }),
62
+ onPurchaseFailed: eventHandlers.onPurchaseFailed || (() => { paywallView.dismiss(); return true; }),
63
+ onRestoreCompleted: eventHandlers.onRestoreCompleted || (() => { paywallView.dismiss(); return true; }),
64
+ onRestoreFailed: eventHandlers.onRestoreFailed || (() => { paywallView.dismiss(); return true; }),
65
+ onProductSelected: eventHandlers.onProductSelected || (() => { }),
66
+ onRenderingFailed: eventHandlers.onRenderingFailed || (() => { return true; }),
67
+ onLoadingProductsFailed: eventHandlers.onLoadingProductsFailed || (() => { paywallView.dismiss(); return true; }),
68
+ onUrlPress: eventHandlers.onUrlPress || (() => { return true; }),
69
+ });
70
+ await paywallView.present();
71
+ } else {
72
+ console.warn('Error showing paywall: paywall not found for placement', placementID, 'and language', lang);
73
+ }
74
+ } catch (error) {
75
+ console.error('Error showing paywall:', error);
76
+ }
77
+ }
78
+
79
+ async getProfile() {
80
+ try {
81
+ return await adapty.getProfile();
82
+ } catch (error) {
83
+ console.error('Error getting profile:', error);
29
84
  return null;
30
85
  }
31
86
  }
@@ -25,50 +25,83 @@ class MixPanel {
25
25
  }
26
26
  }
27
27
 
28
- async identifyUser(userId) {
28
+ async trackEvent(eventName, properties = {}) {
29
29
  if (!this.mixpanel) {
30
30
  console.log('Mixpanel is not initialized');
31
31
  return;
32
32
  }
33
33
 
34
34
  try {
35
- await this.mixpanel.identify(userId);
36
- this.mixpanel.getPeople().set('user_id', userId);
37
- this.mixpanel.getPeople().set('subscribed_user', Session.getIsSubscribed());
38
- this.mixpanel.getPeople().set('app_version', Constants.expoConfig.version);
39
- this.mixpanel.getPeople().set('language', Localization.getLocales()[0].languageCode || 'en');
40
- config.DEBUG_MODE && console.log(`MixPanel User identified: ${userId} with data:`, {
41
- subscribed_user: Session.getIsSubscribed(),
42
- app_version: Constants.expoConfig.version,
43
- language: Localization.getLocales()[0].languageCode || 'en'
44
- });
35
+ await this.mixpanel.track(eventName, properties);
36
+ config.DEBUG_MODE && console.log(`MixPanel Event tracked: ${eventName} with properties:`, properties);
45
37
  } catch (error) {
46
- console.error('Error identifying user:', error);
38
+ console.error('Error tracking event:', error);
47
39
  }
48
40
  }
49
41
 
50
- async trackEvent(eventName, properties = {}) {
42
+ async trackEventIfExist(eventKeyword, eventData = {}) {
43
+ if (config.EVENTS_MIXPANEL[eventKeyword]) {
44
+ this.trackEvent(eventKeyword, eventData);
45
+ } else {
46
+ console.log("Event not found in MixPanel, not sent: " + eventKeyword);
47
+ }
48
+ }
49
+
50
+ async superProperties(properties) {
51
51
  if (!this.mixpanel) {
52
52
  console.log('Mixpanel is not initialized');
53
53
  return;
54
54
  }
55
55
 
56
56
  try {
57
- await this.mixpanel.track(eventName, properties);
58
- config.DEBUG_MODE && console.log(`MixPanel Event tracked: ${eventName} with properties:`, properties);
57
+ await this.mixpanel.registerSuperProperties(properties);
58
+ config.DEBUG_MODE && console.log('MixPanel Super Properties registered:', properties);
59
59
  } catch (error) {
60
- console.error('Error tracking event:', error);
60
+ console.error('Error registering super properties:', error);
61
61
  }
62
62
  }
63
63
 
64
- async trackEventIfExist(eventKeyword, eventData = {}) {
65
- if (config.EVENTS_MIXPANEL[eventKeyword]) {
66
- this.trackEvent(eventKeyword, eventData);
67
- } else {
68
- console.log("Event not found in MixPanel, not sent: " + eventKeyword);
64
+ async superPropertiesAppend(properties) {
65
+ if (!this.mixpanel) {
66
+ console.log('Mixpanel is not initialized');
67
+ return;
68
+ }
69
+
70
+ try {
71
+ await this.mixpanel.registerSuperPropertiesOnce(properties);
72
+ config.DEBUG_MODE && console.log('MixPanel Super Properties appended:', properties);
73
+ } catch (error) {
74
+ console.error('Error appending super properties:', error);
75
+ }
76
+ }
77
+
78
+ async identifyUser(userID) {
79
+ if (!this.mixpanel) {
80
+ console.log('Mixpanel is not initialized');
81
+ return;
82
+ }
83
+
84
+ try {
85
+ await this.mixpanel.identify(userID);
86
+ config.DEBUG_MODE && console.log('MixPanel User identified:', userID);
87
+ } catch (error) {
88
+ console.error('Error identifying user:', error);
69
89
  }
70
90
  }
71
91
 
92
+ async setUserProperty(propertyName, propertyValue) {
93
+ if (!this.mixpanel) {
94
+ console.log('Mixpanel is not initialized');
95
+ return;
96
+ }
97
+
98
+ try {
99
+ await this.mixpanel.getPeople().set(propertyName, propertyValue);
100
+ config.DEBUG_MODE && console.log(`MixPanel User property set: ${propertyName} = ${propertyValue}`);
101
+ } catch (error) {
102
+ console.error('Error setting user property:', error);
103
+ }
104
+ }
72
105
 
73
106
  isMixpanelInitialized() {
74
107
  return this.mixpanel !== null;
package/types/index.d.ts CHANGED
@@ -75,7 +75,7 @@ declare module 'apps-sdk' {
75
75
  getEndpoints(): any;
76
76
  setEvents(events: any): void;
77
77
  sendEvent(eventType: string, eventKeyword:string, eventData?: object, forceSend?: boolean): Promise<void>;
78
- createSubscription(): any;
78
+ createSubscription(data: any): Promise<boolean>;
79
79
  checkConnection(): Promise<boolean>;
80
80
  setImageCompression(compression: any): void;
81
81
  addPendingEvent(event: any): void;
@@ -181,15 +181,36 @@ declare module 'apps-sdk' {
181
181
 
182
182
  export class MixPanel {
183
183
  initialize(token?: string, trackAutomaticEvents?: boolean, useNative?: boolean): Promise<void>;
184
- identifyUser(userID: string): Promise<void>;
185
184
  trackEvent(event: string, properties?: object): Promise<void>;
186
- isMixpanelInitialized(): boolean;
187
185
  trackEventIfExist(eventKeyword: string, eventData?: object): Promise<void>;
188
- }
186
+ isMixpanelInitialized(): boolean;
187
+ superProperties(properties: object): Promise<void>;
188
+ superPropertiesAppend(properties: object): Promise<void>;
189
+ identifyUser(userID: string): Promise<void>;
190
+ setUserProperty(property: string, value: any): Promise<void>;
191
+ }
192
+
193
+ type PaywallEventHandlers = {
194
+ onCloseButtonPress?: () => void;
195
+ onAndroidSystemBack?: () => void;
196
+ onPurchaseCompleted?: (purchaseResult: any, product: any) => void;
197
+ onPurchaseStarted?: (product: any) => void;
198
+ onPurchaseFailed?: (error: any) => void;
199
+ onRestoreCompleted?: (profile: any) => void;
200
+ onRestoreFailed?: (error: any, product: any) => void;
201
+ onProductSelected?: (productId: string) => void;
202
+ onRenderingFailed?: (error: any) => void;
203
+ onLoadingProductsFailed?: (error: any) => void;
204
+ onUrlPress?: (url: string) => void;
205
+ };
189
206
 
190
207
  export class Adapty {
191
208
  initialize(apiKey: string): Promise<void>;
192
209
  getPaywallForPlacement(placementID: string, lang: string): Promise<any>;
210
+ isActivated(): Promise<boolean>;
211
+ createPaywallView(paywall: any): Promise<any>;
212
+ showPaywall(placementID: any, lang: any, eventHandlers?: PaywallEventHandlers): Promise<void>;
213
+ getProfile(): Promise<any>;
193
214
  }
194
215
 
195
216
  export class TrackingTransparency {