gomarketme-react-native 1.0.12 → 1.0.13
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 +510 -0
- package/package.json +8 -7
- package/src/index.tsx +42 -16
- package/tsconfig.json +1 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
var react_native_1 = require("react-native");
|
|
66
|
+
var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
|
|
67
|
+
var RNLocalize = __importStar(require("react-native-localize"));
|
|
68
|
+
var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
69
|
+
var react_native_iap_1 = __importDefault(require("react-native-iap"));
|
|
70
|
+
var axios_1 = __importDefault(require("axios"));
|
|
71
|
+
var GoMarketMe = /** @class */ (function () {
|
|
72
|
+
function GoMarketMe() {
|
|
73
|
+
this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
74
|
+
this.affiliateCampaignCode = '';
|
|
75
|
+
this.deviceId = '';
|
|
76
|
+
this.sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
|
|
77
|
+
this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
|
|
78
|
+
this.eventUrl = 'https://api.gomarketme.net/v1/event';
|
|
79
|
+
}
|
|
80
|
+
GoMarketMe.getInstance = function () {
|
|
81
|
+
if (!GoMarketMe.instance) {
|
|
82
|
+
GoMarketMe.instance = new GoMarketMe();
|
|
83
|
+
}
|
|
84
|
+
return GoMarketMe.instance;
|
|
85
|
+
};
|
|
86
|
+
GoMarketMe.prototype.initialize = function (apiKey) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
var isSDKInitialized, systemInfo, e_1;
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
_a.trys.push([0, 7, , 8]);
|
|
93
|
+
return [4 /*yield*/, this.isSDKInitialized()];
|
|
94
|
+
case 1:
|
|
95
|
+
isSDKInitialized = _a.sent();
|
|
96
|
+
if (!!isSDKInitialized) return [3 /*break*/, 3];
|
|
97
|
+
return [4 /*yield*/, this.postSDKInitialization(apiKey)];
|
|
98
|
+
case 2:
|
|
99
|
+
_a.sent();
|
|
100
|
+
_a.label = 3;
|
|
101
|
+
case 3: return [4 /*yield*/, this.getSystemInfo()];
|
|
102
|
+
case 4:
|
|
103
|
+
systemInfo = _a.sent();
|
|
104
|
+
return [4 /*yield*/, this.postSystemInfo(systemInfo, apiKey)];
|
|
105
|
+
case 5:
|
|
106
|
+
_a.sent();
|
|
107
|
+
return [4 /*yield*/, this.addListener(apiKey)];
|
|
108
|
+
case 6:
|
|
109
|
+
_a.sent();
|
|
110
|
+
return [3 /*break*/, 8];
|
|
111
|
+
case 7:
|
|
112
|
+
e_1 = _a.sent();
|
|
113
|
+
console.error('Error initializing GoMarketMe:', e_1);
|
|
114
|
+
return [3 /*break*/, 8];
|
|
115
|
+
case 8: return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
GoMarketMe.prototype.addListener = function (apiKey) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var _this = this;
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
react_native_iap_1.default.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
|
|
125
|
+
var productIds;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
if (!(this.affiliateCampaignCode != '')) return [3 /*break*/, 3];
|
|
130
|
+
return [4 /*yield*/, this.fetchPurchases([purchase], apiKey)];
|
|
131
|
+
case 1:
|
|
132
|
+
productIds = _a.sent();
|
|
133
|
+
return [4 /*yield*/, this.fetchPurchaseProducts(productIds, apiKey)];
|
|
134
|
+
case 2:
|
|
135
|
+
_a.sent();
|
|
136
|
+
_a.label = 3;
|
|
137
|
+
case 3: return [2 /*return*/];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}); });
|
|
141
|
+
return [2 /*return*/];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
GoMarketMe.prototype.getSystemInfo = function () {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
+
var deviceData, _a, _b, devicePixelRatio, windowData;
|
|
148
|
+
var _c;
|
|
149
|
+
return __generator(this, function (_d) {
|
|
150
|
+
switch (_d.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
_b = (_a = react_native_1.Platform).select;
|
|
153
|
+
_c = {};
|
|
154
|
+
return [4 /*yield*/, this.readIosDeviceInfo()];
|
|
155
|
+
case 1:
|
|
156
|
+
_c.ios = _d.sent();
|
|
157
|
+
return [4 /*yield*/, this.readAndroidDeviceInfo()];
|
|
158
|
+
case 2:
|
|
159
|
+
deviceData = _b.apply(_a, [(_c.android = _d.sent(),
|
|
160
|
+
_c)]);
|
|
161
|
+
devicePixelRatio = react_native_1.PixelRatio.get();
|
|
162
|
+
windowData = {
|
|
163
|
+
devicePixelRatio: devicePixelRatio,
|
|
164
|
+
width: react_native_1.Dimensions.get('window').width * devicePixelRatio,
|
|
165
|
+
height: react_native_1.Dimensions.get('window').height * devicePixelRatio,
|
|
166
|
+
};
|
|
167
|
+
return [2 /*return*/, {
|
|
168
|
+
device_info: deviceData,
|
|
169
|
+
window_info: windowData,
|
|
170
|
+
time_zone_code: this.getTimeZoneCode(),
|
|
171
|
+
language_code: this.getLanguageCode(),
|
|
172
|
+
}];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
GoMarketMe.prototype.postSDKInitialization = function (apiKey) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var response, e_2;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
_a.trys.push([0, 5, , 6]);
|
|
184
|
+
return [4 /*yield*/, axios_1.default.post(this.sdkInitializationUrl, {}, {
|
|
185
|
+
headers: {
|
|
186
|
+
'Content-Type': 'application/json',
|
|
187
|
+
'x-api-key': apiKey,
|
|
188
|
+
},
|
|
189
|
+
})];
|
|
190
|
+
case 1:
|
|
191
|
+
response = _a.sent();
|
|
192
|
+
if (!(response.status === 200)) return [3 /*break*/, 3];
|
|
193
|
+
return [4 /*yield*/, this.markSDKAsInitialized()];
|
|
194
|
+
case 2:
|
|
195
|
+
_a.sent();
|
|
196
|
+
return [3 /*break*/, 4];
|
|
197
|
+
case 3:
|
|
198
|
+
console.error('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
199
|
+
_a.label = 4;
|
|
200
|
+
case 4: return [3 /*break*/, 6];
|
|
201
|
+
case 5:
|
|
202
|
+
e_2 = _a.sent();
|
|
203
|
+
console.error('Error sending SDK information to server:', e_2);
|
|
204
|
+
return [3 /*break*/, 6];
|
|
205
|
+
case 6: return [2 /*return*/];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
GoMarketMe.prototype.postSystemInfo = function (systemInfo, apiKey) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
+
var response, responseData, e_3;
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
_a.trys.push([0, 2, , 3]);
|
|
217
|
+
return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, systemInfo, {
|
|
218
|
+
headers: {
|
|
219
|
+
'Content-Type': 'application/json',
|
|
220
|
+
'x-api-key': apiKey,
|
|
221
|
+
},
|
|
222
|
+
})];
|
|
223
|
+
case 1:
|
|
224
|
+
response = _a.sent();
|
|
225
|
+
if (response.status === 200) {
|
|
226
|
+
responseData = response.data;
|
|
227
|
+
if (responseData.affiliate_campaign_code) {
|
|
228
|
+
this.affiliateCampaignCode = responseData.affiliate_campaign_code;
|
|
229
|
+
}
|
|
230
|
+
if (responseData.device_id) {
|
|
231
|
+
this.deviceId = responseData.device_id;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
console.error('Failed to send system info. Status code:', response.status);
|
|
236
|
+
}
|
|
237
|
+
return [3 /*break*/, 3];
|
|
238
|
+
case 2:
|
|
239
|
+
e_3 = _a.sent();
|
|
240
|
+
console.error('Error sending system info to server:', e_3);
|
|
241
|
+
return [3 /*break*/, 3];
|
|
242
|
+
case 3: return [2 /*return*/];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
GoMarketMe.prototype.readAndroidDeviceInfo = function () {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
249
|
+
var _a;
|
|
250
|
+
return __generator(this, function (_b) {
|
|
251
|
+
switch (_b.label) {
|
|
252
|
+
case 0:
|
|
253
|
+
_a = {};
|
|
254
|
+
return [4 /*yield*/, react_native_device_info_1.default.getAndroidId()];
|
|
255
|
+
case 1:
|
|
256
|
+
_a.deviceId = _b.sent();
|
|
257
|
+
return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
|
|
258
|
+
case 2:
|
|
259
|
+
_a._deviceId = _b.sent();
|
|
260
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
|
|
261
|
+
case 3:
|
|
262
|
+
_a.systemName = _b.sent();
|
|
263
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
|
|
264
|
+
case 4:
|
|
265
|
+
_a.systemVersion = _b.sent();
|
|
266
|
+
return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
|
|
267
|
+
case 5:
|
|
268
|
+
_a.brand = _b.sent();
|
|
269
|
+
return [4 /*yield*/, react_native_device_info_1.default.getModel()];
|
|
270
|
+
case 6:
|
|
271
|
+
_a.model = _b.sent();
|
|
272
|
+
return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
|
|
273
|
+
case 7:
|
|
274
|
+
_a.manufacturer = _b.sent();
|
|
275
|
+
return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
|
|
276
|
+
case 8:
|
|
277
|
+
_a.isEmulator = _b.sent();
|
|
278
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
279
|
+
case 9: return [2 /*return*/, (_a.uniqueId = _b.sent(),
|
|
280
|
+
_a)];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
GoMarketMe.prototype.readIosDeviceInfo = function () {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
+
var info;
|
|
288
|
+
var _a;
|
|
289
|
+
return __generator(this, function (_b) {
|
|
290
|
+
switch (_b.label) {
|
|
291
|
+
case 0:
|
|
292
|
+
_a = {};
|
|
293
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
294
|
+
case 1:
|
|
295
|
+
_a.deviceId = _b.sent();
|
|
296
|
+
return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
|
|
297
|
+
case 2:
|
|
298
|
+
_a._deviceId = _b.sent();
|
|
299
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
|
|
300
|
+
case 3:
|
|
301
|
+
_a.systemName = _b.sent();
|
|
302
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
|
|
303
|
+
case 4:
|
|
304
|
+
_a.systemVersion = _b.sent();
|
|
305
|
+
return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
|
|
306
|
+
case 5:
|
|
307
|
+
_a.brand = _b.sent();
|
|
308
|
+
return [4 /*yield*/, react_native_device_info_1.default.getModel()];
|
|
309
|
+
case 6:
|
|
310
|
+
_a.model = _b.sent();
|
|
311
|
+
return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
|
|
312
|
+
case 7:
|
|
313
|
+
_a.manufacturer = _b.sent();
|
|
314
|
+
return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
|
|
315
|
+
case 8:
|
|
316
|
+
_a.isEmulator = _b.sent();
|
|
317
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
318
|
+
case 9:
|
|
319
|
+
info = (_a.uniqueId = _b.sent(),
|
|
320
|
+
_a);
|
|
321
|
+
return [2 /*return*/];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
GoMarketMe.prototype.getTimeZoneCode = function () {
|
|
327
|
+
// Convert the time zone to GMT format (e.g., "GMT+2")
|
|
328
|
+
var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
329
|
+
var date = new Date();
|
|
330
|
+
var timezoneOffset = date.getTimezoneOffset(); // in minutes
|
|
331
|
+
var absOffset = Math.abs(timezoneOffset);
|
|
332
|
+
var hours = Math.floor(absOffset / 60);
|
|
333
|
+
var minutes = absOffset % 60;
|
|
334
|
+
var sign = timezoneOffset > 0 ? '-' : '+';
|
|
335
|
+
return "GMT".concat(sign).concat(String(hours).padStart(2, '0'), ":").concat(String(minutes).padStart(2, '0')); // Return GMT format
|
|
336
|
+
};
|
|
337
|
+
GoMarketMe.prototype.getLanguageCode = function () {
|
|
338
|
+
var locales = RNLocalize.getLocales();
|
|
339
|
+
// Check if there are any locales available and return the first one or default to 'en-US'
|
|
340
|
+
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
341
|
+
};
|
|
342
|
+
GoMarketMe.prototype.fetchPurchases = function (purchaseDetailsList, apiKey) {
|
|
343
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
+
var productIds, _i, purchaseDetailsList_1, purchase;
|
|
345
|
+
return __generator(this, function (_a) {
|
|
346
|
+
switch (_a.label) {
|
|
347
|
+
case 0:
|
|
348
|
+
productIds = [];
|
|
349
|
+
_i = 0, purchaseDetailsList_1 = purchaseDetailsList;
|
|
350
|
+
_a.label = 1;
|
|
351
|
+
case 1:
|
|
352
|
+
if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 4];
|
|
353
|
+
purchase = purchaseDetailsList_1[_i];
|
|
354
|
+
if (!purchase.transactionReceipt) return [3 /*break*/, 3];
|
|
355
|
+
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey)];
|
|
356
|
+
case 2:
|
|
357
|
+
_a.sent();
|
|
358
|
+
if (purchase.productId && !productIds.includes(purchase.productId)) {
|
|
359
|
+
productIds.push(purchase.productId);
|
|
360
|
+
}
|
|
361
|
+
_a.label = 3;
|
|
362
|
+
case 3:
|
|
363
|
+
_i++;
|
|
364
|
+
return [3 /*break*/, 1];
|
|
365
|
+
case 4: return [2 /*return*/, productIds];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
var products, _i, products_1, product, e_4;
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
switch (_a.label) {
|
|
375
|
+
case 0:
|
|
376
|
+
_a.trys.push([0, 9, , 10]);
|
|
377
|
+
return [4 /*yield*/, react_native_iap_1.default.getProducts(productIds)];
|
|
378
|
+
case 1:
|
|
379
|
+
products = _a.sent();
|
|
380
|
+
if (!(products.length > 0)) return [3 /*break*/, 6];
|
|
381
|
+
_i = 0, products_1 = products;
|
|
382
|
+
_a.label = 2;
|
|
383
|
+
case 2:
|
|
384
|
+
if (!(_i < products_1.length)) return [3 /*break*/, 5];
|
|
385
|
+
product = products_1[_i];
|
|
386
|
+
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
|
|
387
|
+
case 3:
|
|
388
|
+
_a.sent();
|
|
389
|
+
_a.label = 4;
|
|
390
|
+
case 4:
|
|
391
|
+
_i++;
|
|
392
|
+
return [3 /*break*/, 2];
|
|
393
|
+
case 5: return [3 /*break*/, 8];
|
|
394
|
+
case 6: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
|
|
395
|
+
case 7:
|
|
396
|
+
_a.sent();
|
|
397
|
+
_a.label = 8;
|
|
398
|
+
case 8: return [3 /*break*/, 10];
|
|
399
|
+
case 9:
|
|
400
|
+
e_4 = _a.sent();
|
|
401
|
+
console.error('Error fetching products:', e_4);
|
|
402
|
+
return [3 /*break*/, 10];
|
|
403
|
+
case 10: return [2 /*return*/];
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
GoMarketMe.prototype.sendEventToServer = function (body, eventType, apiKey) {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
410
|
+
var response, e_5;
|
|
411
|
+
return __generator(this, function (_a) {
|
|
412
|
+
switch (_a.label) {
|
|
413
|
+
case 0:
|
|
414
|
+
_a.trys.push([0, 2, , 3]);
|
|
415
|
+
return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
|
|
416
|
+
headers: {
|
|
417
|
+
'Content-Type': 'application/json',
|
|
418
|
+
'x-affiliate-campaign-code': this.affiliateCampaignCode,
|
|
419
|
+
'x-device-id': this.deviceId,
|
|
420
|
+
'x-event-type': eventType,
|
|
421
|
+
'x-product-type': react_native_1.Platform.OS,
|
|
422
|
+
'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
423
|
+
'x-api-key': apiKey,
|
|
424
|
+
},
|
|
425
|
+
})];
|
|
426
|
+
case 1:
|
|
427
|
+
response = _a.sent();
|
|
428
|
+
if (response.status === 200) {
|
|
429
|
+
console.log("".concat(eventType, " sent successfully"));
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
console.error("Failed to send ".concat(eventType, ". Status code:"), response.status);
|
|
433
|
+
}
|
|
434
|
+
return [3 /*break*/, 3];
|
|
435
|
+
case 2:
|
|
436
|
+
e_5 = _a.sent();
|
|
437
|
+
console.error("Error sending ".concat(eventType, " to server:"), e_5);
|
|
438
|
+
return [3 /*break*/, 3];
|
|
439
|
+
case 3: return [2 /*return*/];
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
|
|
445
|
+
return {
|
|
446
|
+
productID: purchase.productId,
|
|
447
|
+
purchaseID: purchase.transactionId || '',
|
|
448
|
+
transactionDate: purchase.transactionDate || '',
|
|
449
|
+
status: react_native_1.Platform.select({
|
|
450
|
+
ios: purchase.transactionStateIOS,
|
|
451
|
+
android: purchase.purchaseStateAndroid,
|
|
452
|
+
}),
|
|
453
|
+
verificationData: {
|
|
454
|
+
localVerificationData: purchase.transactionReceipt,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
};
|
|
458
|
+
GoMarketMe.prototype.serializeProductDetails = function (product) {
|
|
459
|
+
return {
|
|
460
|
+
productID: product.productId,
|
|
461
|
+
productTitle: product.title,
|
|
462
|
+
productDescription: product.description,
|
|
463
|
+
productPrice: product.price,
|
|
464
|
+
productRawPrice: product.price,
|
|
465
|
+
productCurrencyCode: product.currency,
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
GoMarketMe.prototype.markSDKAsInitialized = function () {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
470
|
+
var e_6;
|
|
471
|
+
return __generator(this, function (_a) {
|
|
472
|
+
switch (_a.label) {
|
|
473
|
+
case 0:
|
|
474
|
+
_a.trys.push([0, 2, , 3]);
|
|
475
|
+
return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
|
|
476
|
+
case 1:
|
|
477
|
+
_a.sent();
|
|
478
|
+
return [2 /*return*/, true];
|
|
479
|
+
case 2:
|
|
480
|
+
e_6 = _a.sent();
|
|
481
|
+
console.error('Failed to save SDK initialization:', e_6);
|
|
482
|
+
return [2 /*return*/, false];
|
|
483
|
+
case 3: return [2 /*return*/];
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
GoMarketMe.prototype.isSDKInitialized = function () {
|
|
489
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
490
|
+
var value, e_7;
|
|
491
|
+
return __generator(this, function (_a) {
|
|
492
|
+
switch (_a.label) {
|
|
493
|
+
case 0:
|
|
494
|
+
_a.trys.push([0, 2, , 3]);
|
|
495
|
+
return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
|
|
496
|
+
case 1:
|
|
497
|
+
value = _a.sent();
|
|
498
|
+
return [2 /*return*/, value === 'true'];
|
|
499
|
+
case 2:
|
|
500
|
+
e_7 = _a.sent();
|
|
501
|
+
console.error('Failed to load SDK initialization:', e_7);
|
|
502
|
+
return [2 /*return*/, false];
|
|
503
|
+
case 3: return [2 /*return*/];
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
return GoMarketMe;
|
|
509
|
+
}());
|
|
510
|
+
exports.default = GoMarketMe.getInstance();
|
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gomarketme-react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Affiliate Marketing for React Native-Based iOS and Android Apps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "yarn build",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
7
12
|
"homepage": "https://gomarketme.co",
|
|
8
13
|
"keywords": [
|
|
9
14
|
"react-native",
|
|
10
15
|
"gomarketme",
|
|
11
16
|
"sdk"
|
|
12
17
|
],
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/GoMarketMe/gomarketme-react-native.git"
|
|
16
|
-
},
|
|
17
18
|
"author": "GoMarketMe",
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"@react-native-async-storage/async-storage": "^1.15.6",
|
|
21
|
-
"axios": "^
|
|
22
|
-
"react-native-device-info": "^
|
|
22
|
+
"axios": "^1.7.7",
|
|
23
|
+
"react-native-device-info": "^14.0.0",
|
|
23
24
|
"react-native-iap": "^7.0.0",
|
|
24
25
|
"react-native-localize": "^3.2.1"
|
|
25
26
|
},
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Platform, Dimensions, PixelRatio } from 'react-native';
|
|
2
2
|
import DeviceInfo from 'react-native-device-info';
|
|
3
3
|
import * as RNLocalize from 'react-native-localize';
|
|
4
|
-
import
|
|
4
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
5
|
+
import InAppPurchase, { Purchase, Product, ProductPurchase } from 'react-native-iap';
|
|
5
6
|
import axios from 'axios';
|
|
6
7
|
|
|
7
8
|
class GoMarketMe {
|
|
@@ -24,7 +25,7 @@ class GoMarketMe {
|
|
|
24
25
|
|
|
25
26
|
public async initialize(apiKey: string): Promise<void> {
|
|
26
27
|
try {
|
|
27
|
-
const isSDKInitialized = this.isSDKInitialized();
|
|
28
|
+
const isSDKInitialized = await this.isSDKInitialized();
|
|
28
29
|
if (!isSDKInitialized) {
|
|
29
30
|
await this.postSDKInitialization(apiKey);
|
|
30
31
|
}
|
|
@@ -38,7 +39,7 @@ class GoMarketMe {
|
|
|
38
39
|
|
|
39
40
|
private async addListener(apiKey: string): Promise<void> {
|
|
40
41
|
InAppPurchase.purchaseUpdatedListener(async (purchase: Purchase) => {
|
|
41
|
-
if (this.affiliateCampaignCode) {
|
|
42
|
+
if (this.affiliateCampaignCode != '') {
|
|
42
43
|
const productIds = await this.fetchPurchases([purchase], apiKey);
|
|
43
44
|
await this.fetchPurchaseProducts(productIds, apiKey);
|
|
44
45
|
}
|
|
@@ -54,7 +55,7 @@ class GoMarketMe {
|
|
|
54
55
|
const devicePixelRatio = PixelRatio.get();
|
|
55
56
|
|
|
56
57
|
const windowData = {
|
|
57
|
-
devicePixelRatio,
|
|
58
|
+
devicePixelRatio: devicePixelRatio,
|
|
58
59
|
width: Dimensions.get('window').width * devicePixelRatio,
|
|
59
60
|
height: Dimensions.get('window').height * devicePixelRatio,
|
|
60
61
|
};
|
|
@@ -76,7 +77,7 @@ class GoMarketMe {
|
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
79
|
if (response.status === 200) {
|
|
79
|
-
this.markSDKAsInitialized();
|
|
80
|
+
await this.markSDKAsInitialized();
|
|
80
81
|
} else {
|
|
81
82
|
console.error('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
82
83
|
}
|
|
@@ -95,8 +96,12 @@ class GoMarketMe {
|
|
|
95
96
|
});
|
|
96
97
|
if (response.status === 200) {
|
|
97
98
|
const responseData = response.data;
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
100
105
|
} else {
|
|
101
106
|
console.error('Failed to send system info. Status code:', response.status);
|
|
102
107
|
}
|
|
@@ -108,6 +113,7 @@ class GoMarketMe {
|
|
|
108
113
|
private async readAndroidDeviceInfo(): Promise<any> {
|
|
109
114
|
return {
|
|
110
115
|
deviceId: await DeviceInfo.getAndroidId(),
|
|
116
|
+
_deviceId: await DeviceInfo.getDeviceId(),
|
|
111
117
|
systemName: await DeviceInfo.getSystemName(),
|
|
112
118
|
systemVersion: await DeviceInfo.getSystemVersion(),
|
|
113
119
|
brand: await DeviceInfo.getBrand(),
|
|
@@ -119,8 +125,9 @@ class GoMarketMe {
|
|
|
119
125
|
}
|
|
120
126
|
|
|
121
127
|
private async readIosDeviceInfo(): Promise<any> {
|
|
122
|
-
|
|
128
|
+
var info = {
|
|
123
129
|
deviceId: await DeviceInfo.getUniqueId(),
|
|
130
|
+
_deviceId: await DeviceInfo.getDeviceId(),
|
|
124
131
|
systemName: await DeviceInfo.getSystemName(),
|
|
125
132
|
systemVersion: await DeviceInfo.getSystemVersion(),
|
|
126
133
|
brand: await DeviceInfo.getBrand(),
|
|
@@ -132,17 +139,21 @@ class GoMarketMe {
|
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
private getTimeZoneCode(): string {
|
|
135
|
-
|
|
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
|
|
136
146
|
const absOffset = Math.abs(timezoneOffset);
|
|
137
147
|
const hours = Math.floor(absOffset / 60);
|
|
138
148
|
const minutes = absOffset % 60;
|
|
139
149
|
const sign = timezoneOffset > 0 ? '-' : '+';
|
|
140
|
-
return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
|
|
150
|
+
return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`; // Return GMT format
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
private getLanguageCode(): string {
|
|
144
154
|
const locales = RNLocalize.getLocales();
|
|
145
|
-
|
|
155
|
+
// Check if there are any locales available and return the first one or default to 'en-US'
|
|
156
|
+
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
146
157
|
}
|
|
147
158
|
|
|
148
159
|
private async fetchPurchases(purchaseDetailsList: Purchase[], apiKey: string): Promise<string[]> {
|
|
@@ -202,7 +213,7 @@ class GoMarketMe {
|
|
|
202
213
|
purchaseID: purchase.transactionId || '',
|
|
203
214
|
transactionDate: purchase.transactionDate || '',
|
|
204
215
|
status: Platform.select({
|
|
205
|
-
ios: (purchase as any).transactionStateIOS,
|
|
216
|
+
ios: (purchase as any).transactionStateIOS, // Removed non-existent properties
|
|
206
217
|
android: (purchase as any).purchaseStateAndroid,
|
|
207
218
|
}),
|
|
208
219
|
verificationData: {
|
|
@@ -215,16 +226,31 @@ class GoMarketMe {
|
|
|
215
226
|
return {
|
|
216
227
|
productID: product.productId,
|
|
217
228
|
productTitle: product.title,
|
|
229
|
+
productDescription: product.description,
|
|
218
230
|
productPrice: product.price,
|
|
231
|
+
productRawPrice: product.price,
|
|
232
|
+
productCurrencyCode: product.currency,
|
|
219
233
|
};
|
|
220
234
|
}
|
|
221
235
|
|
|
222
|
-
private
|
|
223
|
-
|
|
236
|
+
private async markSDKAsInitialized(): Promise<boolean> {
|
|
237
|
+
try {
|
|
238
|
+
await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
|
|
239
|
+
return true;
|
|
240
|
+
} catch (e) {
|
|
241
|
+
console.error('Failed to save SDK initialization:', e);
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
224
244
|
}
|
|
225
245
|
|
|
226
|
-
private
|
|
227
|
-
|
|
246
|
+
private async isSDKInitialized(): Promise<boolean> {
|
|
247
|
+
try {
|
|
248
|
+
const value = await AsyncStorage.getItem(this.sdkInitializedKey);
|
|
249
|
+
return value === 'true';
|
|
250
|
+
} catch (e) {
|
|
251
|
+
console.error('Failed to load SDK initialization:', e);
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
228
254
|
}
|
|
229
255
|
}
|
|
230
256
|
|
package/tsconfig.json
CHANGED