gomarketme-react-native 1.0.4 → 1.0.5
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/dist/index.js +11 -471
- package/package.json +6 -17
- package/src/index.ts +16 -0
- package/tsconfig.json +4 -8
- package/.editorconfig +0 -15
- package/.gitattributes +0 -3
- package/.github/actions/setup/action.yml +0 -27
- package/.github/workflows/ci.yml +0 -157
- package/.nvmrc +0 -1
- package/.watchmanconfig +0 -1
- package/.yarn/releases/yarn-4.3.1-git.20240705.hash-35167b2.cjs +0 -894
- package/.yarnrc.yml +0 -5
- package/README.md +0 -53
- package/dist/index.d.ts +0 -29
- package/lefthook.yml +0 -35
- package/src/index.tsx +0 -256
package/.yarnrc.yml
DELETED
package/README.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<img src="https://static.gomarketme.net/assets/gmm-icon.png" alt="GoMarketMe"/>
|
|
3
|
-
<br>
|
|
4
|
-
<h1>gomarketme-react-native</h1>
|
|
5
|
-
<p>Affiliate Marketing for React Native-Based iOS and Android Apps.</p>
|
|
6
|
-
</div>
|
|
7
|
-
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
### Using npm
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm install gomarketme-react-native
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Using yarn
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
yarn add gomarketme-react-native
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Using pnpm
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
pnpm add gomarketme-react-native
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
|
|
31
|
-
To initialize GoMarketMe, import the `gomarketme` package and create a new instance of `GoMarketMe`:
|
|
32
|
-
|
|
33
|
-
```tsx
|
|
34
|
-
import GoMarketMe from 'gomarketme-react-native';
|
|
35
|
-
|
|
36
|
-
const App: React.FC = () => {
|
|
37
|
-
const apiKey = 'YOUR_API_KEY_HERE';
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
const initializeGoMarketMe = async () => {
|
|
41
|
-
await GoMarketMe.initialize(apiKey);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
initializeGoMarketMe();
|
|
45
|
-
}, []);
|
|
46
|
-
};
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Make sure to replace API_KEY with your actual GoMarketMe API key. You can find it on the product onboarding page and under Profile > API Key.
|
|
50
|
-
|
|
51
|
-
## Support
|
|
52
|
-
|
|
53
|
-
If you encounter any problems or issues, please contact us at [integrations@gomarketme.co](mailto:integrations@gomarketme.co) or visit [https://gomarketme.co](https://gomarketme.co).
|
package/dist/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare class GoMarketMe {
|
|
2
|
-
private static instance;
|
|
3
|
-
private sdkInitializedKey;
|
|
4
|
-
private affiliateCampaignCode;
|
|
5
|
-
private deviceId;
|
|
6
|
-
private sdkInitializationUrl;
|
|
7
|
-
private systemInfoUrl;
|
|
8
|
-
private eventUrl;
|
|
9
|
-
private constructor();
|
|
10
|
-
static getInstance(): GoMarketMe;
|
|
11
|
-
initialize(apiKey: string): Promise<void>;
|
|
12
|
-
private addListener;
|
|
13
|
-
private getSystemInfo;
|
|
14
|
-
private postSDKInitialization;
|
|
15
|
-
private postSystemInfo;
|
|
16
|
-
private readAndroidDeviceInfo;
|
|
17
|
-
private readIosDeviceInfo;
|
|
18
|
-
private getTimeZoneCode;
|
|
19
|
-
private getLanguageCode;
|
|
20
|
-
private fetchPurchases;
|
|
21
|
-
private fetchPurchaseProducts;
|
|
22
|
-
private sendEventToServer;
|
|
23
|
-
private serializePurchaseDetails;
|
|
24
|
-
private serializeProductDetails;
|
|
25
|
-
private markSDKAsInitialized;
|
|
26
|
-
private isSDKInitialized;
|
|
27
|
-
}
|
|
28
|
-
declare const _default: GoMarketMe;
|
|
29
|
-
export default _default;
|
package/lefthook.yml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# EXAMPLE USAGE:
|
|
2
|
-
#
|
|
3
|
-
# Refer for explanation to following link:
|
|
4
|
-
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
|
|
5
|
-
#
|
|
6
|
-
# pre-push:
|
|
7
|
-
# commands:
|
|
8
|
-
# packages-audit:
|
|
9
|
-
# tags: frontend security
|
|
10
|
-
# run: yarn audit
|
|
11
|
-
# gems-audit:
|
|
12
|
-
# tags: backend security
|
|
13
|
-
# run: bundle audit
|
|
14
|
-
#
|
|
15
|
-
# pre-commit:
|
|
16
|
-
# parallel: true
|
|
17
|
-
# commands:
|
|
18
|
-
# eslint:
|
|
19
|
-
# glob: "*.{js,ts,jsx,tsx}"
|
|
20
|
-
# run: yarn eslint {staged_files}
|
|
21
|
-
# rubocop:
|
|
22
|
-
# tags: backend style
|
|
23
|
-
# glob: "*.rb"
|
|
24
|
-
# exclude: '(^|/)(application|routes)\.rb$'
|
|
25
|
-
# run: bundle exec rubocop --force-exclusion {all_files}
|
|
26
|
-
# govet:
|
|
27
|
-
# tags: backend style
|
|
28
|
-
# files: git ls-files -m
|
|
29
|
-
# glob: "*.go"
|
|
30
|
-
# run: go vet {files}
|
|
31
|
-
# scripts:
|
|
32
|
-
# "hello.js":
|
|
33
|
-
# runner: node
|
|
34
|
-
# "any.go":
|
|
35
|
-
# runner: go run
|
package/src/index.tsx
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { Platform, Dimensions, PixelRatio } from 'react-native';
|
|
2
|
-
import DeviceInfo from 'react-native-device-info';
|
|
3
|
-
import * as RNLocalize from 'react-native-localize';
|
|
4
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
5
|
-
import InAppPurchase, { Purchase, Product } from 'react-native-iap';
|
|
6
|
-
import axios from 'axios';
|
|
7
|
-
|
|
8
|
-
class GoMarketMe {
|
|
9
|
-
private static instance: GoMarketMe;
|
|
10
|
-
private sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
11
|
-
private affiliateCampaignCode = '';
|
|
12
|
-
private deviceId = '';
|
|
13
|
-
private sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
|
|
14
|
-
private systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
|
|
15
|
-
private eventUrl = 'https://api.gomarketme.net/v1/event';
|
|
16
|
-
|
|
17
|
-
private constructor() {}
|
|
18
|
-
|
|
19
|
-
public static getInstance(): GoMarketMe {
|
|
20
|
-
if (!GoMarketMe.instance) {
|
|
21
|
-
GoMarketMe.instance = new GoMarketMe();
|
|
22
|
-
}
|
|
23
|
-
return GoMarketMe.instance;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async initialize(apiKey: string): Promise<void> {
|
|
27
|
-
try {
|
|
28
|
-
const isSDKInitialized = await this.isSDKInitialized();
|
|
29
|
-
if (!isSDKInitialized) {
|
|
30
|
-
await this.postSDKInitialization(apiKey);
|
|
31
|
-
}
|
|
32
|
-
const systemInfo = await this.getSystemInfo();
|
|
33
|
-
await this.postSystemInfo(systemInfo, apiKey);
|
|
34
|
-
await this.addListener(apiKey);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.error('Error initializing GoMarketMe:', e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private async addListener(apiKey: string): Promise<void> {
|
|
41
|
-
InAppPurchase.purchaseUpdatedListener(async (purchase: Purchase) => {
|
|
42
|
-
if (this.affiliateCampaignCode != '') {
|
|
43
|
-
const productIds = await this.fetchPurchases([purchase], apiKey);
|
|
44
|
-
await this.fetchPurchaseProducts(productIds, apiKey);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private async getSystemInfo(): Promise<any> {
|
|
50
|
-
const deviceData = Platform.select({
|
|
51
|
-
ios: await this.readIosDeviceInfo(),
|
|
52
|
-
android: await this.readAndroidDeviceInfo(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const devicePixelRatio = PixelRatio.get();
|
|
56
|
-
|
|
57
|
-
const windowData = {
|
|
58
|
-
devicePixelRatio: devicePixelRatio,
|
|
59
|
-
width: Dimensions.get('window').width * devicePixelRatio,
|
|
60
|
-
height: Dimensions.get('window').height * devicePixelRatio,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
device_info: deviceData,
|
|
65
|
-
window_info: windowData,
|
|
66
|
-
time_zone_code: this.getTimeZoneCode(),
|
|
67
|
-
language_code: this.getLanguageCode(),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private async postSDKInitialization(apiKey: string): Promise<void> {
|
|
72
|
-
try {
|
|
73
|
-
const response = await axios.post(this.sdkInitializationUrl, {}, {
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
'x-api-key': apiKey,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
if (response.status === 200) {
|
|
80
|
-
await this.markSDKAsInitialized();
|
|
81
|
-
} else {
|
|
82
|
-
console.error('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
83
|
-
}
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.error('Error sending SDK information to server:', e);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private async postSystemInfo(systemInfo: any, apiKey: string): Promise<void> {
|
|
90
|
-
try {
|
|
91
|
-
const response = await axios.post(this.systemInfoUrl, systemInfo, {
|
|
92
|
-
headers: {
|
|
93
|
-
'Content-Type': 'application/json',
|
|
94
|
-
'x-api-key': apiKey,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
if (response.status === 200) {
|
|
98
|
-
const responseData = response.data;
|
|
99
|
-
if (responseData.affiliate_campaign_code) {
|
|
100
|
-
this.affiliateCampaignCode = responseData.affiliate_campaign_code;
|
|
101
|
-
}
|
|
102
|
-
if (responseData.device_id) {
|
|
103
|
-
this.deviceId = responseData.device_id;
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
console.error('Failed to send system info. Status code:', response.status);
|
|
107
|
-
}
|
|
108
|
-
} catch (e) {
|
|
109
|
-
console.error('Error sending system info to server:', e);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async readAndroidDeviceInfo(): Promise<any> {
|
|
114
|
-
return {
|
|
115
|
-
deviceId: await DeviceInfo.getAndroidId(),
|
|
116
|
-
_deviceId: await DeviceInfo.getDeviceId(),
|
|
117
|
-
systemName: await DeviceInfo.getSystemName(),
|
|
118
|
-
systemVersion: await DeviceInfo.getSystemVersion(),
|
|
119
|
-
brand: await DeviceInfo.getBrand(),
|
|
120
|
-
model: await DeviceInfo.getModel(),
|
|
121
|
-
manufacturer: await DeviceInfo.getManufacturer(),
|
|
122
|
-
isEmulator: await DeviceInfo.isEmulator(),
|
|
123
|
-
uniqueId: await DeviceInfo.getUniqueId(),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private async readIosDeviceInfo(): Promise<any> {
|
|
128
|
-
var info = {
|
|
129
|
-
deviceId: await DeviceInfo.getUniqueId(),
|
|
130
|
-
_deviceId: await DeviceInfo.getDeviceId(),
|
|
131
|
-
systemName: await DeviceInfo.getSystemName(),
|
|
132
|
-
systemVersion: await DeviceInfo.getSystemVersion(),
|
|
133
|
-
brand: await DeviceInfo.getBrand(),
|
|
134
|
-
model: await DeviceInfo.getModel(),
|
|
135
|
-
manufacturer: await DeviceInfo.getManufacturer(),
|
|
136
|
-
isEmulator: await DeviceInfo.isEmulator(),
|
|
137
|
-
uniqueId: await DeviceInfo.getUniqueId(),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private getTimeZoneCode(): string {
|
|
142
|
-
// Convert the time zone to GMT format (e.g., "GMT+2")
|
|
143
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
144
|
-
const date = new Date();
|
|
145
|
-
const timezoneOffset = date.getTimezoneOffset(); // in minutes
|
|
146
|
-
const absOffset = Math.abs(timezoneOffset);
|
|
147
|
-
const hours = Math.floor(absOffset / 60);
|
|
148
|
-
const minutes = absOffset % 60;
|
|
149
|
-
const sign = timezoneOffset > 0 ? '-' : '+';
|
|
150
|
-
return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`; // Return GMT format
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private getLanguageCode(): string {
|
|
154
|
-
const locales = RNLocalize.getLocales();
|
|
155
|
-
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private async fetchPurchases(purchaseDetailsList: Purchase[], apiKey: string): Promise<string[]> {
|
|
159
|
-
const productIds: string[] = [];
|
|
160
|
-
for (const purchase of purchaseDetailsList) {
|
|
161
|
-
if (purchase.transactionReceipt) {
|
|
162
|
-
await this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey);
|
|
163
|
-
if (purchase.productId && !productIds.includes(purchase.productId)) {
|
|
164
|
-
productIds.push(purchase.productId);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return productIds;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private async fetchPurchaseProducts(productIds: string[], apiKey: string): Promise<void> {
|
|
172
|
-
try {
|
|
173
|
-
const products = await InAppPurchase.getProducts(productIds);
|
|
174
|
-
if (products.length > 0) {
|
|
175
|
-
for (const product of products) {
|
|
176
|
-
await this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey);
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
await this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey);
|
|
180
|
-
}
|
|
181
|
-
} catch (e) {
|
|
182
|
-
console.error('Error fetching products:', e);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
private async sendEventToServer(body: string, eventType: string, apiKey: string): Promise<void> {
|
|
187
|
-
try {
|
|
188
|
-
const response = await axios.post(this.eventUrl, body, {
|
|
189
|
-
headers: {
|
|
190
|
-
'Content-Type': 'application/json',
|
|
191
|
-
'x-affiliate-campaign-code': this.affiliateCampaignCode,
|
|
192
|
-
'x-device-id': this.deviceId,
|
|
193
|
-
'x-event-type': eventType,
|
|
194
|
-
'x-product-type': Platform.OS,
|
|
195
|
-
'x-source-name': Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
196
|
-
'x-api-key': apiKey,
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
if (response.status === 200) {
|
|
200
|
-
console.log(`${eventType} sent successfully`);
|
|
201
|
-
} else {
|
|
202
|
-
console.error(`Failed to send ${eventType}. Status code:`, response.status);
|
|
203
|
-
}
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error(`Error sending ${eventType} to server:`, e);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private serializePurchaseDetails(purchase: Purchase): any {
|
|
210
|
-
return {
|
|
211
|
-
productID: purchase.productId,
|
|
212
|
-
purchaseID: purchase.transactionId || '',
|
|
213
|
-
transactionDate: purchase.transactionDate || '',
|
|
214
|
-
status: Platform.select({
|
|
215
|
-
ios: (purchase as any).transactionStateIOS, // Removed non-existent properties
|
|
216
|
-
android: (purchase as any).purchaseStateAndroid,
|
|
217
|
-
}),
|
|
218
|
-
verificationData: {
|
|
219
|
-
localVerificationData: purchase.transactionReceipt,
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private serializeProductDetails(product: Product): any {
|
|
225
|
-
return {
|
|
226
|
-
productID: product.productId,
|
|
227
|
-
productTitle: product.title,
|
|
228
|
-
productDescription: product.description,
|
|
229
|
-
productPrice: product.price,
|
|
230
|
-
productRawPrice: product.price,
|
|
231
|
-
productCurrencyCode: product.currency,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private async markSDKAsInitialized(): Promise<boolean> {
|
|
236
|
-
try {
|
|
237
|
-
await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
|
|
238
|
-
return true;
|
|
239
|
-
} catch (e) {
|
|
240
|
-
console.error('Failed to save SDK initialization:', e);
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private async isSDKInitialized(): Promise<boolean> {
|
|
246
|
-
try {
|
|
247
|
-
const value = await AsyncStorage.getItem(this.sdkInitializedKey);
|
|
248
|
-
return value === 'true';
|
|
249
|
-
} catch (e) {
|
|
250
|
-
console.error('Failed to load SDK initialization:', e);
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export default GoMarketMe.getInstance();
|