apps-sdk 1.0.45 → 1.0.47

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/config.js CHANGED
@@ -16,6 +16,8 @@ export var ENDPOINTS = {
16
16
 
17
17
  export var EVENTS = {}
18
18
 
19
+ export var SPECIAL_EVENTS = ['picture_upload', 'write_prompt', 'picture_generated', 'paywall_view']
20
+
19
21
  export var PAYWALL_DATA = {
20
22
  actions: {},
21
23
  scenes: {},
@@ -28,4 +30,10 @@ export const EVENT_TYPES = {
28
30
  OTHER: 'other'
29
31
  }
30
32
 
33
+ export const ADJUST = {
34
+ ADJUST_TOKEN : 'y4o1gcezs6ps',
35
+ ENVIRONMENT : 'SANDBOX', // or 'PRODUCTION'
36
+ LOG_LEVEL: 'VERBOSE' // or 'DEBUG', 'INFO', 'WARN', 'ERROR', 'ASSERT', 'SUPPRESS'
37
+ }
38
+
31
39
  export const DEBUG_MODE = true;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating} from "./src/libraries";
1
+ import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust} from "./src/libraries";
2
2
  import PayWall from "./src/components/PayWall";
3
3
 
4
4
  class AppsSDK {
@@ -20,5 +20,6 @@ export default {
20
20
  utils: Utils,
21
21
  rating: Rating,
22
22
  paywallLogic: PayWallLogic,
23
+ adjust: AdJust,
23
24
  paywall: PayWall,
24
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,11 +18,12 @@
18
18
  "expo-media-library": "^15.9.1",
19
19
  "expo-notifications": "^0.23.0",
20
20
  "expo-sharing": "^11.10.0",
21
+ "expo-store-review": "~6.8.3",
21
22
  "react-native": "^0.73.2",
23
+ "react-native-adjust": "^4.37.1",
22
24
  "react-native-btr": "^2.2.1",
23
25
  "react-native-iap": "^12.12.2",
24
- "react-native-webview": "^13.8.1",
25
- "expo-store-review": "~6.8.3"
26
+ "react-native-webview": "^13.8.1"
26
27
  },
27
28
  "types": "./types/index.d.ts"
28
29
  }
@@ -67,6 +67,11 @@ class PayWall extends React.Component {
67
67
  }, 3000);
68
68
  }
69
69
 
