@liquidcommercedev/rmn-sdk 1.5.0-beta.30 → 1.5.0-beta.31
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.cjs
CHANGED
@@ -17196,17 +17196,17 @@ class IntersectionObserverService {
|
|
17196
17196
|
}
|
17197
17197
|
}
|
17198
17198
|
|
17199
|
-
var
|
17200
|
-
(function (
|
17201
|
-
|
17202
|
-
|
17203
|
-
|
17204
|
-
|
17205
|
-
|
17206
|
-
|
17207
|
-
|
17208
|
-
})(
|
17209
|
-
const
|
17199
|
+
var ENUM_SPOT_ARRAY_INDEX;
|
17200
|
+
(function (ENUM_SPOT_ARRAY_INDEX) {
|
17201
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["PLACEMENT_ID"] = 0] = "PLACEMENT_ID";
|
17202
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["SPOT_ID"] = 1] = "SPOT_ID";
|
17203
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["SPOT_TYPE"] = 2] = "SPOT_TYPE";
|
17204
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["EVENTS"] = 3] = "EVENTS";
|
17205
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["FIRED_EVENTS"] = 4] = "FIRED_EVENTS";
|
17206
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["PRODUCT_IDS"] = 5] = "PRODUCT_IDS";
|
17207
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["CREATED_AT"] = 6] = "CREATED_AT";
|
17208
|
+
})(ENUM_SPOT_ARRAY_INDEX || (ENUM_SPOT_ARRAY_INDEX = {}));
|
17209
|
+
const SPOT_EVENTS_ARRAY_INDEX = {
|
17210
17210
|
[exports.RMN_SPOT_EVENT.IMPRESSION]: 0,
|
17211
17211
|
[exports.RMN_SPOT_EVENT.CLICK]: 1,
|
17212
17212
|
[exports.RMN_SPOT_EVENT.PURCHASE]: 2,
|
@@ -17236,43 +17236,24 @@ class LocalStorageService {
|
|
17236
17236
|
}
|
17237
17237
|
return LocalStorageService.instance;
|
17238
17238
|
}
|
17239
|
-
syncLocalStorage() {
|
17240
|
-
const localStorageData = window.localStorage.getItem(LocalStorageService.localStorageKey);
|
17241
|
-
if (localStorageData) {
|
17242
|
-
try {
|
17243
|
-
const decryptedData = this.decryptData(localStorageData);
|
17244
|
-
const parsedData = JSON.parse(decryptedData);
|
17245
|
-
if (parsedData && typeof parsedData === 'object') {
|
17246
|
-
const data = {};
|
17247
|
-
for (const [key, value] of Object.entries(parsedData)) {
|
17248
|
-
data[key] = this.spotArrayToObject(value);
|
17249
|
-
}
|
17250
|
-
this.spots = this.objectToMap(data);
|
17251
|
-
}
|
17252
|
-
else {
|
17253
|
-
this.clearLocalStorage();
|
17254
|
-
}
|
17255
|
-
}
|
17256
|
-
catch (_a) {
|
17257
|
-
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17258
|
-
this.clearLocalStorage();
|
17259
|
-
}
|
17260
|
-
}
|
17261
|
-
}
|
17262
17239
|
setSpot(spotId, data) {
|
17263
|
-
var _a, _b, _c, _d;
|
17240
|
+
var _a, _b, _c, _d, _e;
|
17264
17241
|
data.createdAt = Date.now();
|
17265
17242
|
const isExistentSpot = (_a = this.spots) === null || _a === void 0 ? void 0 : _a.has(spotId);
|
17266
17243
|
if (isExistentSpot) {
|
17267
|
-
|
17268
|
-
data.firedEvents = (_c = existingData === null || existingData === void 0 ? void 0 : existingData.firedEvents) !== null && _c !== void 0 ? _c : [];
|
17244
|
+
data.firedEvents = (_d = (_c = (_b = this.spots) === null || _b === void 0 ? void 0 : _b.get(spotId)) === null || _c === void 0 ? void 0 : _c.firedEvents) !== null && _d !== void 0 ? _d : [];
|
17269
17245
|
}
|
17270
|
-
(
|
17246
|
+
(_e = this.spots) === null || _e === void 0 ? void 0 : _e.set(spotId, data);
|
17271
17247
|
this.updateLocalStorage();
|
17272
17248
|
}
|
17273
17249
|
removeSpot(spotId) {
|
17274
|
-
var _a;
|
17275
|
-
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.
|
17250
|
+
var _a, _b;
|
17251
|
+
const isExistentSpot = (_a = this.spots) === null || _a === void 0 ? void 0 : _a.has(spotId);
|
17252
|
+
if (!isExistentSpot)
|
17253
|
+
return;
|
17254
|
+
const isDeleted = (_b = this.spots) === null || _b === void 0 ? void 0 : _b.delete(spotId);
|
17255
|
+
if (!isDeleted)
|
17256
|
+
return;
|
17276
17257
|
this.updateLocalStorage();
|
17277
17258
|
}
|
17278
17259
|
getSpot(spotId) {
|
@@ -17335,16 +17316,36 @@ class LocalStorageService {
|
|
17335
17316
|
}
|
17336
17317
|
}
|
17337
17318
|
// ======================== Utility functions ======================== //
|
17319
|
+
syncLocalStorage() {
|
17320
|
+
const localStorageData = window.localStorage.getItem(LocalStorageService.localStorageKey);
|
17321
|
+
if (localStorageData) {
|
17322
|
+
try {
|
17323
|
+
const decryptedData = this.decryptData(localStorageData);
|
17324
|
+
const parsedData = JSON.parse(decryptedData);
|
17325
|
+
if (Array.isArray(parsedData)) {
|
17326
|
+
const data = Object.fromEntries(parsedData.map((spot) => [
|
17327
|
+
spot[ENUM_SPOT_ARRAY_INDEX.SPOT_ID],
|
17328
|
+
this.spotArrayToObject(spot),
|
17329
|
+
]));
|
17330
|
+
this.spots = this.objectToMap(data);
|
17331
|
+
}
|
17332
|
+
else {
|
17333
|
+
this.clearLocalStorage();
|
17334
|
+
}
|
17335
|
+
}
|
17336
|
+
catch (_a) {
|
17337
|
+
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17338
|
+
this.clearLocalStorage();
|
17339
|
+
}
|
17340
|
+
}
|
17341
|
+
}
|
17338
17342
|
updateLocalStorage() {
|
17339
17343
|
if (!this.spots)
|
17340
17344
|
return undefined;
|
17341
|
-
const
|
17342
|
-
const
|
17343
|
-
for (const [key, value] of Object.entries(data)) {
|
17344
|
-
dataArray[key] = this.spotObjectToArray(value);
|
17345
|
-
}
|
17345
|
+
const spotsObj = this.mapToObject(this.spots);
|
17346
|
+
const data = Object.values(spotsObj).map((spot) => this.spotObjectToArray(spot));
|
17346
17347
|
try {
|
17347
|
-
const encryptedData = this.encryptData(JSON.stringify(
|
17348
|
+
const encryptedData = this.encryptData(JSON.stringify(data));
|
17348
17349
|
window.localStorage.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17349
17350
|
}
|
17350
17351
|
catch (_a) {
|
@@ -17373,52 +17374,53 @@ class LocalStorageService {
|
|
17373
17374
|
return new Map(Object.entries(obj));
|
17374
17375
|
}
|
17375
17376
|
spotEventObjectToArray(events) {
|
17376
|
-
return Object.keys(
|
17377
|
+
return Object.keys(SPOT_EVENTS_ARRAY_INDEX).map((type) => {
|
17377
17378
|
const result = events.find((item) => item.event === type);
|
17378
17379
|
return result && result.event === type ? result.url : '';
|
17379
17380
|
});
|
17380
17381
|
}
|
17381
17382
|
spotEventArrayToObject(arr) {
|
17382
|
-
return Object.keys(
|
17383
|
+
return Object.keys(SPOT_EVENTS_ARRAY_INDEX).map((type) => ({
|
17383
17384
|
event: type,
|
17384
|
-
url: arr[
|
17385
|
+
url: arr[SPOT_EVENTS_ARRAY_INDEX[type]],
|
17385
17386
|
}));
|
17386
17387
|
}
|
17387
17388
|
/**
|
17388
17389
|
* Converts a spot object to an array.
|
17389
17390
|
*
|
17390
17391
|
* @param {ILocalStorageSpot} obj - The spot object to convert.
|
17391
|
-
* @return {
|
17392
|
+
* @return {SpotArrayType} An array representation of the spot object.
|
17392
17393
|
*/
|
17393
17394
|
spotObjectToArray(obj) {
|
17395
|
+
var _a, _b, _c;
|
17394
17396
|
return [
|
17395
17397
|
obj.placementId,
|
17396
17398
|
obj.spotId,
|
17397
17399
|
obj.spotType,
|
17398
17400
|
this.spotEventObjectToArray(obj.events),
|
17399
|
-
obj.firedEvents.map((event) => [event.productId, event.event]),
|
17401
|
+
(_b = (_a = obj.firedEvents) === null || _a === void 0 ? void 0 : _a.map((event) => [event.productId, event.event])) !== null && _b !== void 0 ? _b : [],
|
17400
17402
|
obj.productIds,
|
17401
|
-
obj.createdAt,
|
17403
|
+
(_c = obj.createdAt) !== null && _c !== void 0 ? _c : 0,
|
17402
17404
|
];
|
17403
17405
|
}
|
17404
17406
|
/**
|
17405
17407
|
* Converts an array representation of spot data into an object representation.
|
17406
17408
|
*
|
17407
|
-
* @param {
|
17409
|
+
* @param {SpotArrayType} arr - The array containing spot data.
|
17408
17410
|
* @return {ILocalStorageSpot} An object representation of the spot data.
|
17409
17411
|
*/
|
17410
17412
|
spotArrayToObject(arr) {
|
17411
17413
|
return {
|
17412
|
-
placementId: arr[
|
17413
|
-
spotId: arr[
|
17414
|
-
spotType: arr[
|
17415
|
-
events: this.spotEventArrayToObject(arr[
|
17416
|
-
firedEvents: arr[
|
17414
|
+
placementId: arr[ENUM_SPOT_ARRAY_INDEX.PLACEMENT_ID],
|
17415
|
+
spotId: arr[ENUM_SPOT_ARRAY_INDEX.SPOT_ID],
|
17416
|
+
spotType: arr[ENUM_SPOT_ARRAY_INDEX.SPOT_TYPE],
|
17417
|
+
events: this.spotEventArrayToObject(arr[ENUM_SPOT_ARRAY_INDEX.EVENTS]),
|
17418
|
+
firedEvents: arr[ENUM_SPOT_ARRAY_INDEX.FIRED_EVENTS].map((item) => ({
|
17417
17419
|
productId: item[0],
|
17418
17420
|
event: item[1],
|
17419
17421
|
})),
|
17420
|
-
productIds: arr[
|
17421
|
-
createdAt: arr[
|
17422
|
+
productIds: arr[ENUM_SPOT_ARRAY_INDEX.PRODUCT_IDS],
|
17423
|
+
createdAt: arr[ENUM_SPOT_ARRAY_INDEX.CREATED_AT],
|
17422
17424
|
};
|
17423
17425
|
}
|
17424
17426
|
/**
|
@@ -20793,7 +20795,7 @@ class MonitorService {
|
|
20793
20795
|
if (!Object.values(exports.RMN_SPOT_EVENT).includes(eventData.event)) {
|
20794
20796
|
continue;
|
20795
20797
|
}
|
20796
|
-
const firedEvents = spot.firedEvents;
|
20798
|
+
const firedEvents = spot.firedEvents || [];
|
20797
20799
|
const [eventProductId] = cleanProductIds([data.id]);
|
20798
20800
|
const isEventAlreadyFired = firedEvents.some((event) => event.productId === eventProductId && event.event === eventData.event);
|
20799
20801
|
if (isEventAlreadyFired) {
|
@@ -20812,9 +20814,12 @@ class MonitorService {
|
|
20812
20814
|
const eventUrl = spot.events[eventPosition].url;
|
20813
20815
|
let additionalQueryParams = '';
|
20814
20816
|
if (eventData.event === exports.RMN_SPOT_EVENT.PURCHASE) {
|
20815
|
-
const
|
20817
|
+
const conversionPrice = data.price && data.quantity ? data.price * data.quantity : undefined;
|
20816
20818
|
// gmv = gross merchandise value, it is calculated by multiplying the product price by the product quantity
|
20817
|
-
additionalQueryParams = objectToQueryParams({
|
20819
|
+
additionalQueryParams = objectToQueryParams({
|
20820
|
+
override: conversionPrice,
|
20821
|
+
gmv: conversionPrice,
|
20822
|
+
});
|
20818
20823
|
}
|
20819
20824
|
// Fire the event and publish it to the pubsub service
|
20820
20825
|
await this.fireAndPublishSpotEvent({
|
@@ -20992,7 +20997,6 @@ class EventService {
|
|
20992
20997
|
spotType: spot.spot,
|
20993
20998
|
events: spot.events,
|
20994
20999
|
productIds: (_a = spot.productIds) !== null && _a !== void 0 ? _a : [],
|
20995
|
-
firedEvents: [],
|
20996
21000
|
});
|
20997
21001
|
}
|
20998
21002
|
async handleClickEvent({ placementId, spot }) {
|
package/dist/index.esm.js
CHANGED
@@ -17194,17 +17194,17 @@ class IntersectionObserverService {
|
|
17194
17194
|
}
|
17195
17195
|
}
|
17196
17196
|
|
17197
|
-
var
|
17198
|
-
(function (
|
17199
|
-
|
17200
|
-
|
17201
|
-
|
17202
|
-
|
17203
|
-
|
17204
|
-
|
17205
|
-
|
17206
|
-
})(
|
17207
|
-
const
|
17197
|
+
var ENUM_SPOT_ARRAY_INDEX;
|
17198
|
+
(function (ENUM_SPOT_ARRAY_INDEX) {
|
17199
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["PLACEMENT_ID"] = 0] = "PLACEMENT_ID";
|
17200
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["SPOT_ID"] = 1] = "SPOT_ID";
|
17201
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["SPOT_TYPE"] = 2] = "SPOT_TYPE";
|
17202
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["EVENTS"] = 3] = "EVENTS";
|
17203
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["FIRED_EVENTS"] = 4] = "FIRED_EVENTS";
|
17204
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["PRODUCT_IDS"] = 5] = "PRODUCT_IDS";
|
17205
|
+
ENUM_SPOT_ARRAY_INDEX[ENUM_SPOT_ARRAY_INDEX["CREATED_AT"] = 6] = "CREATED_AT";
|
17206
|
+
})(ENUM_SPOT_ARRAY_INDEX || (ENUM_SPOT_ARRAY_INDEX = {}));
|
17207
|
+
const SPOT_EVENTS_ARRAY_INDEX = {
|
17208
17208
|
[RMN_SPOT_EVENT.IMPRESSION]: 0,
|
17209
17209
|
[RMN_SPOT_EVENT.CLICK]: 1,
|
17210
17210
|
[RMN_SPOT_EVENT.PURCHASE]: 2,
|
@@ -17234,43 +17234,24 @@ class LocalStorageService {
|
|
17234
17234
|
}
|
17235
17235
|
return LocalStorageService.instance;
|
17236
17236
|
}
|
17237
|
-
syncLocalStorage() {
|
17238
|
-
const localStorageData = window.localStorage.getItem(LocalStorageService.localStorageKey);
|
17239
|
-
if (localStorageData) {
|
17240
|
-
try {
|
17241
|
-
const decryptedData = this.decryptData(localStorageData);
|
17242
|
-
const parsedData = JSON.parse(decryptedData);
|
17243
|
-
if (parsedData && typeof parsedData === 'object') {
|
17244
|
-
const data = {};
|
17245
|
-
for (const [key, value] of Object.entries(parsedData)) {
|
17246
|
-
data[key] = this.spotArrayToObject(value);
|
17247
|
-
}
|
17248
|
-
this.spots = this.objectToMap(data);
|
17249
|
-
}
|
17250
|
-
else {
|
17251
|
-
this.clearLocalStorage();
|
17252
|
-
}
|
17253
|
-
}
|
17254
|
-
catch (_a) {
|
17255
|
-
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17256
|
-
this.clearLocalStorage();
|
17257
|
-
}
|
17258
|
-
}
|
17259
|
-
}
|
17260
17237
|
setSpot(spotId, data) {
|
17261
|
-
var _a, _b, _c, _d;
|
17238
|
+
var _a, _b, _c, _d, _e;
|
17262
17239
|
data.createdAt = Date.now();
|
17263
17240
|
const isExistentSpot = (_a = this.spots) === null || _a === void 0 ? void 0 : _a.has(spotId);
|
17264
17241
|
if (isExistentSpot) {
|
17265
|
-
|
17266
|
-
data.firedEvents = (_c = existingData === null || existingData === void 0 ? void 0 : existingData.firedEvents) !== null && _c !== void 0 ? _c : [];
|
17242
|
+
data.firedEvents = (_d = (_c = (_b = this.spots) === null || _b === void 0 ? void 0 : _b.get(spotId)) === null || _c === void 0 ? void 0 : _c.firedEvents) !== null && _d !== void 0 ? _d : [];
|
17267
17243
|
}
|
17268
|
-
(
|
17244
|
+
(_e = this.spots) === null || _e === void 0 ? void 0 : _e.set(spotId, data);
|
17269
17245
|
this.updateLocalStorage();
|
17270
17246
|
}
|
17271
17247
|
removeSpot(spotId) {
|
17272
|
-
var _a;
|
17273
|
-
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.
|
17248
|
+
var _a, _b;
|
17249
|
+
const isExistentSpot = (_a = this.spots) === null || _a === void 0 ? void 0 : _a.has(spotId);
|
17250
|
+
if (!isExistentSpot)
|
17251
|
+
return;
|
17252
|
+
const isDeleted = (_b = this.spots) === null || _b === void 0 ? void 0 : _b.delete(spotId);
|
17253
|
+
if (!isDeleted)
|
17254
|
+
return;
|
17274
17255
|
this.updateLocalStorage();
|
17275
17256
|
}
|
17276
17257
|
getSpot(spotId) {
|
@@ -17333,16 +17314,36 @@ class LocalStorageService {
|
|
17333
17314
|
}
|
17334
17315
|
}
|
17335
17316
|
// ======================== Utility functions ======================== //
|
17317
|
+
syncLocalStorage() {
|
17318
|
+
const localStorageData = window.localStorage.getItem(LocalStorageService.localStorageKey);
|
17319
|
+
if (localStorageData) {
|
17320
|
+
try {
|
17321
|
+
const decryptedData = this.decryptData(localStorageData);
|
17322
|
+
const parsedData = JSON.parse(decryptedData);
|
17323
|
+
if (Array.isArray(parsedData)) {
|
17324
|
+
const data = Object.fromEntries(parsedData.map((spot) => [
|
17325
|
+
spot[ENUM_SPOT_ARRAY_INDEX.SPOT_ID],
|
17326
|
+
this.spotArrayToObject(spot),
|
17327
|
+
]));
|
17328
|
+
this.spots = this.objectToMap(data);
|
17329
|
+
}
|
17330
|
+
else {
|
17331
|
+
this.clearLocalStorage();
|
17332
|
+
}
|
17333
|
+
}
|
17334
|
+
catch (_a) {
|
17335
|
+
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17336
|
+
this.clearLocalStorage();
|
17337
|
+
}
|
17338
|
+
}
|
17339
|
+
}
|
17336
17340
|
updateLocalStorage() {
|
17337
17341
|
if (!this.spots)
|
17338
17342
|
return undefined;
|
17339
|
-
const
|
17340
|
-
const
|
17341
|
-
for (const [key, value] of Object.entries(data)) {
|
17342
|
-
dataArray[key] = this.spotObjectToArray(value);
|
17343
|
-
}
|
17343
|
+
const spotsObj = this.mapToObject(this.spots);
|
17344
|
+
const data = Object.values(spotsObj).map((spot) => this.spotObjectToArray(spot));
|
17344
17345
|
try {
|
17345
|
-
const encryptedData = this.encryptData(JSON.stringify(
|
17346
|
+
const encryptedData = this.encryptData(JSON.stringify(data));
|
17346
17347
|
window.localStorage.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17347
17348
|
}
|
17348
17349
|
catch (_a) {
|
@@ -17371,52 +17372,53 @@ class LocalStorageService {
|
|
17371
17372
|
return new Map(Object.entries(obj));
|
17372
17373
|
}
|
17373
17374
|
spotEventObjectToArray(events) {
|
17374
|
-
return Object.keys(
|
17375
|
+
return Object.keys(SPOT_EVENTS_ARRAY_INDEX).map((type) => {
|
17375
17376
|
const result = events.find((item) => item.event === type);
|
17376
17377
|
return result && result.event === type ? result.url : '';
|
17377
17378
|
});
|
17378
17379
|
}
|
17379
17380
|
spotEventArrayToObject(arr) {
|
17380
|
-
return Object.keys(
|
17381
|
+
return Object.keys(SPOT_EVENTS_ARRAY_INDEX).map((type) => ({
|
17381
17382
|
event: type,
|
17382
|
-
url: arr[
|
17383
|
+
url: arr[SPOT_EVENTS_ARRAY_INDEX[type]],
|
17383
17384
|
}));
|
17384
17385
|
}
|
17385
17386
|
/**
|
17386
17387
|
* Converts a spot object to an array.
|
17387
17388
|
*
|
17388
17389
|
* @param {ILocalStorageSpot} obj - The spot object to convert.
|
17389
|
-
* @return {
|
17390
|
+
* @return {SpotArrayType} An array representation of the spot object.
|
17390
17391
|
*/
|
17391
17392
|
spotObjectToArray(obj) {
|
17393
|
+
var _a, _b, _c;
|
17392
17394
|
return [
|
17393
17395
|
obj.placementId,
|
17394
17396
|
obj.spotId,
|
17395
17397
|
obj.spotType,
|
17396
17398
|
this.spotEventObjectToArray(obj.events),
|
17397
|
-
obj.firedEvents.map((event) => [event.productId, event.event]),
|
17399
|
+
(_b = (_a = obj.firedEvents) === null || _a === void 0 ? void 0 : _a.map((event) => [event.productId, event.event])) !== null && _b !== void 0 ? _b : [],
|
17398
17400
|
obj.productIds,
|
17399
|
-
obj.createdAt,
|
17401
|
+
(_c = obj.createdAt) !== null && _c !== void 0 ? _c : 0,
|
17400
17402
|
];
|
17401
17403
|
}
|
17402
17404
|
/**
|
17403
17405
|
* Converts an array representation of spot data into an object representation.
|
17404
17406
|
*
|
17405
|
-
* @param {
|
17407
|
+
* @param {SpotArrayType} arr - The array containing spot data.
|
17406
17408
|
* @return {ILocalStorageSpot} An object representation of the spot data.
|
17407
17409
|
*/
|
17408
17410
|
spotArrayToObject(arr) {
|
17409
17411
|
return {
|
17410
|
-
placementId: arr[
|
17411
|
-
spotId: arr[
|
17412
|
-
spotType: arr[
|
17413
|
-
events: this.spotEventArrayToObject(arr[
|
17414
|
-
firedEvents: arr[
|
17412
|
+
placementId: arr[ENUM_SPOT_ARRAY_INDEX.PLACEMENT_ID],
|
17413
|
+
spotId: arr[ENUM_SPOT_ARRAY_INDEX.SPOT_ID],
|
17414
|
+
spotType: arr[ENUM_SPOT_ARRAY_INDEX.SPOT_TYPE],
|
17415
|
+
events: this.spotEventArrayToObject(arr[ENUM_SPOT_ARRAY_INDEX.EVENTS]),
|
17416
|
+
firedEvents: arr[ENUM_SPOT_ARRAY_INDEX.FIRED_EVENTS].map((item) => ({
|
17415
17417
|
productId: item[0],
|
17416
17418
|
event: item[1],
|
17417
17419
|
})),
|
17418
|
-
productIds: arr[
|
17419
|
-
createdAt: arr[
|
17420
|
+
productIds: arr[ENUM_SPOT_ARRAY_INDEX.PRODUCT_IDS],
|
17421
|
+
createdAt: arr[ENUM_SPOT_ARRAY_INDEX.CREATED_AT],
|
17420
17422
|
};
|
17421
17423
|
}
|
17422
17424
|
/**
|
@@ -20791,7 +20793,7 @@ class MonitorService {
|
|
20791
20793
|
if (!Object.values(RMN_SPOT_EVENT).includes(eventData.event)) {
|
20792
20794
|
continue;
|
20793
20795
|
}
|
20794
|
-
const firedEvents = spot.firedEvents;
|
20796
|
+
const firedEvents = spot.firedEvents || [];
|
20795
20797
|
const [eventProductId] = cleanProductIds([data.id]);
|
20796
20798
|
const isEventAlreadyFired = firedEvents.some((event) => event.productId === eventProductId && event.event === eventData.event);
|
20797
20799
|
if (isEventAlreadyFired) {
|
@@ -20810,9 +20812,12 @@ class MonitorService {
|
|
20810
20812
|
const eventUrl = spot.events[eventPosition].url;
|
20811
20813
|
let additionalQueryParams = '';
|
20812
20814
|
if (eventData.event === RMN_SPOT_EVENT.PURCHASE) {
|
20813
|
-
const
|
20815
|
+
const conversionPrice = data.price && data.quantity ? data.price * data.quantity : undefined;
|
20814
20816
|
// gmv = gross merchandise value, it is calculated by multiplying the product price by the product quantity
|
20815
|
-
additionalQueryParams = objectToQueryParams({
|
20817
|
+
additionalQueryParams = objectToQueryParams({
|
20818
|
+
override: conversionPrice,
|
20819
|
+
gmv: conversionPrice,
|
20820
|
+
});
|
20816
20821
|
}
|
20817
20822
|
// Fire the event and publish it to the pubsub service
|
20818
20823
|
await this.fireAndPublishSpotEvent({
|
@@ -20990,7 +20995,6 @@ class EventService {
|
|
20990
20995
|
spotType: spot.spot,
|
20991
20996
|
events: spot.events,
|
20992
20997
|
productIds: (_a = spot.productIds) !== null && _a !== void 0 ? _a : [],
|
20993
|
-
firedEvents: [],
|
20994
20998
|
});
|
20995
20999
|
}
|
20996
21000
|
async handleClickEvent({ placementId, spot }) {
|
@@ -10,46 +10,12 @@ export interface ILocalStorageSpot {
|
|
10
10
|
spotId: string;
|
11
11
|
spotType: RMN_SPOT_TYPE;
|
12
12
|
events: ISpotEvent[];
|
13
|
-
firedEvents
|
13
|
+
firedEvents?: IFiredSpotEvent[];
|
14
14
|
productIds: Array<string | number>;
|
15
15
|
createdAt?: number;
|
16
16
|
}
|
17
|
-
export type
|
17
|
+
export type LocalStorageSpots = Record<string, // spotId
|
18
18
|
ILocalStorageSpot>;
|
19
|
-
export type LocalStorageSpotsObjectType = Record<string, // spotId
|
20
|
-
ILocalStorageSpot>;
|
21
|
-
export type LocalStorageSpotArray = [
|
22
|
-
string,
|
23
|
-
string,
|
24
|
-
RMN_SPOT_TYPE,
|
25
|
-
string[],
|
26
|
-
Array<[string, RMN_SPOT_EVENT]>,
|
27
|
-
Array<string | number>,
|
28
|
-
// PRODUCT_IDS = 5
|
29
|
-
number | undefined
|
30
|
-
];
|
31
|
-
export declare enum ENUM_LOCAL_STORAGE_SPOT_ARRAY_INDEX {
|
32
|
-
PLACEMENT_ID = 0,
|
33
|
-
SPOT_ID = 1,
|
34
|
-
SPOT_TYPE = 2,
|
35
|
-
EVENTS = 3,
|
36
|
-
FIRED_EVENTS = 4,
|
37
|
-
PRODUCT_IDS = 5,
|
38
|
-
CREATED_AT = 6
|
39
|
-
}
|
40
|
-
export declare const LOCAL_STORAGE_SPOT_EVENTS_ARRAY_INDEX: {
|
41
|
-
readonly IMPRESSION: 0;
|
42
|
-
readonly CLICK: 1;
|
43
|
-
readonly PURCHASE: 2;
|
44
|
-
readonly ADD_TO_CART: 3;
|
45
|
-
readonly REMOVE_FROM_CART: 4;
|
46
|
-
readonly ADD_TO_CART_FROM_DETAILS: 5;
|
47
|
-
readonly ADD_TO_WISHLIST: 6;
|
48
|
-
readonly EXPAND_PRODUCT: 7;
|
49
|
-
readonly BUY_NOW: 8;
|
50
|
-
};
|
51
|
-
export type LocalStorageSpotsArrayType = Record<string, // spotId
|
52
|
-
LocalStorageSpotArray>;
|
53
19
|
export declare class LocalStorageService {
|
54
20
|
private spots?;
|
55
21
|
private static instance;
|
@@ -59,11 +25,10 @@ export declare class LocalStorageService {
|
|
59
25
|
private static readonly encryptData;
|
60
26
|
private constructor();
|
61
27
|
static getInstance(): LocalStorageService;
|
62
|
-
private syncLocalStorage;
|
63
28
|
setSpot(spotId: string, data: ILocalStorageSpot): void;
|
64
29
|
removeSpot(spotId: string): void;
|
65
30
|
getSpot(spotId: string): ILocalStorageSpot | undefined;
|
66
|
-
getSpots():
|
31
|
+
getSpots(): LocalStorageSpots | undefined;
|
67
32
|
/**
|
68
33
|
* Retrieves the user ID from the local storage key.
|
69
34
|
* If the key is not found, a new user ID is generated and set.
|
@@ -79,6 +44,7 @@ export declare class LocalStorageService {
|
|
79
44
|
* @return {void} This method does not return a value.
|
80
45
|
*/
|
81
46
|
setUserId(): void;
|
47
|
+
private syncLocalStorage;
|
82
48
|
private updateLocalStorage;
|
83
49
|
private clearLocalStorage;
|
84
50
|
private removeExpiredSpots;
|
@@ -90,13 +56,13 @@ export declare class LocalStorageService {
|
|
90
56
|
* Converts a spot object to an array.
|
91
57
|
*
|
92
58
|
* @param {ILocalStorageSpot} obj - The spot object to convert.
|
93
|
-
* @return {
|
59
|
+
* @return {SpotArrayType} An array representation of the spot object.
|
94
60
|
*/
|
95
61
|
private spotObjectToArray;
|
96
62
|
/**
|
97
63
|
* Converts an array representation of spot data into an object representation.
|
98
64
|
*
|
99
|
-
* @param {
|
65
|
+
* @param {SpotArrayType} arr - The array containing spot data.
|
100
66
|
* @return {ILocalStorageSpot} An object representation of the spot data.
|
101
67
|
*/
|
102
68
|
private spotArrayToObject;
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@liquidcommercedev/rmn-sdk",
|
3
3
|
"description": "LiquidCommerce RMN SDK",
|
4
4
|
"author": "LiquidCommerce Tech",
|
5
|
-
"version": "1.5.0-beta.
|
5
|
+
"version": "1.5.0-beta.31",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|