gomarketme-react-native 1.1.1 → 2.0.0
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/README.md +5 -8
- package/dist/index.d.ts +57 -18
- package/dist/index.js +250 -163
- package/package.json +2 -2
- package/src/index.tsx +248 -92
package/README.md
CHANGED
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
### Using npm
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npm install gomarketme-react-native
|
|
13
|
+
npm install gomarketme-react-native@2.0.0
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
### Using yarn
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
yarn add gomarketme-react-native
|
|
19
|
+
yarn add gomarketme-react-native@2.0.0
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
### Using pnpm
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
pnpm add gomarketme-react-native
|
|
25
|
+
pnpm add gomarketme-react-native@2.0.0
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
|
|
@@ -34,14 +34,11 @@ To initialize GoMarketMe, import the `gomarketme` package and create a new insta
|
|
|
34
34
|
import GoMarketMe from 'gomarketme-react-native';
|
|
35
35
|
|
|
36
36
|
const App: React.FC = () => {
|
|
37
|
-
const apiKey = 'YOUR_API_KEY_HERE';
|
|
38
37
|
|
|
39
38
|
useEffect(() => {
|
|
40
|
-
const initializeGoMarketMe = async () => {
|
|
41
|
-
await GoMarketMe.initialize(apiKey);
|
|
42
|
-
};
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
GoMarketMe.initialize('API_KEY'); // Initialize with your API key
|
|
41
|
+
|
|
45
42
|
}, []);
|
|
46
43
|
};
|
|
47
44
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,69 @@
|
|
|
1
|
+
export declare class GoMarketMeAffiliateMarketingData {
|
|
2
|
+
campaign: Campaign;
|
|
3
|
+
affiliate: Affiliate;
|
|
4
|
+
saleDistribution: SaleDistribution;
|
|
5
|
+
affiliateCampaignCode: string;
|
|
6
|
+
deviceId: string;
|
|
7
|
+
offerCode?: string;
|
|
8
|
+
constructor(campaign: Campaign, affiliate: Affiliate, saleDistribution: SaleDistribution, affiliateCampaignCode: string, deviceId: string, offerCode?: string);
|
|
9
|
+
static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null;
|
|
10
|
+
}
|
|
11
|
+
export declare class Campaign {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
status: string;
|
|
15
|
+
type: string;
|
|
16
|
+
publicLinkUrl?: string;
|
|
17
|
+
constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string);
|
|
18
|
+
static fromJson(json: Record<string, any>): Campaign;
|
|
19
|
+
}
|
|
20
|
+
export declare class Affiliate {
|
|
21
|
+
id: string;
|
|
22
|
+
firstName: string;
|
|
23
|
+
lastName: string;
|
|
24
|
+
countryCode: string;
|
|
25
|
+
instagramAccount: string;
|
|
26
|
+
tiktokAccount: string;
|
|
27
|
+
xAccount: string;
|
|
28
|
+
constructor(id: string, firstName: string, lastName: string, countryCode: string, instagramAccount: string, tiktokAccount: string, xAccount: string);
|
|
29
|
+
static fromJson(json: Record<string, any>): Affiliate;
|
|
30
|
+
}
|
|
31
|
+
export declare class SaleDistribution {
|
|
32
|
+
platformPercentage: string;
|
|
33
|
+
affiliatePercentage: string;
|
|
34
|
+
constructor(platformPercentage: string, affiliatePercentage: string);
|
|
35
|
+
static fromJson(json: Record<string, any>): SaleDistribution;
|
|
36
|
+
}
|
|
1
37
|
declare class GoMarketMe {
|
|
2
38
|
private static instance;
|
|
39
|
+
private sdkType;
|
|
40
|
+
private sdkVersion;
|
|
3
41
|
private sdkInitializedKey;
|
|
4
|
-
private affiliateCampaignCode;
|
|
5
|
-
private deviceId;
|
|
6
42
|
private sdkInitializationUrl;
|
|
7
43
|
private systemInfoUrl;
|
|
8
44
|
private eventUrl;
|
|
45
|
+
private _affiliateCampaignCode;
|
|
46
|
+
private _deviceId;
|
|
47
|
+
private _packageName;
|
|
48
|
+
affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
|
|
9
49
|
private constructor();
|
|
10
50
|
static getInstance(): GoMarketMe;
|
|
11
51
|
initialize(apiKey: string): Promise<void>;
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private isSDKInitialized;
|
|
52
|
+
private _addListener;
|
|
53
|
+
private _getSystemInfo;
|
|
54
|
+
private _postSDKInitialization;
|
|
55
|
+
private _postSystemInfo;
|
|
56
|
+
private _readAndroidDeviceInfo;
|
|
57
|
+
private _readIosDeviceInfo;
|
|
58
|
+
private _getTimeZone;
|
|
59
|
+
private _getLanguageCode;
|
|
60
|
+
private _fetchConsolidatedPurchases;
|
|
61
|
+
private _sendEventToServer;
|
|
62
|
+
private _serializePurchaseDetails;
|
|
63
|
+
private _serializeProductDetails;
|
|
64
|
+
private _serializeSubscriptionDetails;
|
|
65
|
+
private _markSDKAsInitialized;
|
|
66
|
+
private _isSDKInitialized;
|
|
28
67
|
}
|
|
29
68
|
declare const _default: GoMarketMe;
|
|
30
69
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -39,21 +62,85 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
63
|
};
|
|
41
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.SaleDistribution = exports.Affiliate = exports.Campaign = exports.GoMarketMeAffiliateMarketingData = void 0;
|
|
42
66
|
var react_native_1 = require("react-native");
|
|
43
67
|
var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
|
|
44
68
|
var get_user_locale_1 = __importDefault(require("get-user-locale"));
|
|
45
69
|
var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
46
|
-
var
|
|
70
|
+
var RNIap = __importStar(require("react-native-iap"));
|
|
47
71
|
var axios_1 = __importDefault(require("axios"));
|
|
72
|
+
var GoMarketMeAffiliateMarketingData = /** @class */ (function () {
|
|
73
|
+
function GoMarketMeAffiliateMarketingData(campaign, affiliate, saleDistribution, affiliateCampaignCode, deviceId, offerCode) {
|
|
74
|
+
this.campaign = campaign;
|
|
75
|
+
this.affiliate = affiliate;
|
|
76
|
+
this.saleDistribution = saleDistribution;
|
|
77
|
+
this.affiliateCampaignCode = affiliateCampaignCode;
|
|
78
|
+
this.deviceId = deviceId;
|
|
79
|
+
this.offerCode = offerCode;
|
|
80
|
+
}
|
|
81
|
+
GoMarketMeAffiliateMarketingData.fromJson = function (json) {
|
|
82
|
+
// Check if the json is an empty object
|
|
83
|
+
if (Object.keys(json).length === 0) {
|
|
84
|
+
return null; // Return null or undefined, depending on your preference
|
|
85
|
+
}
|
|
86
|
+
return new GoMarketMeAffiliateMarketingData(Campaign.fromJson(json.campaign), Affiliate.fromJson(json.affiliate), SaleDistribution.fromJson(json.sale_distribution), json.affiliate_campaign_code || '', json.device_id || '', json.offer_code);
|
|
87
|
+
};
|
|
88
|
+
return GoMarketMeAffiliateMarketingData;
|
|
89
|
+
}());
|
|
90
|
+
exports.GoMarketMeAffiliateMarketingData = GoMarketMeAffiliateMarketingData;
|
|
91
|
+
var Campaign = /** @class */ (function () {
|
|
92
|
+
function Campaign(id, name, status, type, publicLinkUrl) {
|
|
93
|
+
this.id = id;
|
|
94
|
+
this.name = name;
|
|
95
|
+
this.status = status;
|
|
96
|
+
this.type = type;
|
|
97
|
+
this.publicLinkUrl = publicLinkUrl;
|
|
98
|
+
}
|
|
99
|
+
Campaign.fromJson = function (json) {
|
|
100
|
+
return new Campaign(json.id || '', json.name || '', json.status || '', json.type || '', json.public_link_url);
|
|
101
|
+
};
|
|
102
|
+
return Campaign;
|
|
103
|
+
}());
|
|
104
|
+
exports.Campaign = Campaign;
|
|
105
|
+
var Affiliate = /** @class */ (function () {
|
|
106
|
+
function Affiliate(id, firstName, lastName, countryCode, instagramAccount, tiktokAccount, xAccount) {
|
|
107
|
+
this.id = id;
|
|
108
|
+
this.firstName = firstName;
|
|
109
|
+
this.lastName = lastName;
|
|
110
|
+
this.countryCode = countryCode;
|
|
111
|
+
this.instagramAccount = instagramAccount;
|
|
112
|
+
this.tiktokAccount = tiktokAccount;
|
|
113
|
+
this.xAccount = xAccount;
|
|
114
|
+
}
|
|
115
|
+
Affiliate.fromJson = function (json) {
|
|
116
|
+
return new Affiliate(json.id || '', json.first_name || '', json.last_name || '', json.country_code || '', json.instagram_account || '', json.tiktok_account || '', json.x_account || '');
|
|
117
|
+
};
|
|
118
|
+
return Affiliate;
|
|
119
|
+
}());
|
|
120
|
+
exports.Affiliate = Affiliate;
|
|
121
|
+
var SaleDistribution = /** @class */ (function () {
|
|
122
|
+
function SaleDistribution(platformPercentage, affiliatePercentage) {
|
|
123
|
+
this.platformPercentage = platformPercentage;
|
|
124
|
+
this.affiliatePercentage = affiliatePercentage;
|
|
125
|
+
}
|
|
126
|
+
SaleDistribution.fromJson = function (json) {
|
|
127
|
+
return new SaleDistribution(json.platform_percentage || '', json.affiliate_percentage || '');
|
|
128
|
+
};
|
|
129
|
+
return SaleDistribution;
|
|
130
|
+
}());
|
|
131
|
+
exports.SaleDistribution = SaleDistribution;
|
|
48
132
|
var GoMarketMe = /** @class */ (function () {
|
|
49
133
|
function GoMarketMe() {
|
|
134
|
+
this.sdkType = 'ReactNative';
|
|
135
|
+
this.sdkVersion = '2.0.0';
|
|
50
136
|
this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
137
|
+
this.sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
|
|
138
|
+
this.systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
|
|
139
|
+
this.eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
|
|
140
|
+
this._affiliateCampaignCode = '';
|
|
141
|
+
this._deviceId = '';
|
|
142
|
+
this._packageName = '';
|
|
143
|
+
this._getTimeZone = function () {
|
|
57
144
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
58
145
|
};
|
|
59
146
|
}
|
|
@@ -65,64 +152,68 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
65
152
|
};
|
|
66
153
|
GoMarketMe.prototype.initialize = function (apiKey) {
|
|
67
154
|
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
-
var isSDKInitialized, systemInfo, e_1;
|
|
69
|
-
return __generator(this, function (
|
|
70
|
-
switch (
|
|
155
|
+
var isSDKInitialized, systemInfo, _a, e_1;
|
|
156
|
+
return __generator(this, function (_b) {
|
|
157
|
+
switch (_b.label) {
|
|
71
158
|
case 0:
|
|
72
|
-
|
|
73
|
-
return [4 /*yield*/, this.
|
|
159
|
+
_b.trys.push([0, 7, , 8]);
|
|
160
|
+
return [4 /*yield*/, this._isSDKInitialized()];
|
|
74
161
|
case 1:
|
|
75
|
-
isSDKInitialized =
|
|
162
|
+
isSDKInitialized = _b.sent();
|
|
76
163
|
if (!!isSDKInitialized) return [3 /*break*/, 3];
|
|
77
|
-
return [4 /*yield*/, this.
|
|
164
|
+
return [4 /*yield*/, this._postSDKInitialization(apiKey)];
|
|
78
165
|
case 2:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case 3:
|
|
166
|
+
_b.sent();
|
|
167
|
+
_b.label = 3;
|
|
168
|
+
case 3:
|
|
169
|
+
this._packageName = react_native_device_info_1.default.getBundleId();
|
|
170
|
+
return [4 /*yield*/, this._getSystemInfo()];
|
|
82
171
|
case 4:
|
|
83
|
-
systemInfo =
|
|
84
|
-
|
|
172
|
+
systemInfo = _b.sent();
|
|
173
|
+
_a = this;
|
|
174
|
+
return [4 /*yield*/, this._postSystemInfo(systemInfo, apiKey)];
|
|
85
175
|
case 5:
|
|
86
|
-
_a.sent();
|
|
87
|
-
return [4 /*yield*/, this.
|
|
176
|
+
_a.affiliateMarketingData = _b.sent();
|
|
177
|
+
return [4 /*yield*/, this._addListener(apiKey)];
|
|
88
178
|
case 6:
|
|
89
|
-
|
|
179
|
+
_b.sent();
|
|
90
180
|
return [3 /*break*/, 8];
|
|
91
181
|
case 7:
|
|
92
|
-
e_1 =
|
|
93
|
-
console.
|
|
182
|
+
e_1 = _b.sent();
|
|
183
|
+
console.log('Error initializing GoMarketMe:', e_1);
|
|
94
184
|
return [3 /*break*/, 8];
|
|
95
185
|
case 8: return [2 /*return*/];
|
|
96
186
|
}
|
|
97
187
|
});
|
|
98
188
|
});
|
|
99
189
|
};
|
|
100
|
-
GoMarketMe.prototype.
|
|
190
|
+
GoMarketMe.prototype._addListener = function (apiKey) {
|
|
101
191
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
192
|
var _this = this;
|
|
103
193
|
return __generator(this, function (_a) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case 3: return [2 /*return*/];
|
|
118
|
-
}
|
|
194
|
+
try {
|
|
195
|
+
RNIap.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
switch (_a.label) {
|
|
198
|
+
case 0: return [4 /*yield*/, this._fetchConsolidatedPurchases([purchase], apiKey)];
|
|
199
|
+
case 1:
|
|
200
|
+
_a.sent();
|
|
201
|
+
return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}); });
|
|
205
|
+
RNIap.purchaseErrorListener(function (error) {
|
|
206
|
+
console.log('Purchase error:', error);
|
|
119
207
|
});
|
|
120
|
-
}
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
console.log('Error setting up IAP listeners:', e);
|
|
211
|
+
}
|
|
121
212
|
return [2 /*return*/];
|
|
122
213
|
});
|
|
123
214
|
});
|
|
124
215
|
};
|
|
125
|
-
GoMarketMe.prototype.
|
|
216
|
+
GoMarketMe.prototype._getSystemInfo = function () {
|
|
126
217
|
return __awaiter(this, void 0, void 0, function () {
|
|
127
218
|
var deviceData, _a, _b, devicePixelRatio, dimension, windowData;
|
|
128
219
|
var _c;
|
|
@@ -131,13 +222,14 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
131
222
|
case 0:
|
|
132
223
|
_b = (_a = react_native_1.Platform).select;
|
|
133
224
|
_c = {};
|
|
134
|
-
return [4 /*yield*/, this.
|
|
225
|
+
return [4 /*yield*/, this._readIosDeviceInfo()];
|
|
135
226
|
case 1:
|
|
136
227
|
_c.ios = _d.sent();
|
|
137
|
-
return [4 /*yield*/, this.
|
|
228
|
+
return [4 /*yield*/, this._readAndroidDeviceInfo()];
|
|
138
229
|
case 2:
|
|
139
230
|
deviceData = _b.apply(_a, [(_c.android = _d.sent(),
|
|
140
231
|
_c)]);
|
|
232
|
+
this._deviceId = deviceData['deviceId'];
|
|
141
233
|
devicePixelRatio = react_native_1.PixelRatio.get();
|
|
142
234
|
dimension = react_native_1.Dimensions.get('window');
|
|
143
235
|
windowData = {
|
|
@@ -148,14 +240,14 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
148
240
|
return [2 /*return*/, {
|
|
149
241
|
device_info: deviceData,
|
|
150
242
|
window_info: windowData,
|
|
151
|
-
time_zone: this.
|
|
152
|
-
language_code: this.
|
|
243
|
+
time_zone: this._getTimeZone(),
|
|
244
|
+
language_code: this._getLanguageCode(),
|
|
153
245
|
}];
|
|
154
246
|
}
|
|
155
247
|
});
|
|
156
248
|
});
|
|
157
249
|
};
|
|
158
|
-
GoMarketMe.prototype.
|
|
250
|
+
GoMarketMe.prototype._postSDKInitialization = function (apiKey) {
|
|
159
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
252
|
var response, e_2;
|
|
161
253
|
return __generator(this, function (_a) {
|
|
@@ -171,61 +263,64 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
171
263
|
case 1:
|
|
172
264
|
response = _a.sent();
|
|
173
265
|
if (!(response.status === 200)) return [3 /*break*/, 3];
|
|
174
|
-
return [4 /*yield*/, this.
|
|
266
|
+
return [4 /*yield*/, this._markSDKAsInitialized()];
|
|
175
267
|
case 2:
|
|
176
268
|
_a.sent();
|
|
177
269
|
return [3 /*break*/, 4];
|
|
178
270
|
case 3:
|
|
179
|
-
console.
|
|
271
|
+
console.log('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
180
272
|
_a.label = 4;
|
|
181
273
|
case 4: return [3 /*break*/, 6];
|
|
182
274
|
case 5:
|
|
183
275
|
e_2 = _a.sent();
|
|
184
|
-
console.
|
|
276
|
+
console.log('Error sending SDK information to server:', e_2);
|
|
185
277
|
return [3 /*break*/, 6];
|
|
186
278
|
case 6: return [2 /*return*/];
|
|
187
279
|
}
|
|
188
280
|
});
|
|
189
281
|
});
|
|
190
282
|
};
|
|
191
|
-
GoMarketMe.prototype.
|
|
283
|
+
GoMarketMe.prototype._postSystemInfo = function (data, apiKey) {
|
|
192
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
var
|
|
285
|
+
var output, response, e_3;
|
|
194
286
|
return __generator(this, function (_a) {
|
|
195
287
|
switch (_a.label) {
|
|
196
288
|
case 0:
|
|
197
|
-
|
|
198
|
-
|
|
289
|
+
output = null;
|
|
290
|
+
_a.label = 1;
|
|
291
|
+
case 1:
|
|
292
|
+
_a.trys.push([1, 3, , 4]);
|
|
293
|
+
data['sdk_type'] = this.sdkType;
|
|
294
|
+
data['sdk_version'] = this.sdkVersion;
|
|
295
|
+
data['package_name'] = this._packageName;
|
|
296
|
+
return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, data, {
|
|
199
297
|
headers: {
|
|
200
298
|
'Content-Type': 'application/json',
|
|
201
299
|
'x-api-key': apiKey,
|
|
202
300
|
},
|
|
203
301
|
})];
|
|
204
|
-
case
|
|
302
|
+
case 2:
|
|
205
303
|
response = _a.sent();
|
|
206
304
|
if (response.status === 200) {
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
this.
|
|
210
|
-
}
|
|
211
|
-
if (responseData.device_id) {
|
|
212
|
-
this.deviceId = responseData.device_id;
|
|
305
|
+
output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
|
|
306
|
+
if (output != null) {
|
|
307
|
+
this._affiliateCampaignCode = output.affiliateCampaignCode;
|
|
213
308
|
}
|
|
214
309
|
}
|
|
215
310
|
else {
|
|
216
|
-
console.
|
|
311
|
+
console.log('Failed to send system info. Status code:', response.status);
|
|
217
312
|
}
|
|
218
|
-
return [3 /*break*/,
|
|
219
|
-
case
|
|
313
|
+
return [3 /*break*/, 4];
|
|
314
|
+
case 3:
|
|
220
315
|
e_3 = _a.sent();
|
|
221
|
-
console.
|
|
222
|
-
return [3 /*break*/,
|
|
223
|
-
case
|
|
316
|
+
console.log('Error sending system info to server:', e_3);
|
|
317
|
+
return [3 /*break*/, 4];
|
|
318
|
+
case 4: return [2 /*return*/, output];
|
|
224
319
|
}
|
|
225
320
|
});
|
|
226
321
|
});
|
|
227
322
|
};
|
|
228
|
-
GoMarketMe.prototype.
|
|
323
|
+
GoMarketMe.prototype._readAndroidDeviceInfo = function () {
|
|
229
324
|
return __awaiter(this, void 0, void 0, function () {
|
|
230
325
|
var androidId, uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
|
|
231
326
|
return __generator(this, function (_a) {
|
|
@@ -272,7 +367,7 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
272
367
|
});
|
|
273
368
|
});
|
|
274
369
|
};
|
|
275
|
-
GoMarketMe.prototype.
|
|
370
|
+
GoMarketMe.prototype._readIosDeviceInfo = function () {
|
|
276
371
|
return __awaiter(this, void 0, void 0, function () {
|
|
277
372
|
var uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
|
|
278
373
|
return __generator(this, function (_a) {
|
|
@@ -315,95 +410,58 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
315
410
|
});
|
|
316
411
|
});
|
|
317
412
|
};
|
|
318
|
-
GoMarketMe.prototype.
|
|
413
|
+
GoMarketMe.prototype._getLanguageCode = function () {
|
|
319
414
|
return (0, get_user_locale_1.default)();
|
|
320
415
|
};
|
|
321
|
-
GoMarketMe.prototype.
|
|
416
|
+
GoMarketMe.prototype._fetchConsolidatedPurchases = function (purchaseDetailsList, apiKey) {
|
|
322
417
|
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
-
var
|
|
324
|
-
return __generator(this, function (
|
|
325
|
-
switch (
|
|
418
|
+
var _i, purchaseDetailsList_1, purchase, data, products, _a, products_1, product0, products_3, _b, products_2, product0;
|
|
419
|
+
return __generator(this, function (_c) {
|
|
420
|
+
switch (_c.label) {
|
|
326
421
|
case 0:
|
|
327
|
-
productIds = [];
|
|
328
422
|
_i = 0, purchaseDetailsList_1 = purchaseDetailsList;
|
|
329
|
-
|
|
423
|
+
_c.label = 1;
|
|
330
424
|
case 1:
|
|
331
|
-
if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/,
|
|
425
|
+
if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 8];
|
|
332
426
|
purchase = purchaseDetailsList_1[_i];
|
|
333
|
-
if (!purchase.transactionReceipt) return [3 /*break*/,
|
|
334
|
-
|
|
427
|
+
if (!purchase.transactionReceipt) return [3 /*break*/, 7];
|
|
428
|
+
data = this._serializePurchaseDetails(purchase);
|
|
429
|
+
data['products'] = [];
|
|
430
|
+
if (!(data.productID != '')) return [3 /*break*/, 5];
|
|
431
|
+
return [4 /*yield*/, RNIap.getProducts({ skus: [data.productID] })];
|
|
335
432
|
case 2:
|
|
336
|
-
|
|
337
|
-
if (
|
|
338
|
-
|
|
433
|
+
products = _c.sent();
|
|
434
|
+
if (!(products.length > 0)) return [3 /*break*/, 3];
|
|
435
|
+
for (_a = 0, products_1 = products; _a < products_1.length; _a++) {
|
|
436
|
+
product0 = products_1[_a];
|
|
437
|
+
data['products'].push(this._serializeProductDetails(product0));
|
|
339
438
|
}
|
|
340
|
-
|
|
341
|
-
case 3:
|
|
342
|
-
_i++;
|
|
343
|
-
return [3 /*break*/, 1];
|
|
344
|
-
case 4: return [2 /*return*/, productIds];
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
|
|
350
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
351
|
-
var products, _i, products_1, product, products_3, _a, products_2, product, e_4;
|
|
352
|
-
return __generator(this, function (_b) {
|
|
353
|
-
switch (_b.label) {
|
|
354
|
-
case 0:
|
|
355
|
-
_b.trys.push([0, 15, , 16]);
|
|
356
|
-
return [4 /*yield*/, react_native_iap_1.default.getProducts(productIds)];
|
|
357
|
-
case 1:
|
|
358
|
-
products = _b.sent();
|
|
359
|
-
if (!(products.length > 0)) return [3 /*break*/, 6];
|
|
360
|
-
_i = 0, products_1 = products;
|
|
361
|
-
_b.label = 2;
|
|
362
|
-
case 2:
|
|
363
|
-
if (!(_i < products_1.length)) return [3 /*break*/, 5];
|
|
364
|
-
product = products_1[_i];
|
|
365
|
-
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
|
|
366
|
-
case 3:
|
|
367
|
-
_b.sent();
|
|
368
|
-
_b.label = 4;
|
|
439
|
+
return [3 /*break*/, 5];
|
|
440
|
+
case 3: return [4 /*yield*/, RNIap.getSubscriptions({ skus: [data.productID] })];
|
|
369
441
|
case 4:
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
442
|
+
products_3 = _c.sent();
|
|
443
|
+
if (products_3.length > 0) {
|
|
444
|
+
for (_b = 0, products_2 = products_3; _b < products_2.length; _b++) {
|
|
445
|
+
product0 = products_2[_b];
|
|
446
|
+
data['products'].push(this._serializeSubscriptionDetails(product0));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
_c.label = 5;
|
|
450
|
+
case 5: return [4 /*yield*/, this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey)];
|
|
451
|
+
case 6:
|
|
452
|
+
_c.sent();
|
|
453
|
+
_c.label = 7;
|
|
374
454
|
case 7:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
_b.label = 8;
|
|
379
|
-
case 8:
|
|
380
|
-
if (!(_a < products_2.length)) return [3 /*break*/, 11];
|
|
381
|
-
product = products_2[_a];
|
|
382
|
-
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeSubscriptionDetails(product)), 'product', apiKey)];
|
|
383
|
-
case 9:
|
|
384
|
-
_b.sent();
|
|
385
|
-
_b.label = 10;
|
|
386
|
-
case 10:
|
|
387
|
-
_a++;
|
|
388
|
-
return [3 /*break*/, 8];
|
|
389
|
-
case 11: return [3 /*break*/, 14];
|
|
390
|
-
case 12: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
|
|
391
|
-
case 13:
|
|
392
|
-
_b.sent();
|
|
393
|
-
_b.label = 14;
|
|
394
|
-
case 14: return [3 /*break*/, 16];
|
|
395
|
-
case 15:
|
|
396
|
-
e_4 = _b.sent();
|
|
397
|
-
console.error('Error fetching products:', e_4);
|
|
398
|
-
return [3 /*break*/, 16];
|
|
399
|
-
case 16: return [2 /*return*/];
|
|
455
|
+
_i++;
|
|
456
|
+
return [3 /*break*/, 1];
|
|
457
|
+
case 8: return [2 /*return*/];
|
|
400
458
|
}
|
|
401
459
|
});
|
|
402
460
|
});
|
|
403
461
|
};
|
|
404
|
-
GoMarketMe.prototype.
|
|
462
|
+
GoMarketMe.prototype._sendEventToServer = function (body, eventType, apiKey) {
|
|
405
463
|
return __awaiter(this, void 0, void 0, function () {
|
|
406
|
-
var response,
|
|
464
|
+
var response, e_4;
|
|
407
465
|
return __generator(this, function (_a) {
|
|
408
466
|
switch (_a.label) {
|
|
409
467
|
case 0:
|
|
@@ -411,8 +469,8 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
411
469
|
return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
|
|
412
470
|
headers: {
|
|
413
471
|
'Content-Type': 'application/json',
|
|
414
|
-
'x-affiliate-campaign-code': this.
|
|
415
|
-
'x-device-id': this.
|
|
472
|
+
'x-affiliate-campaign-code': this._affiliateCampaignCode,
|
|
473
|
+
'x-device-id': this._deviceId,
|
|
416
474
|
'x-event-type': eventType,
|
|
417
475
|
'x-product-type': react_native_1.Platform.OS,
|
|
418
476
|
'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
@@ -425,20 +483,21 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
425
483
|
console.log("".concat(eventType, " sent successfully"));
|
|
426
484
|
}
|
|
427
485
|
else {
|
|
428
|
-
console.
|
|
486
|
+
console.log("Failed to send ".concat(eventType, ". Status code:"), response.status);
|
|
429
487
|
}
|
|
430
488
|
return [3 /*break*/, 3];
|
|
431
489
|
case 2:
|
|
432
|
-
|
|
433
|
-
console.
|
|
490
|
+
e_4 = _a.sent();
|
|
491
|
+
console.log("Error sending ".concat(eventType, " to server:"), e_4);
|
|
434
492
|
return [3 /*break*/, 3];
|
|
435
493
|
case 3: return [2 /*return*/];
|
|
436
494
|
}
|
|
437
495
|
});
|
|
438
496
|
});
|
|
439
497
|
};
|
|
440
|
-
GoMarketMe.prototype.
|
|
498
|
+
GoMarketMe.prototype._serializePurchaseDetails = function (purchase) {
|
|
441
499
|
return {
|
|
500
|
+
packageName: this._packageName,
|
|
442
501
|
productID: purchase.productId,
|
|
443
502
|
purchaseID: purchase.transactionId || '',
|
|
444
503
|
transactionDate: purchase.transactionDate || '',
|
|
@@ -448,32 +507,60 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
448
507
|
}),
|
|
449
508
|
verificationData: {
|
|
450
509
|
localVerificationData: purchase.transactionReceipt,
|
|
510
|
+
serverVerificationData: purchase.transactionReceipt,
|
|
511
|
+
source: react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
451
512
|
},
|
|
513
|
+
pendingCompletePurchase: '',
|
|
514
|
+
error: {},
|
|
515
|
+
hashCode: '',
|
|
516
|
+
_purchase: purchase
|
|
452
517
|
};
|
|
453
518
|
};
|
|
454
|
-
GoMarketMe.prototype.
|
|
519
|
+
GoMarketMe.prototype._serializeProductDetails = function (product) {
|
|
455
520
|
return {
|
|
521
|
+
packageName: this._packageName,
|
|
456
522
|
productID: product.productId,
|
|
457
523
|
productTitle: product.title,
|
|
458
524
|
productDescription: product.description,
|
|
459
|
-
productPrice: product.
|
|
525
|
+
productPrice: product.localizedPrice,
|
|
460
526
|
productRawPrice: product.price,
|
|
527
|
+
productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
|
|
461
528
|
productCurrencyCode: product.currency,
|
|
529
|
+
hashCode: '',
|
|
530
|
+
_product: product
|
|
462
531
|
};
|
|
463
532
|
};
|
|
464
|
-
GoMarketMe.prototype.
|
|
465
|
-
|
|
533
|
+
GoMarketMe.prototype._serializeSubscriptionDetails = function (subscription) {
|
|
534
|
+
var _a;
|
|
535
|
+
var output = {
|
|
466
536
|
productID: subscription.productId,
|
|
467
537
|
productTitle: subscription.title,
|
|
468
538
|
productDescription: subscription.description,
|
|
469
|
-
|
|
470
|
-
productRawPrice: subscription.price,
|
|
471
|
-
productCurrencyCode: subscription.currency,
|
|
539
|
+
hashCode: '',
|
|
472
540
|
};
|
|
541
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
542
|
+
var subscriptionIOS = subscription;
|
|
543
|
+
output.productPrice = subscriptionIOS.localizedPrice;
|
|
544
|
+
output.productRawPrice = subscriptionIOS.price;
|
|
545
|
+
output.productCurrencyCode = subscriptionIOS.currency;
|
|
546
|
+
output._subscription = subscriptionIOS;
|
|
547
|
+
}
|
|
548
|
+
else if (react_native_1.Platform.OS === 'android') {
|
|
549
|
+
var subscriptionAndroid = subscription;
|
|
550
|
+
if ((_a = subscriptionAndroid.subscriptionOfferDetails) === null || _a === void 0 ? void 0 : _a.length) {
|
|
551
|
+
var offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
|
|
552
|
+
var priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
|
|
553
|
+
output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
|
|
554
|
+
output.productRawPrice = String(priceAmountMicros / 1000000);
|
|
555
|
+
output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
|
|
556
|
+
}
|
|
557
|
+
output._subscription = subscriptionAndroid;
|
|
558
|
+
}
|
|
559
|
+
return output;
|
|
473
560
|
};
|
|
474
|
-
GoMarketMe.prototype.
|
|
561
|
+
GoMarketMe.prototype._markSDKAsInitialized = function () {
|
|
475
562
|
return __awaiter(this, void 0, void 0, function () {
|
|
476
|
-
var
|
|
563
|
+
var e_5;
|
|
477
564
|
return __generator(this, function (_a) {
|
|
478
565
|
switch (_a.label) {
|
|
479
566
|
case 0:
|
|
@@ -483,17 +570,17 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
483
570
|
_a.sent();
|
|
484
571
|
return [2 /*return*/, true];
|
|
485
572
|
case 2:
|
|
486
|
-
|
|
487
|
-
console.
|
|
573
|
+
e_5 = _a.sent();
|
|
574
|
+
console.log('Failed to save SDK initialization:', e_5);
|
|
488
575
|
return [2 /*return*/, false];
|
|
489
576
|
case 3: return [2 /*return*/];
|
|
490
577
|
}
|
|
491
578
|
});
|
|
492
579
|
});
|
|
493
580
|
};
|
|
494
|
-
GoMarketMe.prototype.
|
|
581
|
+
GoMarketMe.prototype._isSDKInitialized = function () {
|
|
495
582
|
return __awaiter(this, void 0, void 0, function () {
|
|
496
|
-
var value,
|
|
583
|
+
var value, e_6;
|
|
497
584
|
return __generator(this, function (_a) {
|
|
498
585
|
switch (_a.label) {
|
|
499
586
|
case 0:
|
|
@@ -503,8 +590,8 @@ var GoMarketMe = /** @class */ (function () {
|
|
|
503
590
|
value = _a.sent();
|
|
504
591
|
return [2 /*return*/, value === 'true'];
|
|
505
592
|
case 2:
|
|
506
|
-
|
|
507
|
-
console.
|
|
593
|
+
e_6 = _a.sent();
|
|
594
|
+
console.log('Failed to load SDK initialization:', e_6);
|
|
508
595
|
return [2 /*return*/, false];
|
|
509
596
|
case 3: return [2 /*return*/];
|
|
510
597
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gomarketme-react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"axios": "^0.21.1",
|
|
23
23
|
"get-user-locale": "^2.3.2",
|
|
24
24
|
"react-native-device-info": "^14.0.0",
|
|
25
|
-
"react-native-iap": "^
|
|
25
|
+
"react-native-iap": "^12.16.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^15.12.5",
|
package/src/index.tsx
CHANGED
|
@@ -2,19 +2,146 @@ import { Platform, Dimensions, PixelRatio } from 'react-native';
|
|
|
2
2
|
import DeviceInfo from 'react-native-device-info';
|
|
3
3
|
import getUserLocale from 'get-user-locale'
|
|
4
4
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
5
|
-
import
|
|
5
|
+
import * as RNIap from 'react-native-iap';
|
|
6
6
|
import axios from 'axios';
|
|
7
|
+
export class GoMarketMeAffiliateMarketingData {
|
|
8
|
+
campaign: Campaign;
|
|
9
|
+
affiliate: Affiliate;
|
|
10
|
+
saleDistribution: SaleDistribution;
|
|
11
|
+
affiliateCampaignCode: string;
|
|
12
|
+
deviceId: string;
|
|
13
|
+
offerCode?: string;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
campaign: Campaign,
|
|
17
|
+
affiliate: Affiliate,
|
|
18
|
+
saleDistribution: SaleDistribution,
|
|
19
|
+
affiliateCampaignCode: string,
|
|
20
|
+
deviceId: string,
|
|
21
|
+
offerCode?: string
|
|
22
|
+
) {
|
|
23
|
+
this.campaign = campaign;
|
|
24
|
+
this.affiliate = affiliate;
|
|
25
|
+
this.saleDistribution = saleDistribution;
|
|
26
|
+
this.affiliateCampaignCode = affiliateCampaignCode;
|
|
27
|
+
this.deviceId = deviceId;
|
|
28
|
+
this.offerCode = offerCode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null {
|
|
32
|
+
// Check if the json is an empty object
|
|
33
|
+
if (Object.keys(json).length === 0) {
|
|
34
|
+
return null; // Return null or undefined, depending on your preference
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new GoMarketMeAffiliateMarketingData(
|
|
38
|
+
Campaign.fromJson(json.campaign),
|
|
39
|
+
Affiliate.fromJson(json.affiliate),
|
|
40
|
+
SaleDistribution.fromJson(json.sale_distribution),
|
|
41
|
+
json.affiliate_campaign_code || '',
|
|
42
|
+
json.device_id || '',
|
|
43
|
+
json.offer_code
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class Campaign {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
status: string;
|
|
52
|
+
type: string;
|
|
53
|
+
publicLinkUrl?: string;
|
|
54
|
+
|
|
55
|
+
constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string) {
|
|
56
|
+
this.id = id;
|
|
57
|
+
this.name = name;
|
|
58
|
+
this.status = status;
|
|
59
|
+
this.type = type;
|
|
60
|
+
this.publicLinkUrl = publicLinkUrl;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static fromJson(json: Record<string, any>): Campaign {
|
|
64
|
+
return new Campaign(
|
|
65
|
+
json.id || '',
|
|
66
|
+
json.name || '',
|
|
67
|
+
json.status || '',
|
|
68
|
+
json.type || '',
|
|
69
|
+
json.public_link_url
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class Affiliate {
|
|
75
|
+
id: string;
|
|
76
|
+
firstName: string;
|
|
77
|
+
lastName: string;
|
|
78
|
+
countryCode: string;
|
|
79
|
+
instagramAccount: string;
|
|
80
|
+
tiktokAccount: string;
|
|
81
|
+
xAccount: string;
|
|
82
|
+
|
|
83
|
+
constructor(
|
|
84
|
+
id: string,
|
|
85
|
+
firstName: string,
|
|
86
|
+
lastName: string,
|
|
87
|
+
countryCode: string,
|
|
88
|
+
instagramAccount: string,
|
|
89
|
+
tiktokAccount: string,
|
|
90
|
+
xAccount: string
|
|
91
|
+
) {
|
|
92
|
+
this.id = id;
|
|
93
|
+
this.firstName = firstName;
|
|
94
|
+
this.lastName = lastName;
|
|
95
|
+
this.countryCode = countryCode;
|
|
96
|
+
this.instagramAccount = instagramAccount;
|
|
97
|
+
this.tiktokAccount = tiktokAccount;
|
|
98
|
+
this.xAccount = xAccount;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static fromJson(json: Record<string, any>): Affiliate {
|
|
102
|
+
return new Affiliate(
|
|
103
|
+
json.id || '',
|
|
104
|
+
json.first_name || '',
|
|
105
|
+
json.last_name || '',
|
|
106
|
+
json.country_code || '',
|
|
107
|
+
json.instagram_account || '',
|
|
108
|
+
json.tiktok_account || '',
|
|
109
|
+
json.x_account || ''
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class SaleDistribution {
|
|
115
|
+
platformPercentage: string;
|
|
116
|
+
affiliatePercentage: string;
|
|
117
|
+
|
|
118
|
+
constructor(platformPercentage: string, affiliatePercentage: string) {
|
|
119
|
+
this.platformPercentage = platformPercentage;
|
|
120
|
+
this.affiliatePercentage = affiliatePercentage;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static fromJson(json: Record<string, any>): SaleDistribution {
|
|
124
|
+
return new SaleDistribution(
|
|
125
|
+
json.platform_percentage || '',
|
|
126
|
+
json.affiliate_percentage || ''
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
7
130
|
|
|
8
131
|
class GoMarketMe {
|
|
9
132
|
private static instance: GoMarketMe;
|
|
133
|
+
private sdkType = 'ReactNative';
|
|
134
|
+
private sdkVersion = '2.0.0';
|
|
10
135
|
private sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
136
|
+
private sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
|
|
137
|
+
private systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
|
|
138
|
+
private eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
|
|
139
|
+
private _affiliateCampaignCode = '';
|
|
140
|
+
private _deviceId = '';
|
|
141
|
+
private _packageName = ''
|
|
142
|
+
public affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
|
|
16
143
|
|
|
17
|
-
private constructor() {}
|
|
144
|
+
private constructor() { }
|
|
18
145
|
|
|
19
146
|
public static getInstance(): GoMarketMe {
|
|
20
147
|
if (!GoMarketMe.instance) {
|
|
@@ -25,51 +152,59 @@ class GoMarketMe {
|
|
|
25
152
|
|
|
26
153
|
public async initialize(apiKey: string): Promise<void> {
|
|
27
154
|
try {
|
|
28
|
-
const isSDKInitialized = await this.
|
|
155
|
+
const isSDKInitialized = await this._isSDKInitialized();
|
|
29
156
|
if (!isSDKInitialized) {
|
|
30
|
-
await this.
|
|
157
|
+
await this._postSDKInitialization(apiKey);
|
|
31
158
|
}
|
|
32
|
-
|
|
33
|
-
await this.
|
|
34
|
-
await this.
|
|
159
|
+
this._packageName = DeviceInfo.getBundleId();
|
|
160
|
+
const systemInfo = await this._getSystemInfo();
|
|
161
|
+
this.affiliateMarketingData = await this._postSystemInfo(systemInfo, apiKey);
|
|
162
|
+
await this._addListener(apiKey);
|
|
35
163
|
} catch (e) {
|
|
36
|
-
console.
|
|
164
|
+
console.log('Error initializing GoMarketMe:', e);
|
|
37
165
|
}
|
|
38
166
|
}
|
|
39
167
|
|
|
40
|
-
private async
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
168
|
+
private async _addListener(apiKey: string): Promise<void> {
|
|
169
|
+
try {
|
|
170
|
+
RNIap.purchaseUpdatedListener(async (purchase: RNIap.Purchase) => {
|
|
171
|
+
await this._fetchConsolidatedPurchases([purchase], apiKey);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
RNIap.purchaseErrorListener((error) => {
|
|
175
|
+
console.log('Purchase error:', error);
|
|
176
|
+
});
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.log('Error setting up IAP listeners:', e);
|
|
179
|
+
}
|
|
47
180
|
}
|
|
48
181
|
|
|
49
|
-
private async
|
|
182
|
+
private async _getSystemInfo(): Promise<any> {
|
|
50
183
|
const deviceData = Platform.select({
|
|
51
|
-
ios: await this.
|
|
52
|
-
android: await this.
|
|
184
|
+
ios: await this._readIosDeviceInfo(),
|
|
185
|
+
android: await this._readAndroidDeviceInfo(),
|
|
53
186
|
});
|
|
54
|
-
|
|
187
|
+
|
|
188
|
+
this._deviceId = deviceData['deviceId'];
|
|
189
|
+
|
|
55
190
|
const devicePixelRatio = PixelRatio.get();
|
|
56
191
|
const dimension = Dimensions.get('window');
|
|
57
|
-
|
|
192
|
+
|
|
58
193
|
const windowData = {
|
|
59
194
|
devicePixelRatio: devicePixelRatio,
|
|
60
195
|
width: dimension.width * devicePixelRatio,
|
|
61
196
|
height: dimension.height * devicePixelRatio,
|
|
62
197
|
};
|
|
63
|
-
|
|
198
|
+
|
|
64
199
|
return {
|
|
65
200
|
device_info: deviceData,
|
|
66
201
|
window_info: windowData,
|
|
67
|
-
time_zone: this.
|
|
68
|
-
language_code: this.
|
|
202
|
+
time_zone: this._getTimeZone(),
|
|
203
|
+
language_code: this._getLanguageCode(),
|
|
69
204
|
};
|
|
70
205
|
}
|
|
71
206
|
|
|
72
|
-
private async
|
|
207
|
+
private async _postSDKInitialization(apiKey: string): Promise<void> {
|
|
73
208
|
try {
|
|
74
209
|
const response = await axios.post(this.sdkInitializationUrl, {}, {
|
|
75
210
|
headers: {
|
|
@@ -78,41 +213,42 @@ class GoMarketMe {
|
|
|
78
213
|
},
|
|
79
214
|
});
|
|
80
215
|
if (response.status === 200) {
|
|
81
|
-
await this.
|
|
216
|
+
await this._markSDKAsInitialized();
|
|
82
217
|
} else {
|
|
83
|
-
console.
|
|
218
|
+
console.log('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
84
219
|
}
|
|
85
220
|
} catch (e) {
|
|
86
|
-
console.
|
|
221
|
+
console.log('Error sending SDK information to server:', e);
|
|
87
222
|
}
|
|
88
223
|
}
|
|
89
224
|
|
|
90
|
-
private async
|
|
225
|
+
private async _postSystemInfo(data: any, apiKey: string): Promise<GoMarketMeAffiliateMarketingData | null> {
|
|
226
|
+
let output: GoMarketMeAffiliateMarketingData | null = null;
|
|
91
227
|
try {
|
|
92
|
-
|
|
228
|
+
data['sdk_type'] = this.sdkType;
|
|
229
|
+
data['sdk_version'] = this.sdkVersion;
|
|
230
|
+
data['package_name'] = this._packageName;
|
|
231
|
+
const response = await axios.post(this.systemInfoUrl, data, {
|
|
93
232
|
headers: {
|
|
94
233
|
'Content-Type': 'application/json',
|
|
95
234
|
'x-api-key': apiKey,
|
|
96
235
|
},
|
|
97
236
|
});
|
|
98
237
|
if (response.status === 200) {
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
this.
|
|
102
|
-
}
|
|
103
|
-
if (responseData.device_id) {
|
|
104
|
-
this.deviceId = responseData.device_id;
|
|
238
|
+
output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
|
|
239
|
+
if (output != null) {
|
|
240
|
+
this._affiliateCampaignCode = output.affiliateCampaignCode;
|
|
105
241
|
}
|
|
106
|
-
|
|
107
242
|
} else {
|
|
108
|
-
console.
|
|
243
|
+
console.log('Failed to send system info. Status code:', response.status);
|
|
109
244
|
}
|
|
110
245
|
} catch (e) {
|
|
111
|
-
console.
|
|
246
|
+
console.log('Error sending system info to server:', e);
|
|
112
247
|
}
|
|
248
|
+
return output;
|
|
113
249
|
}
|
|
114
250
|
|
|
115
|
-
private async
|
|
251
|
+
private async _readAndroidDeviceInfo(): Promise<any> {
|
|
116
252
|
|
|
117
253
|
let androidId = await DeviceInfo.getAndroidId();
|
|
118
254
|
let uniqueId = await DeviceInfo.getUniqueId();
|
|
@@ -137,7 +273,7 @@ class GoMarketMe {
|
|
|
137
273
|
};
|
|
138
274
|
}
|
|
139
275
|
|
|
140
|
-
private async
|
|
276
|
+
private async _readIosDeviceInfo(): Promise<any> {
|
|
141
277
|
|
|
142
278
|
let uniqueId = await DeviceInfo.getUniqueId();
|
|
143
279
|
let deviceId = await DeviceInfo.getDeviceId(); // model
|
|
@@ -160,56 +296,47 @@ class GoMarketMe {
|
|
|
160
296
|
};
|
|
161
297
|
}
|
|
162
298
|
|
|
163
|
-
private
|
|
299
|
+
private _getTimeZone = (): string => {
|
|
164
300
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
165
|
-
};
|
|
301
|
+
};
|
|
166
302
|
|
|
167
|
-
private
|
|
303
|
+
private _getLanguageCode(): string {
|
|
168
304
|
return getUserLocale();
|
|
169
305
|
}
|
|
170
306
|
|
|
171
|
-
private async
|
|
172
|
-
const productIds: string[] = [];
|
|
307
|
+
private async _fetchConsolidatedPurchases(purchaseDetailsList: RNIap.Purchase[], apiKey: string): Promise<void> {
|
|
173
308
|
for (const purchase of purchaseDetailsList) {
|
|
174
309
|
if (purchase.transactionReceipt) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} else {
|
|
192
|
-
const products = await InAppPurchase.getSubscriptions(productIds);
|
|
193
|
-
if (products.length > 0) {
|
|
194
|
-
for (const product of products) {
|
|
195
|
-
await this.sendEventToServer(JSON.stringify(this.serializeSubscriptionDetails(product)), 'product', apiKey);
|
|
310
|
+
var data = this._serializePurchaseDetails(purchase);
|
|
311
|
+
data['products'] = []
|
|
312
|
+
if (data.productID != '') {
|
|
313
|
+
const products = await RNIap.getProducts({ skus: [data.productID] })
|
|
314
|
+
if (products.length > 0) {
|
|
315
|
+
for (const product0 of products) {
|
|
316
|
+
data['products'].push(this._serializeProductDetails(product0))
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const products = await RNIap.getSubscriptions({ skus: [data.productID] });
|
|
321
|
+
if (products.length > 0) {
|
|
322
|
+
for (const product0 of products) {
|
|
323
|
+
data['products'].push(this._serializeSubscriptionDetails(product0))
|
|
324
|
+
}
|
|
325
|
+
}
|
|
196
326
|
}
|
|
197
|
-
} else {
|
|
198
|
-
await this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey);
|
|
199
327
|
}
|
|
328
|
+
await this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey);
|
|
200
329
|
}
|
|
201
|
-
} catch (e) {
|
|
202
|
-
console.error('Error fetching products:', e);
|
|
203
330
|
}
|
|
204
331
|
}
|
|
205
332
|
|
|
206
|
-
private async
|
|
333
|
+
private async _sendEventToServer(body: string, eventType: string, apiKey: string): Promise<void> {
|
|
207
334
|
try {
|
|
208
335
|
const response = await axios.post(this.eventUrl, body, {
|
|
209
336
|
headers: {
|
|
210
337
|
'Content-Type': 'application/json',
|
|
211
|
-
'x-affiliate-campaign-code': this.
|
|
212
|
-
'x-device-id': this.
|
|
338
|
+
'x-affiliate-campaign-code': this._affiliateCampaignCode,
|
|
339
|
+
'x-device-id': this._deviceId,
|
|
213
340
|
'x-event-type': eventType,
|
|
214
341
|
'x-product-type': Platform.OS,
|
|
215
342
|
'x-source-name': Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
@@ -219,15 +346,16 @@ class GoMarketMe {
|
|
|
219
346
|
if (response.status === 200) {
|
|
220
347
|
console.log(`${eventType} sent successfully`);
|
|
221
348
|
} else {
|
|
222
|
-
console.
|
|
349
|
+
console.log(`Failed to send ${eventType}. Status code:`, response.status);
|
|
223
350
|
}
|
|
224
351
|
} catch (e) {
|
|
225
|
-
console.
|
|
352
|
+
console.log(`Error sending ${eventType} to server:`, e);
|
|
226
353
|
}
|
|
227
354
|
}
|
|
228
355
|
|
|
229
|
-
private
|
|
356
|
+
private _serializePurchaseDetails(purchase: RNIap.Purchase): any {
|
|
230
357
|
return {
|
|
358
|
+
packageName: this._packageName,
|
|
231
359
|
productID: purchase.productId,
|
|
232
360
|
purchaseID: purchase.transactionId || '',
|
|
233
361
|
transactionDate: purchase.transactionDate || '',
|
|
@@ -237,48 +365,76 @@ class GoMarketMe {
|
|
|
237
365
|
}),
|
|
238
366
|
verificationData: {
|
|
239
367
|
localVerificationData: purchase.transactionReceipt,
|
|
368
|
+
serverVerificationData: purchase.transactionReceipt,
|
|
369
|
+
source: Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
240
370
|
},
|
|
371
|
+
pendingCompletePurchase: '',
|
|
372
|
+
error: {},
|
|
373
|
+
hashCode: '',
|
|
374
|
+
_purchase: purchase
|
|
241
375
|
};
|
|
242
376
|
}
|
|
243
377
|
|
|
244
|
-
private
|
|
378
|
+
private _serializeProductDetails(product: RNIap.Product): any {
|
|
245
379
|
return {
|
|
380
|
+
packageName: this._packageName,
|
|
246
381
|
productID: product.productId,
|
|
247
382
|
productTitle: product.title,
|
|
248
383
|
productDescription: product.description,
|
|
249
|
-
productPrice: product.
|
|
384
|
+
productPrice: product.localizedPrice,
|
|
250
385
|
productRawPrice: product.price,
|
|
386
|
+
productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
|
|
251
387
|
productCurrencyCode: product.currency,
|
|
388
|
+
hashCode: '',
|
|
389
|
+
_product: product
|
|
252
390
|
};
|
|
253
391
|
}
|
|
254
392
|
|
|
255
|
-
private
|
|
256
|
-
|
|
393
|
+
private _serializeSubscriptionDetails(subscription: RNIap.Subscription): any {
|
|
394
|
+
let output: any = {
|
|
257
395
|
productID: subscription.productId,
|
|
258
396
|
productTitle: subscription.title,
|
|
259
397
|
productDescription: subscription.description,
|
|
260
|
-
|
|
261
|
-
productRawPrice: subscription.price,
|
|
262
|
-
productCurrencyCode: subscription.currency,
|
|
398
|
+
hashCode: '',
|
|
263
399
|
};
|
|
400
|
+
|
|
401
|
+
if (Platform.OS === 'ios') {
|
|
402
|
+
const subscriptionIOS = subscription as RNIap.SubscriptionIOS;
|
|
403
|
+
output.productPrice = subscriptionIOS.localizedPrice;
|
|
404
|
+
output.productRawPrice = subscriptionIOS.price;
|
|
405
|
+
output.productCurrencyCode = subscriptionIOS.currency;
|
|
406
|
+
output._subscription = subscriptionIOS;
|
|
407
|
+
} else if (Platform.OS === 'android') {
|
|
408
|
+
const subscriptionAndroid = subscription as RNIap.SubscriptionAndroid;
|
|
409
|
+
if (subscriptionAndroid.subscriptionOfferDetails?.length) {
|
|
410
|
+
const offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
|
|
411
|
+
const priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
|
|
412
|
+
output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
|
|
413
|
+
output.productRawPrice = String(priceAmountMicros / 1_000_000);
|
|
414
|
+
output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
|
|
415
|
+
}
|
|
416
|
+
output._subscription = subscriptionAndroid;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return output;
|
|
264
420
|
}
|
|
265
421
|
|
|
266
|
-
private async
|
|
422
|
+
private async _markSDKAsInitialized(): Promise<boolean> {
|
|
267
423
|
try {
|
|
268
424
|
await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
|
|
269
425
|
return true;
|
|
270
426
|
} catch (e) {
|
|
271
|
-
console.
|
|
427
|
+
console.log('Failed to save SDK initialization:', e);
|
|
272
428
|
return false;
|
|
273
429
|
}
|
|
274
430
|
}
|
|
275
431
|
|
|
276
|
-
private async
|
|
432
|
+
private async _isSDKInitialized(): Promise<boolean> {
|
|
277
433
|
try {
|
|
278
434
|
const value = await AsyncStorage.getItem(this.sdkInitializedKey);
|
|
279
435
|
return value === 'true';
|
|
280
436
|
} catch (e) {
|
|
281
|
-
console.
|
|
437
|
+
console.log('Failed to load SDK initialization:', e);
|
|
282
438
|
return false;
|
|
283
439
|
}
|
|
284
440
|
}
|