70
+ eventClickFreeSubscription = (data) => {
71
+ Networking.sendEvent('action', 'continue_free');
72
+ this.props.onClose();
73
+ }
74
+
70
75
  hideSpinner = () => {
71
76
  const event = {
72
77
  event: 'hideLoader',
@@ -0,0 +1,40 @@
1
+ import { Adjust, AdjustEvent, AdjustConfig } from 'react-native-adjust';
2
+ import * as config from '../../config';
3
+ import { default as storage } from './Storage';
4
+
5
+ class AdJust {
6
+ initialize() {
7
+ const adjustConfig = new AdjustConfig(config.ADJUST.ADJUST_TOKEN, config.ADJUST.ENVIRONMENT === 'SANDBOX' ? AdjustConfig.EnvironmentSandbox : AdjustConfig.EnvironmentProduction);
8
+ adjustConfig.setLogLevel(config.ADJUST.LOG_LEVEL === 'VERBOSE' ? AdjustConfig.LogLevelVerbose : AdjustConfig.LogLevelSuppress);
9
+ Adjust.create(adjustConfig);
10
+ }
11
+
12
+ trackEventIfExist(eventKeyword, eventValue= 0) {
13
+ let finalKeyword = eventKeyword;
14
+ if (config.EVENTS[finalKeyword]) {
15
+ if (this.isSpecialEvent(eventKeyword)) {
16
+ const finalKeyword = 'first_' + eventKeyword;
17
+ if (config.EVENTS[finalKeyword]) {
18
+ const alreadySent = storage.getData(finalKeyword);
19
+ if (!alreadySent) {
20
+ storage.storeData(finalKeyword, true);
21
+ }
22
+ }
23
+ }
24
+ const adjustEvent = new AdjustEvent(config.EVENTS[finalKeyword]);
25
+ if (eventValue > 0) {
26
+ adjustEvent.setRevenue(eventValue, 'EUR');
27
+ }
28
+ Adjust.trackEvent(adjustEvent);
29
+ console.log("Event sent to AdJust: " + eventKeyword + " with value: " + eventValue)
30
+ } else {
31
+ console.log("Event not found in AdJust, not sent: " + eventKeyword);
32
+ }
33
+ }
34
+
35
+ isSpecialEvent(eventKeyword) {
36
+ return config.SPECIAL_EVENTS[eventKeyword] ? config.SPECIAL_EVENTS[eventKeyword] : false;
37
+ }
38
+ }
39
+
40
+ export default new AdJust();
@@ -1,6 +1,7 @@
1
1
  import * as config from '../../config';
2
2
  import { default as storage } from './Storage';
3
3
  import Session from './Session';
4
+ import AdJust from './AdJust';
4
5
  import CryptoES from "crypto-es";
5
6
 
6
7
  class Networking {
@@ -17,28 +18,6 @@ class Networking {
17
18
  this.DEFAULT_ENCRYPT_VALUE = value;
18
19
  }
19
20
 
20
- async trackEvent(wid, event, user_id=null) {
21
- let data = {
22
- date : Date.now(),
23
- in_app : true,
24
- event : event
25
- };
26
-
27
- await fetch(config.ENDPOINTS.EVENTS_PUSH, {
28
- method: 'POST',
29
- headers: {
30
- Accept: 'application/json',
31
- 'Content-Type': 'application/json'
32
- },
33
- body: JSON.stringify({
34
- wid: wid,
35
- event_name: 'user_events',
36
- action: 'eventApp',
37
- data: data
38
- })
39
- });
40
- }
41
-
42
21
  async executeInit() {
43
22
  config.DEBUG_MODE && console.debug("executeInit");
44
23
  try {
@@ -202,6 +181,7 @@ class Networking {
202
181
  config.DEBUG_MODE && console.debug("eventResponse", eventResponse);
203
182
  return eventResponse;
204
183
  }
184
+ AdJust.trackEventIfExist(eventKeyword);
205
185
  return null;
206
186
  } catch (error) {
207
187
  console.error(error);
@@ -49,12 +49,19 @@ class NotificationsPush {
49
49
  }
50
50
  const { status: existingStatus } = await Notifications.getPermissionsAsync();
51
51
  if (existingStatus !== 'granted') {
52
- const status = await Notifications.requestPermissionsAsync();
52
+ const{status} = await Notifications.requestPermissionsAsync();
53
+ if (status === 'granted') {
54
+ Networking.sendEvent('action', 'allow_notifications');
55
+ }
53
56
  }
54
- token = (await Notifications.getExpoPushTokenAsync({"projectId": Constants.expoConfig.extra.eas.projectId})).data;
55
- console.log('Notification token',token);
56
- if(token) {
57
- await Networking.setToken(token);
57
+ if (existingStatus === 'granted') {
58
+ token = (await Notifications.getExpoPushTokenAsync({"projectId": Constants.expoConfig.extra.eas.projectId})).data;
59
+ console.log('Notification token',token);
60
+ if(token) {
61
+ await Networking.setToken(token);
62
+ }
63
+ } else {
64
+ console.log('Notifications permissions not granted');
58
65
  }
59
66
  } else {
60
67
  console.log('Must use physical device for Push Notifications');
@@ -91,6 +91,7 @@ class PayWallLogic {
91
91
  let subscribe = false;
92
92
  try {
93
93
  const subscriptionTemplates = await getSubscriptions({skus: [productID]});
94
+ console.log('subscriptionTemplates', subscriptionTemplates);
94
95
  if (subscriptionTemplates.length > 0) {
95
96
  const subscription = subscriptionTemplates[0];
96
97
  const sku = subscription.productId;
@@ -1,17 +1,36 @@
1
1
  import * as StoreReview from 'expo-store-review';
2
+ import Storage from './Storage';
2
3
 
4
+ const REVIEW_INTERVAL = 1000 * 60 * 60 * 24 * 3; // 3 días
3
5
  class Rating {
4
6
  showRatingDialog = async () => {
5
7
  try {
6
- if (await StoreReview.hasAction()) {
7
- if (await StoreReview.isAvailableAsync()) {
8
- return await StoreReview.requestReview();
8
+ if (await this.requestReviewIfNeeded()) {
9
+ if (await StoreReview.hasAction()) {
10
+ if (await StoreReview.isAvailableAsync()) {
11
+ return await StoreReview.requestReview();
12
+ }
9
13
  }
14
+ } else {
15
+ console.log("Rating requestReviewIfNeeded not needed");
10
16
  }
11
17
  } catch (error) {
12
18
  console.log("Error en requestReview", error);
13
19
  }
14
20
  }
21
+
22
+ requestReviewIfNeeded = async () => {
23
+ const lastReviewRequestString = await Storage.getData('lastReviewRequest');
24
+ const lastReviewRequest = lastReviewRequestString ? Number(lastReviewRequestString) : 0;
25
+ const now = Date.now();
26
+ if (now - lastReviewRequest > REVIEW_INTERVAL) {
27
+ const available = await StoreReview.isAvailableAsync();
28
+ if (available) {
29
+ await StoreReview.requestReview();
30
+ await Storage.storeData('lastReviewRequest', now.toString());
31
+ }
32
+ }
33
+ }
15
34
  }
16
35
 
17
36
  export default new Rating();
@@ -2,6 +2,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
2
2
  import * as MediaLibrary from 'expo-media-library';
3
3
  import * as FileSystem from 'expo-file-system';
4
4
  import * as Sharing from 'expo-sharing';
5
+ import Networking from "./Networking";
5
6
  import utils from "./Utils";
6
7
 
7
8
  const CREATIONS_DIR = `${FileSystem.documentDirectory}/creations`
@@ -48,10 +49,35 @@ class Storage {
48
49
  }
49
50
  }
50
51
 
52
+ async handleRequestGalleryPermission() {
53
+ try {
54
+ let galleryPermission = await this.getData('GALLERY_PERMISSION');
55
+ if (galleryPermission !== 'granted') {
56
+ const { status } = await MediaLibrary.requestPermissionsAsync();
57
+ galleryPermission = status;
58
+ if (status === 'granted') {
59
+ await this.storeData('GALLERY_PERMISSION', 'granted');
60
+ Networking.sendEvent('action', 'galery_consent');
61
+ }
62
+ }
63
+ return galleryPermission;
64
+ } catch (error) {
65
+ console.error('Error al solicitar permiso de galería:', error);
66
+ }
67
+ }
68
+
51
69
  async handleDownloadImage(base64, fileName) {
52
70
  try {
53
- const { status } = await MediaLibrary.requestPermissionsAsync();
54
- if (status === 'granted') {
71
+ let galleryPermission = await this.getData('GALLERY_PERMISSION');
72
+ if (galleryPermission !== 'granted') {
73
+ const { status } = await MediaLibrary.requestPermissionsAsync();
74
+ galleryPermission = status;
75
+ if (status === 'granted') {
76
+ await this.storeData('GALLERY_PERMISSION', 'granted');
77
+ Networking.sendEvent('action', 'galery_consent');
78
+ }
79
+ }
80
+ if (galleryPermission === 'granted') {
55
81
  let fileUri = FileSystem.documentDirectory + fileName + '.jpg';
56
82
  if (utils.isBase64Image(base64)) {
57
83
  console.log('DOWNLOADIMAGE isBase64Image');
@@ -4,4 +4,5 @@ export { default as Storage } from './Storage';
4
4
  export { default as Session } from './Session';
5
5
  export { default as Utils } from './Utils';
6
6
  export { default as Rating } from './Rating';
7
+ export { default as AdJust } from './AdJust';
7
8
  export { default as PayWallLogic } from './PayWallLogic';
package/types/index.d.ts CHANGED
@@ -51,7 +51,6 @@ declare module 'apps-sdk' {
51
51
  export class Networking {
52
52
  setEncryptKey(key: string): void;
53
53
  setDefaultEncryptValue(value: boolean): void;
54
- trackEvent(wid: string, event: string, user_id?: string | null): Promise<void>;
55
54
  executeInit(): Promise<void>;
56
55
  setToken(token: string): Promise<boolean | null>;
57
56
  request(url: string, data?: any): Promise<any>;
@@ -75,6 +74,7 @@ declare module 'apps-sdk' {
75
74
  deleteCreation(dirName: string): Promise<void>;
76
75
  deleteAllCreations(): Promise<void>;
77
76
  handleDownloadImageToGallery(imageURI: string): Promise<void>;
77
+ handleRequestGalleryPermission(): Promise<string>;
78
78
  }
79
79
 
80
80
  export class Utils {
@@ -105,6 +105,10 @@ declare module 'apps-sdk' {
105
105
  executePurchase(productID: string): Promise<void>;
106
106
  }
107
107
 
108
+ export class AdJust {
109
+ trackEvent(eventKeyword: string, eventValue: number): void;
110
+ }
111
+
108
112
  export class AppsSDK {
109
113
  initializePushNotifications(): Promise<string>;
110
114
  }
@@ -116,6 +120,8 @@ declare module 'apps-sdk' {
116
120
  session: Session;
117
121
  utils: Utils;
118
122
  paywall: PayWall;
123
+ rating: Rating;
124
+ adjust: AdJust;
119
125
  paywallLogic: PayWallLogic;
120
126
  }
121
127