apps-sdk 1.0.57 → 1.0.59

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
@@ -2,7 +2,8 @@ export var ENDPOINTS = {
2
2
  CONTENT: "https://backend.ailandsapp.com/content",
3
3
  PAYMENT_CARD: "https://backend.ailandsapp.com/payment-card",
4
4
  EVENTS_PUSH: "https://backend.ailandsapp.com/event/push",
5
- ATTRIBUTION_SET_ID: "https://backend.ailandsapp.com/user/set-adjust-id",
5
+ ATTRIBUTION_SET_ID: "https://backend.ailandsapp.com/user/set-attribution-data",
6
+ SET_ATTRIBUTION_DATA: "https://backend.ailandsapp.com/user/set-attribution-data",
6
7
  USER_CREATE_ID: "https://backend.ailandsapp.com/user/create-id",
7
8
  NOTIFICATION_SET_TOKEN: "https://backend.ailandsapp.com/user/notification-token",
8
9
  CONFIG: "https://backend.ailandsapp.com/core/config",
@@ -34,9 +35,15 @@ export const EVENT_TYPES = {
34
35
  }
35
36
 
36
37
  export const ADJUST = {
37
- ADJUST_TOKEN : 'y4o1gcezs6ps',
38
- ENVIRONMENT : 'SANDBOX', // or 'PRODUCTION'
39
- LOG_LEVEL : 'VERBOSE'
38
+ ADJUST_TOKEN : 'y4o1gcezs6ps',
39
+ ENVIRONMENT : 'SANDBOX', // or 'PRODUCTION'
40
+ LOG_LEVEL : 'VERBOSE',
41
+ ATTRIBUTION_DATA : {
42
+ ATTRIBUTION: {},
43
+ ADID: '',
44
+ IDFA: '',
45
+ GOOGLE_AID: '',
46
+ },
40
47
  }
41
48
 
42
49
  export var TRACKING_ACTIVE = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,19 +1,64 @@
1
1
  import { Adjust, AdjustEvent, AdjustConfig, AdjustPlayStoreSubscription, AdjustAppStoreSubscription, AdjustAttribution } from 'react-native-adjust';
2
2
  import * as config from '../../config';
3
3
  import { default as storage } from './Storage';
4
+ import Session from './Session';
4
5
  import {Platform} from "react-native";
6
+ import Networking from './Networking';
5
7
 
6
8
  class AdJust {
9
+ sdkVersion = null;
10
+ attribution = {};
7
11
  initialize() {
8
12
  const adjustEnvironment = config.ADJUST.ENVIRONMENT === 'SANDBOX' ? AdjustConfig.EnvironmentSandbox : AdjustConfig.EnvironmentProduction;
9
13
  const adjustLogLevel = config.ADJUST.LOG_LEVEL === 'VERBOSE' ? AdjustConfig.LogLevelVerbose : AdjustConfig.LogLevelSuppress;
10
14
  console.log("Initializing AdJust. Environment: " + adjustEnvironment + ", Log level: " + adjustLogLevel);
11
15
  const adjustConfig = new AdjustConfig(config.ADJUST.ADJUST_TOKEN, adjustEnvironment);
12
16
  adjustConfig.setLogLevel(adjustLogLevel);
17
+ const self = this;
13
18
  adjustConfig.setAttributionCallbackListener(function(attribution) {
14
- console.log("AdJust Attribution callback received: ", JSON.stringify(attribution));
19
+ self.attribution = attribution;
20
+ setTimeout(() => {
21
+ self.sendAttributionData(attribution);
22
+ }, 60000);
15
23
  });
16
- Adjust.create(adjustConfig);
24
+ Adjust.create(adjustConfig)
25
+ }
26
+
27
+ updateAttributionInfo() {
28
+ setTimeout(() => {
29
+ this.getAttribution();
30
+ this.getAdid();
31
+ this.getIdfa();
32
+ this.getGoogleAdId();
33
+ this.getSDKVersion();
34
+ }, 10000);
35
+ }
36
+
37
+ async getAttributionData() {
38
+ return new Promise((resolve, reject) => {
39
+ Adjust.getAttribution(attr => {
40
+ if (attr) {
41
+ resolve(attr);
42
+ } else {
43
+ reject('No attribution data');
44
+ }
45
+ });
46
+ });
47
+ }
48
+
49
+ async sendAttributionData(attribution) {
50
+ const data = {
51
+ user_id: Session.getUserID(),
52
+ adjust: {
53
+ attribution_id: Session.getAdjustAttributionID() || attribution.adid,
54
+ googleAdid: Session.getAdjustGoogleAdid(),
55
+ idfa: Session.getAdjustIDFA(),
56
+ sdkVersion: this.sdkVersion,
57
+ attribution: attribution,
58
+ }
59
+ }
60
+ console.log('sendAttributionData', data);
61
+ Networking.request(config.ENDPOINTS.SET_ATTRIBUTION_DATA, data);
17
62
  }
18
63
 
19
64
  trackEventIfExist(eventKeyword, eventValue= 0) {
@@ -63,6 +108,82 @@ class AdJust {
63
108
  isSpecialEvent(eventKeyword) {
64
109
  return config.SPECIAL_EVENTS.includes(eventKeyword);
65
110
  }
111
+
112
+ async getAttribution() {
113
+ try {
114
+ const attribution = await new Promise((resolve, reject) => {
115
+ Adjust.getAttribution((attribution) => {
116
+ if (attribution) {
117
+ resolve(attribution);
118
+ } else {
119
+ reject('Invalid Attribution');
120
+ }
121
+ });
122
+ });
123
+
124
+ Session.setAdjustAttribution(attribution);
125
+ } catch (error) {
126
+ console.error(error);
127
+ }
128
+ }
129
+
130
+ async getAdid() {
131
+ try {
132
+ const adid = await new Promise((resolve, reject) => {
133
+ Adjust.getAdid((adid) => {
134
+ if (adid) {
135
+ resolve(adid);
136
+ } else {
137
+ reject('Invalid Adid');
138
+ }
139
+ });
140
+ });
141
+
142
+ Session.setAdjustAttributionID(adid);
143
+ } catch (error) {
144
+ console.error(error);
145
+ }
146
+ }
147
+
148
+ async getGoogleAdId() {
149
+ try {
150
+ const googleAdId = await new Promise((resolve, reject) => {
151
+ Adjust.getGoogleAdId((googleAdId) => {
152
+ if (googleAdId) {
153
+ resolve(googleAdId);
154
+ } else {
155
+ reject('Invalid Google AdId');
156
+ }
157
+ });
158
+ });
159
+
160
+ Session.setAdjustGoogleAdid(googleAdId);
161
+ } catch (error) {
162
+ console.error(error);
163
+ }
164
+ }
165
+
166
+ async getIdfa() {
167
+ try {
168
+ const idfa = await new Promise((resolve, reject) => {
169
+ Adjust.getIdfa((idfa) => {
170
+ if (idfa && idfa !== '00000000-0000-0000-0000-000000000000') {
171
+ resolve(idfa);
172
+ } else {
173
+ reject('Invalid IDFA');
174
+ }
175
+ });
176
+ });
177
+ Session.setAdjustIDFA(idfa);
178
+ } catch (error) {
179
+ console.error(error);
180
+ }
181
+ }
182
+ getSDKVersion() {
183
+ Adjust.getSdkVersion((sdkVersion) => {
184
+ this.sdkVersion = sdkVersion;
185
+ });
186
+ }
66
187
  }
67
188
 
68
189
  export default new AdJust();
@@ -155,8 +155,9 @@ class Networking {
155
155
 
156
156
  setForcedUpdate = (data) => {
157
157
  const currentVersion = DeviceInfo.getVersion();
158
- const updateNeeded = (data.data.update_state === 'force' && semver.lt(currentVersion, data.release));
158
+ const updateNeeded = (data.update_state === 'force' && semver.lt(currentVersion, data.release));
159
159
  console.log('update_state: ' + data.update_state + ', currentVersion: ' + currentVersion + ', initVersion: ' + data.release + ', updateNeeded: ' + updateNeeded);
160
+ config.FORCED_UPDATE = updateNeeded;
160
161
  return updateNeeded;
161
162
  }
162
163
 
@@ -105,6 +105,7 @@ class PayWallLogic {
105
105
  ...(offerToken && {subscriptionOffers: [{sku, offerToken}]}),
106
106
  });
107
107
  subscribed = true;
108
+ Session.setIsSubscribed(true);
108
109
  if (hidePayWallCallback) {
109
110
  hidePayWallCallback();
110
111
  }
@@ -4,6 +4,7 @@ import { Platform } from 'react-native';
4
4
  import * as Localization from 'expo-localization'
5
5
  import Storage from './Storage';
6
6
  import Networking from './Networking';
7
+ import AdJust from './AdJust';
7
8
  import * as config from "../../config";
8
9
 
9
10
  class Session {
@@ -45,7 +46,9 @@ class Session {
45
46
  "domains": "0"
46
47
  },
47
48
  adjust : {
48
-
49
+ attribution_id: await Storage.getData("adjustAttributionID") || '',
50
+ idfa: await Storage.getData("adjustIDFA") || '',
51
+ googleAdid: await Storage.getData("adjustGoogleAdid") || '',
49
52
  },
50
53
  dev : false,
51
54
  lang : Localization.getLocales()[0].languageCode || 'en',
@@ -140,10 +143,41 @@ class Session {
140
143
  return this.sessionData.user_id;
141
144
  }
142
145
 
146
+ setAdjustIDFA = (idfa) => {
147
+ this.sessionData.adjust.idfa = idfa;
148
+ Storage.storeData("adjustIDFA", idfa);
149
+ }
150
+
151
+ getAdjustIDFA = () => {
152
+ return this.sessionData.adjust.idfa || Storage.getData("adjustIDFA") || '';
153
+ }
154
+
155
+ setAdjustGoogleAdid = (googleAdid) => {
156
+ this.sessionData.adjust.googleAdid = googleAdid;
157
+ Storage.storeData("adjustGoogleAdid", googleAdid);
158
+ }
159
+
160
+ getAdjustGoogleAdid = () => {
161
+ return this.sessionData.adjust.googleAdid || Storage.getData("adjustGoogleAdid") || '';
162
+ }
163
+
164
+ setAdjustAttributionID = (attribution_id) => {
165
+ this.sessionData.adjust.attribution_id = attribution_id;
166
+ Storage.storeData("adjustAttributionID", attribution_id);
167
+ }
168
+
169
+ getAdjustAttributionID = () => {
170
+ return this.sessionData.adjust.attribution_id || Storage.getData("adjustAttributionID") || '';
171
+ }
172
+
173
+ setAdjustAttribution = (attribution) => {
174
+ console.log('setAdjustAttribution', attribution);
175
+ }
176
+
143
177
  sendFirstOpen = async () => {
144
178
  config.DEBUG_MODE && console.debug("sendFirstOpen");
145
179
  try {
146
- let result = Networking.sendEvent(config.EVENT_TYPES.OTHER, 'first_open');
180
+ let result = await Networking.sendEvent(config.EVENT_TYPES.OTHER, 'first_open');
147
181
  config.DEBUG_MODE && console.debug("sendFirstOpen - result: ", result);
148
182
  } catch (error) {
149
183
  console.error(error);
@@ -154,7 +188,7 @@ class Session {
154
188
  checkSubscription = async () => {
155
189
  config.DEBUG_MODE && console.debug("checkSubscription");
156
190
  try {
157
- let result = Networking.checkSubscription();
191
+ let result = await Networking.checkSubscription();
158
192
  config.DEBUG_MODE && console.debug("checkSubscription - result: ", result);
159
193
  } catch (error) {
160
194
  console.error(error);
package/types/index.d.ts CHANGED
@@ -26,27 +26,38 @@ declare module 'apps-sdk' {
26
26
  }
27
27
 
28
28
  export class Session {
29
- sessionData: SessionData;
29
+ sessionData: any;
30
30
  sessionID: string | null;
31
31
  isFirstOpen: boolean;
32
32
  isSubscribed: boolean;
33
+ subscriptionData: any;
33
34
  isDevUser: boolean;
35
+ forcedUpdate: boolean;
34
36
  init(): Promise<void>;
35
37
  storeSessionStructure(): Promise<void>;
36
38
  checkFirstOpen(): Promise<void>;
37
- checkUserID(): Promise<void>;
38
- setSubscriptionID(subscriptionID: string): void;
39
39
  generateSessionID(): string;
40
- getSessionData(): SessionData;
40
+ checkUserID(): Promise<string | null>;
41
+ getSessionData(): any;
41
42
  getSessionID(): string | null;
42
43
  getIsFirstOpen(): boolean;
43
44
  getIsSubscribed(): boolean;
44
45
  getIsDevUser(): boolean;
45
46
  setIsSubscribed(isSubscribed: boolean): void;
47
+ setSubscriptionData(subscriptionData: any): void;
48
+ setSubscriptionID(subscriptionID: string): void;
46
49
  setIsDevUser(isDevUser: boolean): void;
47
50
  setUserID(userID: string): void;
48
51
  getUserID(): string | null;
49
- setSubscriptionData(subscriptionData: any): void;
52
+ setAdjustIDFA(idfa: string): void;
53
+ getAdjustIDFA(): string;
54
+ setAdjustGoogleAdid(googleAdid: string): void;
55
+ getAdjustGoogleAdid(): string;
56
+ setAdjustAttributionID(attributionID: string): void;
57
+ getAdjustAttributionID(): string;
58
+ setAdjustAttribution(attribution: any): void;
59
+ sendFirstOpen(): Promise<void>;
60
+ checkSubscription(): Promise<void>;
50
61
  checkSubscription24h(): Promise<void>;
51
62
  isForcedUpdate(): boolean;
52
63
  }
@@ -112,8 +123,20 @@ declare module 'apps-sdk' {
112
123
  }
113
124
 
114
125
  export class AdJust {
115
- initialize(): Promise<void>;
116
- trackEvent(eventKeyword: string, eventValue: number): void;
126
+ sdkVersion: string | null;
127
+ attribution: object;
128
+ initialize(): void;
129
+ updateAttributionInfo(): void;
130
+ getAttributionData(): Promise<any>;
131
+ sendAttributionData(attribution: any): Promise<void>;
132
+ trackEventIfExist(eventKeyword: string, eventValue?: number): void;
133
+ storeSubscription(subscriptionData: any): void;
134
+ isSpecialEvent(eventKeyword: string): boolean;
135
+ getAttribution(): Promise<void>;
136
+ getAdid(): Promise<void>;
137
+ getIdfa(): Promise<void>;
138
+ getGoogleAdId(): Promise<void>;
139
+ getSDKVersion(): void;
117
140
  }
118
141
 
119
142
  export class TrackingTransparency {