@bprotsyk/aso-core 2.1.113 → 2.1.115
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/lib/network/keitaro/traffle/traffle-keitaro-service.d.ts +95 -0
- package/lib/network/keitaro/traffle/traffle-keitaro-service.js +252 -24
- package/lib/offers/list.d.ts +18 -18
- package/lib/templates/words.txt +212 -0
- package/package.json +3 -2
- package/src/network/keitaro/traffle/traffle-keitaro-service.ts +284 -26
- package/src/templates/words.txt +212 -0
- package/test-keitaro.js +21 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
apple
|
|
2
|
+
banana
|
|
3
|
+
cherry
|
|
4
|
+
dragon
|
|
5
|
+
eagle
|
|
6
|
+
forest
|
|
7
|
+
garden
|
|
8
|
+
hammer
|
|
9
|
+
island
|
|
10
|
+
jungle
|
|
11
|
+
kitten
|
|
12
|
+
lemon
|
|
13
|
+
mountain
|
|
14
|
+
ocean
|
|
15
|
+
pencil
|
|
16
|
+
queen
|
|
17
|
+
river
|
|
18
|
+
sunset
|
|
19
|
+
tiger
|
|
20
|
+
umbrella
|
|
21
|
+
village
|
|
22
|
+
window
|
|
23
|
+
xylophone
|
|
24
|
+
yellow
|
|
25
|
+
zebra
|
|
26
|
+
adventure
|
|
27
|
+
beautiful
|
|
28
|
+
creative
|
|
29
|
+
delicious
|
|
30
|
+
excellent
|
|
31
|
+
fantastic
|
|
32
|
+
gorgeous
|
|
33
|
+
handsome
|
|
34
|
+
incredible
|
|
35
|
+
joyful
|
|
36
|
+
knowledge
|
|
37
|
+
luminous
|
|
38
|
+
magnificent
|
|
39
|
+
natural
|
|
40
|
+
outstanding
|
|
41
|
+
perfect
|
|
42
|
+
quality
|
|
43
|
+
radiant
|
|
44
|
+
spectacular
|
|
45
|
+
tremendous
|
|
46
|
+
ultimate
|
|
47
|
+
valuable
|
|
48
|
+
wonderful
|
|
49
|
+
amazing
|
|
50
|
+
brilliant
|
|
51
|
+
charming
|
|
52
|
+
delightful
|
|
53
|
+
elegant
|
|
54
|
+
fascinating
|
|
55
|
+
graceful
|
|
56
|
+
harmonious
|
|
57
|
+
inspiring
|
|
58
|
+
jubilant
|
|
59
|
+
kindhearted
|
|
60
|
+
loving
|
|
61
|
+
mysterious
|
|
62
|
+
nurturing
|
|
63
|
+
optimistic
|
|
64
|
+
peaceful
|
|
65
|
+
quintessential
|
|
66
|
+
radiant
|
|
67
|
+
serene
|
|
68
|
+
tranquil
|
|
69
|
+
uplifting
|
|
70
|
+
vibrant
|
|
71
|
+
whimsical
|
|
72
|
+
abundant
|
|
73
|
+
blessed
|
|
74
|
+
cheerful
|
|
75
|
+
dazzling
|
|
76
|
+
energetic
|
|
77
|
+
friendly
|
|
78
|
+
generous
|
|
79
|
+
hopeful
|
|
80
|
+
imaginative
|
|
81
|
+
jovial
|
|
82
|
+
knowledgeable
|
|
83
|
+
lively
|
|
84
|
+
majestic
|
|
85
|
+
noble
|
|
86
|
+
outstanding
|
|
87
|
+
passionate
|
|
88
|
+
quintessential
|
|
89
|
+
remarkable
|
|
90
|
+
splendid
|
|
91
|
+
treasured
|
|
92
|
+
unique
|
|
93
|
+
valuable
|
|
94
|
+
warmhearted
|
|
95
|
+
authentic
|
|
96
|
+
benevolent
|
|
97
|
+
charismatic
|
|
98
|
+
determined
|
|
99
|
+
enthusiastic
|
|
100
|
+
faithful
|
|
101
|
+
gracious
|
|
102
|
+
humble
|
|
103
|
+
inspiring
|
|
104
|
+
joyful
|
|
105
|
+
kind
|
|
106
|
+
loyal
|
|
107
|
+
magnificent
|
|
108
|
+
nurturing
|
|
109
|
+
optimistic
|
|
110
|
+
patient
|
|
111
|
+
quintessential
|
|
112
|
+
resilient
|
|
113
|
+
sincere
|
|
114
|
+
trustworthy
|
|
115
|
+
understanding
|
|
116
|
+
virtuous
|
|
117
|
+
wise
|
|
118
|
+
zealous
|
|
119
|
+
abundant
|
|
120
|
+
blessed
|
|
121
|
+
cheerful
|
|
122
|
+
dazzling
|
|
123
|
+
energetic
|
|
124
|
+
friendly
|
|
125
|
+
generous
|
|
126
|
+
hopeful
|
|
127
|
+
imaginative
|
|
128
|
+
jovial
|
|
129
|
+
knowledgeable
|
|
130
|
+
lively
|
|
131
|
+
majestic
|
|
132
|
+
noble
|
|
133
|
+
outstanding
|
|
134
|
+
passionate
|
|
135
|
+
quintessential
|
|
136
|
+
remarkable
|
|
137
|
+
splendid
|
|
138
|
+
treasured
|
|
139
|
+
unique
|
|
140
|
+
valuable
|
|
141
|
+
warmhearted
|
|
142
|
+
authentic
|
|
143
|
+
benevolent
|
|
144
|
+
charismatic
|
|
145
|
+
determined
|
|
146
|
+
enthusiastic
|
|
147
|
+
faithful
|
|
148
|
+
gracious
|
|
149
|
+
humble
|
|
150
|
+
inspiring
|
|
151
|
+
joyful
|
|
152
|
+
kind
|
|
153
|
+
loyal
|
|
154
|
+
magnificent
|
|
155
|
+
nurturing
|
|
156
|
+
optimistic
|
|
157
|
+
patient
|
|
158
|
+
quintessential
|
|
159
|
+
resilient
|
|
160
|
+
sincere
|
|
161
|
+
trustworthy
|
|
162
|
+
understanding
|
|
163
|
+
virtuous
|
|
164
|
+
wise
|
|
165
|
+
zealous
|
|
166
|
+
abundant
|
|
167
|
+
blessed
|
|
168
|
+
cheerful
|
|
169
|
+
dazzling
|
|
170
|
+
energetic
|
|
171
|
+
friendly
|
|
172
|
+
generous
|
|
173
|
+
hopeful
|
|
174
|
+
imaginative
|
|
175
|
+
jovial
|
|
176
|
+
knowledgeable
|
|
177
|
+
lively
|
|
178
|
+
majestic
|
|
179
|
+
noble
|
|
180
|
+
outstanding
|
|
181
|
+
passionate
|
|
182
|
+
quintessential
|
|
183
|
+
remarkable
|
|
184
|
+
splendid
|
|
185
|
+
treasured
|
|
186
|
+
unique
|
|
187
|
+
valuable
|
|
188
|
+
warmhearted
|
|
189
|
+
authentic
|
|
190
|
+
benevolent
|
|
191
|
+
charismatic
|
|
192
|
+
determined
|
|
193
|
+
enthusiastic
|
|
194
|
+
faithful
|
|
195
|
+
gracious
|
|
196
|
+
humble
|
|
197
|
+
inspiring
|
|
198
|
+
joyful
|
|
199
|
+
kind
|
|
200
|
+
loyal
|
|
201
|
+
magnificent
|
|
202
|
+
nurturing
|
|
203
|
+
optimistic
|
|
204
|
+
patient
|
|
205
|
+
quintessential
|
|
206
|
+
resilient
|
|
207
|
+
sincere
|
|
208
|
+
trustworthy
|
|
209
|
+
understanding
|
|
210
|
+
virtuous
|
|
211
|
+
wise
|
|
212
|
+
zealous
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bprotsyk/aso-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.115",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prod": "tsc -p ./tsconfig.json && copyfiles -u 1 src/templates/**/* lib/ && git add . && git commit -m \"Зміни до версії\" && git push origin master && npm version patch && npm publish",
|
|
8
|
-
"build": "tsc",
|
|
8
|
+
"build": "tsc && copyfiles -u 1 src/templates/**/* lib/",
|
|
9
|
+
"copy-templates": "copyfiles -u 1 src/templates/**/* lib/",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
11
|
"keitaro": "tsc; node lib/utils/keitaro-utils.js",
|
|
11
12
|
"traffle": "tsc; node lib/utils/traffle-keitaro-utils.js",
|
|
@@ -11,6 +11,8 @@ import { IKeitaroClicksRequest, IKeitaroClicksRangeRequest, KeitaroClicksInterva
|
|
|
11
11
|
import { OpenAI } from "../../../network/openai/openai";
|
|
12
12
|
import { off } from "process";
|
|
13
13
|
import { IKeitaroCampaignParameters } from "../../../keitaro/keitaro-campaign";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
14
16
|
|
|
15
17
|
async function getAllOffers(): Promise<IKeitaroOffer[]> {
|
|
16
18
|
const { data: offers } = await keitaroApi.get<IKeitaroOffer[]>('offers')
|
|
@@ -251,27 +253,15 @@ async function createCampaign(campaignData: Partial<IKeitaroCampaign>): Promise<
|
|
|
251
253
|
async function TrafleKeitaroParameters(parameters: any) {
|
|
252
254
|
const {bundle, appsflyerDevKey, name, originalParameters} = parameters
|
|
253
255
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
if (!openAIResponse) {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
let ParamsGenerationsOpenAIResponse: IParamsGenerationsOpenAIResponse | null = null;
|
|
266
|
-
try {
|
|
267
|
-
ParamsGenerationsOpenAIResponse = JSON.parse(openAIResponse);
|
|
268
|
-
} catch (error) {
|
|
269
|
-
console.error("Failed to parse OpenAI response:", error);
|
|
256
|
+
// Генеруємо параметри локально замість OpenAI
|
|
257
|
+
const localParameters = await generateLocalParameters();
|
|
258
|
+
|
|
259
|
+
if (!localParameters) {
|
|
260
|
+
console.error("Failed to generate local parameters");
|
|
270
261
|
return null;
|
|
271
262
|
}
|
|
272
263
|
|
|
273
|
-
console.log(`
|
|
274
|
-
|
|
264
|
+
console.log(`Local generated parameters: ${JSON.stringify(localParameters)}`)
|
|
275
265
|
|
|
276
266
|
return {
|
|
277
267
|
parameters: {
|
|
@@ -288,24 +278,24 @@ async function TrafleKeitaroParameters(parameters: any) {
|
|
|
288
278
|
sub_id_4: { name: 'DEV', placeholder: '', alias: '' },
|
|
289
279
|
sub_id_5: { name: 'LANG', placeholder: '', alias: '' },
|
|
290
280
|
sub_id_10: { name: 'market', placeholder: '', alias: '' },
|
|
291
|
-
sub_id_15: { name:
|
|
281
|
+
sub_id_15: { name: localParameters.naming, placeholder: '{naming}', alias: 'Naming' },
|
|
292
282
|
sub_id_16: {
|
|
293
283
|
name: 'bundle_id',
|
|
294
284
|
placeholder: bundle,
|
|
295
285
|
alias: 'Bundle ID'
|
|
296
286
|
},
|
|
297
287
|
sub_id_17: {
|
|
298
|
-
name:
|
|
288
|
+
name: localParameters.advertisingid,
|
|
299
289
|
placeholder: '{advertising_id}',
|
|
300
290
|
alias: 'Advertising ID'
|
|
301
291
|
},
|
|
302
292
|
sub_id_18: {
|
|
303
|
-
name:
|
|
293
|
+
name: localParameters.appsflyerDeviceID,
|
|
304
294
|
placeholder: '{appsflyer_device_id}',
|
|
305
295
|
alias: 'Appsflyer Device ID'
|
|
306
296
|
},
|
|
307
297
|
sub_id_19: {
|
|
308
|
-
name:
|
|
298
|
+
name: 'appsflyer_dev_key',
|
|
309
299
|
placeholder: appsflyerDevKey,
|
|
310
300
|
alias: 'Appsflyer Dev Key'
|
|
311
301
|
}
|
|
@@ -313,7 +303,271 @@ async function TrafleKeitaroParameters(parameters: any) {
|
|
|
313
303
|
}
|
|
314
304
|
}
|
|
315
305
|
|
|
306
|
+
async function generateLocalParameters(): Promise<IParamsGenerationsOpenAIResponse | null> {
|
|
307
|
+
try {
|
|
308
|
+
// Читаємо слова з файлу
|
|
309
|
+
const wordsFilePath = path.join(__dirname, '../../../templates/words.txt');
|
|
310
|
+
const wordsContent = fs.readFileSync(wordsFilePath, 'utf-8');
|
|
311
|
+
const words = wordsContent.split('\n').filter(word => word.trim().length > 0);
|
|
312
|
+
|
|
313
|
+
if (words.length === 0) {
|
|
314
|
+
console.error("No words found in words.txt file");
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Генеруємо випадкові індекси
|
|
319
|
+
const namingIndex = Math.floor(Math.random() * words.length);
|
|
320
|
+
const advertisingIdIndex = Math.floor(Math.random() * words.length);
|
|
321
|
+
const appsflyerDeviceIdIndex = Math.floor(Math.random() * words.length);
|
|
322
|
+
|
|
323
|
+
// Отримуємо випадкові слова
|
|
324
|
+
const naming = words[namingIndex];
|
|
325
|
+
const advertisingid = words[advertisingIdIndex];
|
|
326
|
+
const appsflyerDeviceID = words[appsflyerDeviceIdIndex];
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
naming,
|
|
330
|
+
advertisingid,
|
|
331
|
+
appsflyerDeviceID
|
|
332
|
+
};
|
|
333
|
+
} catch (error) {
|
|
334
|
+
console.error("Error reading words file:", error);
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function checkAndUpdateCampaignParameters(existingCampaign: IKeitaroCampaign, app: IApp, platform: EPlatform): Promise<boolean> {
|
|
340
|
+
// Отримуємо trackingParams з додатку
|
|
341
|
+
const platformData = app.platforms[platform];
|
|
342
|
+
|
|
343
|
+
// Перевіряємо наявність параметрів у кампанії
|
|
344
|
+
const campaignParams = existingCampaign.parameters;
|
|
345
|
+
const hasCampaignParams = campaignParams && campaignParams.sub_id_15 && campaignParams.sub_id_17 && campaignParams.sub_id_18;
|
|
346
|
+
|
|
347
|
+
// Перевіряємо чи є trackingParams в app
|
|
348
|
+
const hasAppTrackingParams = platformData?.direct?.keitaroData && typeof platformData.direct.keitaroData !== 'boolean' && platformData.direct.keitaroData.trackingParams;
|
|
349
|
+
|
|
350
|
+
// Якщо параметрів нема ні в Keitaro ні в app - генеруємо нові
|
|
351
|
+
if (!hasCampaignParams && !hasAppTrackingParams) {
|
|
352
|
+
console.log("No parameters in campaign and no trackingParams in app, generating new ones...");
|
|
353
|
+
return await generateAndUpdateCampaignParameters(existingCampaign, app, platform);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Якщо параметрів нема в Keitaro, але є в app - використовуємо app
|
|
357
|
+
if (!hasCampaignParams && hasAppTrackingParams) {
|
|
358
|
+
console.log("Campaign has no parameters, using app trackingParams...");
|
|
359
|
+
return await updateCampaignWithAppParams(existingCampaign, app, platform);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Якщо параметри є в Keitaro, але нема в app - оновлюємо app
|
|
363
|
+
if (hasCampaignParams && !hasAppTrackingParams) {
|
|
364
|
+
console.log("Campaign has parameters but no app trackingParams, updating app with campaign parameters...");
|
|
365
|
+
return await updateAppWithCampaignParams(existingCampaign, app, platform);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Якщо параметри є і в Keitaro і в app - перевіряємо чи потрібно оновлювати
|
|
369
|
+
if (hasCampaignParams && hasAppTrackingParams && platformData.direct && typeof platformData.direct.keitaroData !== 'boolean') {
|
|
370
|
+
const appTrackingParams = platformData.direct.keitaroData.trackingParams;
|
|
371
|
+
const needsUpdate = await checkParametersMatch(appTrackingParams, campaignParams, app, platform);
|
|
372
|
+
|
|
373
|
+
if (needsUpdate) {
|
|
374
|
+
console.log("Parameters need update due to app changes, updating with app trackingParams...");
|
|
375
|
+
return await updateCampaignWithAppParams(existingCampaign, app, platform);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
console.log("Parameters are up to date, no update needed");
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async function checkParametersMatch(appTrackingParams: any, campaignParams: IKeitaroCampaignParameters, app: IApp, platform: EPlatform): Promise<boolean> {
|
|
386
|
+
// Перевіряємо чи параметри відповідають trackingParams з app
|
|
387
|
+
const namingMatch = campaignParams.sub_id_15?.name === appTrackingParams.naming;
|
|
388
|
+
const advertisingIdMatch = campaignParams.sub_id_17?.name === appTrackingParams.advertising_id;
|
|
389
|
+
const appsflyerDeviceIdMatch = campaignParams.sub_id_18?.name === appTrackingParams.appsflyer_device_id;
|
|
390
|
+
|
|
391
|
+
// Перевіряємо чи змінилися ключові налаштування додатку
|
|
392
|
+
const bundleChanged = campaignParams.sub_id_16?.placeholder !== app.bundle;
|
|
393
|
+
const appsflyerDevKeyChanged = campaignParams.sub_id_19?.placeholder !== (app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key');
|
|
394
|
+
|
|
395
|
+
// Якщо всі параметри співпадають з app trackingParams і немає змін в додатку
|
|
396
|
+
if (namingMatch && advertisingIdMatch && appsflyerDeviceIdMatch && !bundleChanged && !appsflyerDevKeyChanged) {
|
|
397
|
+
console.log("All parameters match app trackingParams and app settings unchanged, no update needed");
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Логуємо причину оновлення
|
|
402
|
+
if (bundleChanged) console.log(`Bundle changed: ${campaignParams.sub_id_16?.placeholder} → ${app.bundle}`);
|
|
403
|
+
if (appsflyerDevKeyChanged) console.log(`Appsflyer Dev Key changed: ${campaignParams.sub_id_19?.placeholder} → ${app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key'}`);
|
|
404
|
+
if (!namingMatch) console.log(`Naming changed: ${campaignParams.sub_id_15?.name} → ${appTrackingParams.naming}`);
|
|
405
|
+
if (!advertisingIdMatch) console.log(`Advertising ID changed: ${campaignParams.sub_id_17?.name} → ${appTrackingParams.advertising_id}`);
|
|
406
|
+
if (!appsflyerDeviceIdMatch) console.log(`Appsflyer Device ID changed: ${campaignParams.sub_id_18?.name} → ${appTrackingParams.appsflyer_device_id}`);
|
|
407
|
+
|
|
408
|
+
return true; // Потрібно оновлення
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function generateAndUpdateCampaignParameters(existingCampaign: IKeitaroCampaign, app: IApp, platform: EPlatform): Promise<boolean> {
|
|
412
|
+
try {
|
|
413
|
+
// Генеруємо нові параметри
|
|
414
|
+
const newParameters = await TrafleKeitaroParameters({
|
|
415
|
+
bundle: app.bundle,
|
|
416
|
+
appsflyerDevKey: app.platforms[platform].appsflyerParams?.devKey,
|
|
417
|
+
name: existingCampaign.name,
|
|
418
|
+
originalParameters: existingCampaign.parameters
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
if (!newParameters) {
|
|
422
|
+
console.error("Failed to generate new parameters");
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Оновлюємо кампанію з новими параметрами
|
|
427
|
+
const updatePayload = {
|
|
428
|
+
parameters: newParameters.parameters
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
await keitaroApi.put(`/campaigns/${existingCampaign.id}`, updatePayload);
|
|
432
|
+
console.log("Campaign parameters updated successfully");
|
|
433
|
+
|
|
434
|
+
// Оновлюємо локальний об'єкт кампанії
|
|
435
|
+
existingCampaign.parameters = newParameters.parameters;
|
|
436
|
+
console.log("Local campaign parameters updated:", existingCampaign.parameters);
|
|
437
|
+
|
|
438
|
+
// Оновлюємо trackingParams в додатку
|
|
439
|
+
await updateAppTrackingParams(app, platform, newParameters.parameters);
|
|
440
|
+
|
|
441
|
+
return true;
|
|
442
|
+
} catch (error) {
|
|
443
|
+
console.error("Failed to update campaign parameters:", error);
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
async function updateAppTrackingParams(app: IApp, platform: EPlatform, newParameters: IKeitaroCampaignParameters): Promise<void> {
|
|
449
|
+
try {
|
|
450
|
+
// Оновлюємо trackingParams в додатку
|
|
451
|
+
const platformData = app.platforms[platform];
|
|
452
|
+
if (platformData?.direct?.keitaroData && typeof platformData.direct.keitaroData !== 'boolean' && platformData.direct.keitaroData.trackingParams) {
|
|
453
|
+
platformData.direct.keitaroData.trackingParams = {
|
|
454
|
+
naming: newParameters.sub_id_15?.name || "",
|
|
455
|
+
advertising_id: newParameters.sub_id_17?.name || "",
|
|
456
|
+
appsflyer_device_id: newParameters.sub_id_18?.name || "",
|
|
457
|
+
bundle_id: newParameters.sub_id_16?.name || ""
|
|
458
|
+
};
|
|
459
|
+
console.log("App trackingParams updated:", platformData.direct.keitaroData.trackingParams);
|
|
460
|
+
}
|
|
461
|
+
} catch (error) {
|
|
462
|
+
console.error("Failed to update app trackingParams:", error);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
316
465
|
|
|
466
|
+
async function updateCampaignWithAppParams(existingCampaign: IKeitaroCampaign, app: IApp, platform: EPlatform): Promise<boolean> {
|
|
467
|
+
try {
|
|
468
|
+
const platformData = app.platforms[platform];
|
|
469
|
+
if (!platformData?.direct?.keitaroData || typeof platformData.direct.keitaroData === 'boolean' || !platformData.direct.keitaroData.trackingParams) {
|
|
470
|
+
console.error("No trackingParams found in app");
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const appTrackingParams = platformData.direct.keitaroData.trackingParams;
|
|
475
|
+
|
|
476
|
+
// Використовуємо існуючі параметри з app замість генерації нових
|
|
477
|
+
const newParameters = {
|
|
478
|
+
parameters: {
|
|
479
|
+
keyword: { name: 'keyword', placeholder: '', alias: '' },
|
|
480
|
+
cost: { name: 'cost', placeholder: '', alias: '' },
|
|
481
|
+
currency: { name: 'currency', placeholder: '', alias: '' },
|
|
482
|
+
external_id: { name: 'external_id', placeholder: '', alias: '' },
|
|
483
|
+
creative_id: { name: 'creative_id', placeholder: '', alias: '' },
|
|
484
|
+
ad_campaign_id: { name: 'ad_campaign_id', placeholder: '', alias: '' },
|
|
485
|
+
source: { name: 'source', placeholder: '', alias: '' },
|
|
486
|
+
sub_id_1: { name: 'uqID', placeholder: '', alias: '' },
|
|
487
|
+
sub_id_2: { name: 'AD_ID', placeholder: '', alias: '' },
|
|
488
|
+
sub_id_3: { name: 'USB', placeholder: '', alias: '' },
|
|
489
|
+
sub_id_4: { name: 'DEV', placeholder: '', alias: '' },
|
|
490
|
+
sub_id_5: { name: 'LANG', placeholder: '', alias: '' },
|
|
491
|
+
sub_id_10: { name: 'market', placeholder: '', alias: '' },
|
|
492
|
+
sub_id_15: {
|
|
493
|
+
name: appTrackingParams.naming || 'naming',
|
|
494
|
+
placeholder: '{naming}',
|
|
495
|
+
alias: 'Naming'
|
|
496
|
+
},
|
|
497
|
+
sub_id_16: {
|
|
498
|
+
name: 'bundle_id',
|
|
499
|
+
placeholder: app.bundle,
|
|
500
|
+
alias: 'Bundle ID'
|
|
501
|
+
},
|
|
502
|
+
sub_id_17: {
|
|
503
|
+
name: appTrackingParams.advertising_id || 'advertising_id',
|
|
504
|
+
placeholder: '{advertising_id}',
|
|
505
|
+
alias: 'Advertising ID'
|
|
506
|
+
},
|
|
507
|
+
sub_id_18: {
|
|
508
|
+
name: appTrackingParams.appsflyer_device_id || 'appsflyer_device_id',
|
|
509
|
+
placeholder: '{appsflyer_device_id}',
|
|
510
|
+
alias: 'Appsflyer Device ID'
|
|
511
|
+
},
|
|
512
|
+
sub_id_19: {
|
|
513
|
+
name: 'appsflyer_dev_key',
|
|
514
|
+
placeholder: app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key',
|
|
515
|
+
alias: 'Appsflyer Dev Key'
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
console.log(`Using app trackingParams: naming=${appTrackingParams.naming}, advertising_id=${appTrackingParams.advertising_id}, appsflyer_device_id=${appTrackingParams.appsflyer_device_id}`);
|
|
521
|
+
|
|
522
|
+
// Оновлюємо кампанію з параметрами з app
|
|
523
|
+
const updatePayload = {
|
|
524
|
+
parameters: newParameters.parameters
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
await keitaroApi.put(`/campaigns/${existingCampaign.id}`, updatePayload);
|
|
528
|
+
console.log("Campaign parameters updated with app trackingParams");
|
|
529
|
+
|
|
530
|
+
// Оновлюємо локальний об'єкт кампанії
|
|
531
|
+
existingCampaign.parameters = newParameters.parameters;
|
|
532
|
+
console.log("Local campaign parameters updated with app trackingParams:", existingCampaign.parameters);
|
|
533
|
+
|
|
534
|
+
return true;
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.error("Failed to update campaign with app params:", error);
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async function updateAppWithCampaignParams(existingCampaign: IKeitaroCampaign, app: IApp, platform: EPlatform): Promise<boolean> {
|
|
542
|
+
try {
|
|
543
|
+
const platformData = app.platforms[platform];
|
|
544
|
+
if (!platformData?.direct?.keitaroData || typeof platformData.direct.keitaroData === 'boolean') {
|
|
545
|
+
console.error("No keitaroData found in app");
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const campaignParams = existingCampaign.parameters;
|
|
550
|
+
if (!campaignParams) {
|
|
551
|
+
console.error("No parameters found in campaign");
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Оновлюємо app з параметрами з Keitaro
|
|
556
|
+
platformData.direct.keitaroData.trackingParams = {
|
|
557
|
+
naming: campaignParams.sub_id_15?.name || "",
|
|
558
|
+
advertising_id: campaignParams.sub_id_17?.name || "",
|
|
559
|
+
appsflyer_device_id: campaignParams.sub_id_18?.name || "",
|
|
560
|
+
bundle_id: campaignParams.sub_id_16?.placeholder || ""
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
console.log(`Updated app with campaign parameters: naming=${platformData.direct.keitaroData.trackingParams.naming}, advertising_id=${platformData.direct.keitaroData.trackingParams.advertising_id}, appsflyer_device_id=${platformData.direct.keitaroData.trackingParams.appsflyer_device_id}`);
|
|
564
|
+
|
|
565
|
+
return true;
|
|
566
|
+
} catch (error) {
|
|
567
|
+
console.error("Failed to update app with campaign params:", error);
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
317
571
|
|
|
318
572
|
async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultStreams?: boolean): Promise<IKeitaroCampaign | any> {
|
|
319
573
|
|
|
@@ -337,13 +591,14 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
|
|
|
337
591
|
// Для конкретної платформи
|
|
338
592
|
const platformName = getPlatformName(platform);
|
|
339
593
|
matchingCampaign = allCampaigns.filter((c) => {
|
|
340
|
-
|
|
594
|
+
|
|
341
595
|
const hasDomain = c.name.includes(app.domainParams.name);
|
|
596
|
+
const hasGroup = c.group == app.id.toString()
|
|
342
597
|
|
|
343
598
|
// Перевіряємо наявність платформи в дужках в кінці назви
|
|
344
599
|
const platformPattern = new RegExp(`\\(.*${platformName}.*\\)\\s*$`);
|
|
345
600
|
const hasPlatform = platformPattern.test(c.name);
|
|
346
|
-
return
|
|
601
|
+
return hasGroup && hasDomain && hasPlatform;
|
|
347
602
|
});
|
|
348
603
|
} else {
|
|
349
604
|
// Для General платформи
|
|
@@ -358,10 +613,13 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
|
|
|
358
613
|
});
|
|
359
614
|
}
|
|
360
615
|
|
|
361
|
-
// Якщо знайдена існуюча кампанія -
|
|
616
|
+
// Якщо знайдена існуюча кампанія - перевіряємо параметри
|
|
362
617
|
if (matchingCampaign.length > 0) {
|
|
363
618
|
const existingCampaign = matchingCampaign[0];
|
|
364
619
|
|
|
620
|
+
// Перевіряємо наявність та актуальність параметрів
|
|
621
|
+
const needsParameterUpdate = await checkAndUpdateCampaignParameters(existingCampaign, app, platform);
|
|
622
|
+
|
|
365
623
|
// Отримуємо потоки тільки якщо потрібно щось робити з ними
|
|
366
624
|
const originalStreams = await getStreamsByCampaignId(ORIGINAL_CLONE_CAMPAIGN_ID);
|
|
367
625
|
const existingStreams = await getStreamsByCampaignId(existingCampaign.id);
|
|
@@ -612,5 +870,5 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
|
|
|
612
870
|
|
|
613
871
|
|
|
614
872
|
export const TraffleKeitaroService = {
|
|
615
|
-
addOffersToTraffleKeitaro, getTraffleOffersGroups, getTraffleAffiliateNetworks, createGroup, deleteOfferById, getAllOffers, updateOfferLinkById, cloneTraffleCampaign
|
|
873
|
+
addOffersToTraffleKeitaro, getTraffleOffersGroups, getTraffleAffiliateNetworks, createGroup, deleteOfferById, getAllOffers, updateOfferLinkById, cloneTraffleCampaign, TrafleKeitaroParameters
|
|
616
874
|
}
|