@blotoutio/providers-app-lovin-sdk 1.16.1 → 1.17.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/index.cjs.js +59 -11
- package/index.js +59 -11
- package/index.mjs +59 -11
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -77,26 +77,58 @@ const logger = {
|
|
|
77
77
|
},
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
const
|
|
80
|
+
const getParsedCategoryId = (category) => {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(category);
|
|
83
|
+
return parsed.value;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
logger.error(`Error parsing category: ${category}`, error);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const getCategories = (categoryMapping) => {
|
|
91
|
+
let categoryMappings = [];
|
|
92
|
+
try {
|
|
93
|
+
categoryMappings = JSON.parse(categoryMapping || '[]');
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
logger.error('Unable to parse category mappings');
|
|
97
|
+
categoryMappings = [];
|
|
98
|
+
}
|
|
99
|
+
return new Map(categoryMappings.map(({ storeCategory, appLovinCategory }) => [
|
|
100
|
+
storeCategory.toLowerCase(),
|
|
101
|
+
appLovinCategory.value,
|
|
102
|
+
]));
|
|
103
|
+
};
|
|
104
|
+
const getItems = (contents, defaultCategoryId, categories) => contents.map((item) => {
|
|
105
|
+
let categoryId = '';
|
|
106
|
+
if (item.category) {
|
|
107
|
+
categoryId = categories.get(item.category.toLowerCase()) || '';
|
|
108
|
+
}
|
|
81
109
|
return {
|
|
82
110
|
item_id: item.id,
|
|
83
111
|
item_name: item.title || '',
|
|
84
112
|
price: item.item_price,
|
|
85
113
|
quantity: item.quantity,
|
|
86
114
|
image_url: item.image,
|
|
87
|
-
|
|
115
|
+
item_variant_id: item.variantId,
|
|
88
116
|
item_brand: item.brand,
|
|
89
|
-
|
|
117
|
+
item_category_id: categoryId || defaultCategoryId || '',
|
|
90
118
|
};
|
|
91
119
|
});
|
|
92
|
-
const getEventData = (eventName, userId, data) => {
|
|
120
|
+
const getEventData = ({ eventName, userId, data, defaultCategory, categoryMapping, }) => {
|
|
121
|
+
const categories = getCategories(categoryMapping);
|
|
122
|
+
const defaultCategoryId = getParsedCategoryId(defaultCategory);
|
|
93
123
|
switch (eventName) {
|
|
94
124
|
case 'AddToCart': {
|
|
95
125
|
return {
|
|
96
126
|
name: 'add_to_cart',
|
|
97
127
|
data: {
|
|
98
128
|
currency: data.currency,
|
|
99
|
-
items: data.contents
|
|
129
|
+
items: data.contents
|
|
130
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
131
|
+
: [],
|
|
100
132
|
value: data.value,
|
|
101
133
|
},
|
|
102
134
|
};
|
|
@@ -106,7 +138,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
106
138
|
name: 'begin_checkout',
|
|
107
139
|
data: {
|
|
108
140
|
currency: data.currency,
|
|
109
|
-
items: data.contents
|
|
141
|
+
items: data.contents
|
|
142
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
143
|
+
: [],
|
|
110
144
|
value: data.value,
|
|
111
145
|
},
|
|
112
146
|
};
|
|
@@ -132,7 +166,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
132
166
|
name: 'purchase',
|
|
133
167
|
data: {
|
|
134
168
|
currency: data.currency,
|
|
135
|
-
items: data.contents
|
|
169
|
+
items: data.contents
|
|
170
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
171
|
+
: [],
|
|
136
172
|
transaction_id: data.orderId,
|
|
137
173
|
user_id: userId,
|
|
138
174
|
value: data.value,
|
|
@@ -144,7 +180,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
144
180
|
name: 'remove_from_cart',
|
|
145
181
|
data: {
|
|
146
182
|
currency: data.currency,
|
|
147
|
-
items: data.contents
|
|
183
|
+
items: data.contents
|
|
184
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
185
|
+
: [],
|
|
148
186
|
value: data.value,
|
|
149
187
|
},
|
|
150
188
|
};
|
|
@@ -170,7 +208,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
170
208
|
name: 'view_item',
|
|
171
209
|
data: {
|
|
172
210
|
currency: data.currency,
|
|
173
|
-
items: data.contents
|
|
211
|
+
items: data.contents
|
|
212
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
213
|
+
: [],
|
|
174
214
|
value: data.value,
|
|
175
215
|
},
|
|
176
216
|
};
|
|
@@ -190,11 +230,19 @@ const getEventData = (eventName, userId, data) => {
|
|
|
190
230
|
|
|
191
231
|
const tag = ({ data, eventName, manifestVariables, userId }) => {
|
|
192
232
|
const payload = {
|
|
193
|
-
sdkVersion: "1.
|
|
233
|
+
sdkVersion: "1.17.0" ,
|
|
194
234
|
};
|
|
195
235
|
if (window.axon && manifestVariables['enableBrowser'] === '1') {
|
|
196
236
|
try {
|
|
197
|
-
const
|
|
237
|
+
const defaultCategory = manifestVariables['defaultCategory'];
|
|
238
|
+
const categoryMapping = manifestVariables['categoryMapping'];
|
|
239
|
+
const event = getEventData({
|
|
240
|
+
eventName,
|
|
241
|
+
userId,
|
|
242
|
+
data,
|
|
243
|
+
defaultCategory,
|
|
244
|
+
categoryMapping,
|
|
245
|
+
});
|
|
198
246
|
if (!event) {
|
|
199
247
|
logger.log(`[${packageName}] ${eventName} not supported`);
|
|
200
248
|
return;
|
package/index.js
CHANGED
|
@@ -78,26 +78,58 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
78
78
|
},
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
const
|
|
81
|
+
const getParsedCategoryId = (category) => {
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(category);
|
|
84
|
+
return parsed.value;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
logger.error(`Error parsing category: ${category}`, error);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const getCategories = (categoryMapping) => {
|
|
92
|
+
let categoryMappings = [];
|
|
93
|
+
try {
|
|
94
|
+
categoryMappings = JSON.parse(categoryMapping || '[]');
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
logger.error('Unable to parse category mappings');
|
|
98
|
+
categoryMappings = [];
|
|
99
|
+
}
|
|
100
|
+
return new Map(categoryMappings.map(({ storeCategory, appLovinCategory }) => [
|
|
101
|
+
storeCategory.toLowerCase(),
|
|
102
|
+
appLovinCategory.value,
|
|
103
|
+
]));
|
|
104
|
+
};
|
|
105
|
+
const getItems = (contents, defaultCategoryId, categories) => contents.map((item) => {
|
|
106
|
+
let categoryId = '';
|
|
107
|
+
if (item.category) {
|
|
108
|
+
categoryId = categories.get(item.category.toLowerCase()) || '';
|
|
109
|
+
}
|
|
82
110
|
return {
|
|
83
111
|
item_id: item.id,
|
|
84
112
|
item_name: item.title || '',
|
|
85
113
|
price: item.item_price,
|
|
86
114
|
quantity: item.quantity,
|
|
87
115
|
image_url: item.image,
|
|
88
|
-
|
|
116
|
+
item_variant_id: item.variantId,
|
|
89
117
|
item_brand: item.brand,
|
|
90
|
-
|
|
118
|
+
item_category_id: categoryId || defaultCategoryId || '',
|
|
91
119
|
};
|
|
92
120
|
});
|
|
93
|
-
const getEventData = (eventName, userId, data) => {
|
|
121
|
+
const getEventData = ({ eventName, userId, data, defaultCategory, categoryMapping, }) => {
|
|
122
|
+
const categories = getCategories(categoryMapping);
|
|
123
|
+
const defaultCategoryId = getParsedCategoryId(defaultCategory);
|
|
94
124
|
switch (eventName) {
|
|
95
125
|
case 'AddToCart': {
|
|
96
126
|
return {
|
|
97
127
|
name: 'add_to_cart',
|
|
98
128
|
data: {
|
|
99
129
|
currency: data.currency,
|
|
100
|
-
items: data.contents
|
|
130
|
+
items: data.contents
|
|
131
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
132
|
+
: [],
|
|
101
133
|
value: data.value,
|
|
102
134
|
},
|
|
103
135
|
};
|
|
@@ -107,7 +139,9 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
107
139
|
name: 'begin_checkout',
|
|
108
140
|
data: {
|
|
109
141
|
currency: data.currency,
|
|
110
|
-
items: data.contents
|
|
142
|
+
items: data.contents
|
|
143
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
144
|
+
: [],
|
|
111
145
|
value: data.value,
|
|
112
146
|
},
|
|
113
147
|
};
|
|
@@ -133,7 +167,9 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
133
167
|
name: 'purchase',
|
|
134
168
|
data: {
|
|
135
169
|
currency: data.currency,
|
|
136
|
-
items: data.contents
|
|
170
|
+
items: data.contents
|
|
171
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
172
|
+
: [],
|
|
137
173
|
transaction_id: data.orderId,
|
|
138
174
|
user_id: userId,
|
|
139
175
|
value: data.value,
|
|
@@ -145,7 +181,9 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
145
181
|
name: 'remove_from_cart',
|
|
146
182
|
data: {
|
|
147
183
|
currency: data.currency,
|
|
148
|
-
items: data.contents
|
|
184
|
+
items: data.contents
|
|
185
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
186
|
+
: [],
|
|
149
187
|
value: data.value,
|
|
150
188
|
},
|
|
151
189
|
};
|
|
@@ -171,7 +209,9 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
171
209
|
name: 'view_item',
|
|
172
210
|
data: {
|
|
173
211
|
currency: data.currency,
|
|
174
|
-
items: data.contents
|
|
212
|
+
items: data.contents
|
|
213
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
214
|
+
: [],
|
|
175
215
|
value: data.value,
|
|
176
216
|
},
|
|
177
217
|
};
|
|
@@ -191,11 +231,19 @@ var ProvidersAppLovinSdk = (function () {
|
|
|
191
231
|
|
|
192
232
|
const tag = ({ data, eventName, manifestVariables, userId }) => {
|
|
193
233
|
const payload = {
|
|
194
|
-
sdkVersion: "1.
|
|
234
|
+
sdkVersion: "1.17.0" ,
|
|
195
235
|
};
|
|
196
236
|
if (window.axon && manifestVariables['enableBrowser'] === '1') {
|
|
197
237
|
try {
|
|
198
|
-
const
|
|
238
|
+
const defaultCategory = manifestVariables['defaultCategory'];
|
|
239
|
+
const categoryMapping = manifestVariables['categoryMapping'];
|
|
240
|
+
const event = getEventData({
|
|
241
|
+
eventName,
|
|
242
|
+
userId,
|
|
243
|
+
data,
|
|
244
|
+
defaultCategory,
|
|
245
|
+
categoryMapping,
|
|
246
|
+
});
|
|
199
247
|
if (!event) {
|
|
200
248
|
logger.log(`[${packageName}] ${eventName} not supported`);
|
|
201
249
|
return;
|
package/index.mjs
CHANGED
|
@@ -75,26 +75,58 @@ const logger = {
|
|
|
75
75
|
},
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
const
|
|
78
|
+
const getParsedCategoryId = (category) => {
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(category);
|
|
81
|
+
return parsed.value;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.error(`Error parsing category: ${category}`, error);
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const getCategories = (categoryMapping) => {
|
|
89
|
+
let categoryMappings = [];
|
|
90
|
+
try {
|
|
91
|
+
categoryMappings = JSON.parse(categoryMapping || '[]');
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
logger.error('Unable to parse category mappings');
|
|
95
|
+
categoryMappings = [];
|
|
96
|
+
}
|
|
97
|
+
return new Map(categoryMappings.map(({ storeCategory, appLovinCategory }) => [
|
|
98
|
+
storeCategory.toLowerCase(),
|
|
99
|
+
appLovinCategory.value,
|
|
100
|
+
]));
|
|
101
|
+
};
|
|
102
|
+
const getItems = (contents, defaultCategoryId, categories) => contents.map((item) => {
|
|
103
|
+
let categoryId = '';
|
|
104
|
+
if (item.category) {
|
|
105
|
+
categoryId = categories.get(item.category.toLowerCase()) || '';
|
|
106
|
+
}
|
|
79
107
|
return {
|
|
80
108
|
item_id: item.id,
|
|
81
109
|
item_name: item.title || '',
|
|
82
110
|
price: item.item_price,
|
|
83
111
|
quantity: item.quantity,
|
|
84
112
|
image_url: item.image,
|
|
85
|
-
|
|
113
|
+
item_variant_id: item.variantId,
|
|
86
114
|
item_brand: item.brand,
|
|
87
|
-
|
|
115
|
+
item_category_id: categoryId || defaultCategoryId || '',
|
|
88
116
|
};
|
|
89
117
|
});
|
|
90
|
-
const getEventData = (eventName, userId, data) => {
|
|
118
|
+
const getEventData = ({ eventName, userId, data, defaultCategory, categoryMapping, }) => {
|
|
119
|
+
const categories = getCategories(categoryMapping);
|
|
120
|
+
const defaultCategoryId = getParsedCategoryId(defaultCategory);
|
|
91
121
|
switch (eventName) {
|
|
92
122
|
case 'AddToCart': {
|
|
93
123
|
return {
|
|
94
124
|
name: 'add_to_cart',
|
|
95
125
|
data: {
|
|
96
126
|
currency: data.currency,
|
|
97
|
-
items: data.contents
|
|
127
|
+
items: data.contents
|
|
128
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
129
|
+
: [],
|
|
98
130
|
value: data.value,
|
|
99
131
|
},
|
|
100
132
|
};
|
|
@@ -104,7 +136,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
104
136
|
name: 'begin_checkout',
|
|
105
137
|
data: {
|
|
106
138
|
currency: data.currency,
|
|
107
|
-
items: data.contents
|
|
139
|
+
items: data.contents
|
|
140
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
141
|
+
: [],
|
|
108
142
|
value: data.value,
|
|
109
143
|
},
|
|
110
144
|
};
|
|
@@ -130,7 +164,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
130
164
|
name: 'purchase',
|
|
131
165
|
data: {
|
|
132
166
|
currency: data.currency,
|
|
133
|
-
items: data.contents
|
|
167
|
+
items: data.contents
|
|
168
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
169
|
+
: [],
|
|
134
170
|
transaction_id: data.orderId,
|
|
135
171
|
user_id: userId,
|
|
136
172
|
value: data.value,
|
|
@@ -142,7 +178,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
142
178
|
name: 'remove_from_cart',
|
|
143
179
|
data: {
|
|
144
180
|
currency: data.currency,
|
|
145
|
-
items: data.contents
|
|
181
|
+
items: data.contents
|
|
182
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
183
|
+
: [],
|
|
146
184
|
value: data.value,
|
|
147
185
|
},
|
|
148
186
|
};
|
|
@@ -168,7 +206,9 @@ const getEventData = (eventName, userId, data) => {
|
|
|
168
206
|
name: 'view_item',
|
|
169
207
|
data: {
|
|
170
208
|
currency: data.currency,
|
|
171
|
-
items: data.contents
|
|
209
|
+
items: data.contents
|
|
210
|
+
? getItems(data.contents, defaultCategoryId, categories)
|
|
211
|
+
: [],
|
|
172
212
|
value: data.value,
|
|
173
213
|
},
|
|
174
214
|
};
|
|
@@ -188,11 +228,19 @@ const getEventData = (eventName, userId, data) => {
|
|
|
188
228
|
|
|
189
229
|
const tag = ({ data, eventName, manifestVariables, userId }) => {
|
|
190
230
|
const payload = {
|
|
191
|
-
sdkVersion: "1.
|
|
231
|
+
sdkVersion: "1.17.0" ,
|
|
192
232
|
};
|
|
193
233
|
if (window.axon && manifestVariables['enableBrowser'] === '1') {
|
|
194
234
|
try {
|
|
195
|
-
const
|
|
235
|
+
const defaultCategory = manifestVariables['defaultCategory'];
|
|
236
|
+
const categoryMapping = manifestVariables['categoryMapping'];
|
|
237
|
+
const event = getEventData({
|
|
238
|
+
eventName,
|
|
239
|
+
userId,
|
|
240
|
+
data,
|
|
241
|
+
defaultCategory,
|
|
242
|
+
categoryMapping,
|
|
243
|
+
});
|
|
196
244
|
if (!event) {
|
|
197
245
|
logger.log(`[${packageName}] ${eventName} not supported`);
|
|
198
246
|
return;
|