@liquidcommercedev/rmn-sdk 1.5.0-beta.4 → 1.5.0-beta.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +119 -8
- package/dist/index.esm.js +119 -8
- package/dist/types/modules/event/helpers/datalayer.monitor.d.ts +10 -0
- package/dist/types/modules/event/helpers/index.d.ts +1 -0
- package/dist/types/modules/event/helpers/localstorage.service.d.ts +7 -2
- package/dist/types/modules/event/index.d.ts +1 -0
- package/dist/types/modules/event/user.monitor.d.ts +13 -0
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
package/dist/index.cjs
CHANGED
@@ -15166,6 +15166,40 @@ const GFONT_CORMORANT = `
|
|
15166
15166
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Cormorant:ital,wght@0,300..700;1,300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap">
|
15167
15167
|
`;
|
15168
15168
|
|
15169
|
+
class DataLayerMonitor {
|
15170
|
+
constructor() {
|
15171
|
+
if (!window.dataLayer) {
|
15172
|
+
return;
|
15173
|
+
}
|
15174
|
+
this.originalPush = window.dataLayer.push;
|
15175
|
+
}
|
15176
|
+
static getInstance() {
|
15177
|
+
if (!DataLayerMonitor.instance) {
|
15178
|
+
DataLayerMonitor.instance = new DataLayerMonitor();
|
15179
|
+
}
|
15180
|
+
return DataLayerMonitor.instance;
|
15181
|
+
}
|
15182
|
+
setListener(listener) {
|
15183
|
+
this.listener = listener;
|
15184
|
+
}
|
15185
|
+
start() {
|
15186
|
+
window.dataLayer.push = (...args) => {
|
15187
|
+
const result = this.originalPush.apply(window.dataLayer, args);
|
15188
|
+
const pushedEvent = args[0];
|
15189
|
+
if (this.listener) {
|
15190
|
+
this.listener(pushedEvent);
|
15191
|
+
}
|
15192
|
+
return result;
|
15193
|
+
};
|
15194
|
+
}
|
15195
|
+
stop() {
|
15196
|
+
if (this.originalPush) {
|
15197
|
+
window.dataLayer.push = this.originalPush;
|
15198
|
+
}
|
15199
|
+
this.listener = undefined;
|
15200
|
+
}
|
15201
|
+
}
|
15202
|
+
|
15169
15203
|
class IntersectionObserverService {
|
15170
15204
|
constructor(defaultOptions = {}) {
|
15171
15205
|
this.observers = new Map();
|
@@ -15244,24 +15278,28 @@ class LocalStorage {
|
|
15244
15278
|
}
|
15245
15279
|
}
|
15246
15280
|
setSpot(spotId, data) {
|
15247
|
-
|
15248
|
-
return;
|
15281
|
+
var _a;
|
15249
15282
|
data.createdAt = Date.now();
|
15250
|
-
this.spots.set(spotId, data);
|
15283
|
+
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.set(spotId, data);
|
15251
15284
|
this.updateLocalStorage();
|
15252
15285
|
}
|
15253
|
-
getSpot(spotId) {
|
15254
|
-
var _a;
|
15255
|
-
return (_a = this.spots) === null || _a === void 0 ? void 0 : _a.get(spotId);
|
15256
|
-
}
|
15257
15286
|
removeSpot(spotId) {
|
15258
15287
|
var _a;
|
15259
15288
|
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.delete(spotId);
|
15260
15289
|
this.updateLocalStorage();
|
15261
15290
|
}
|
15291
|
+
getSpot(spotId) {
|
15292
|
+
var _a;
|
15293
|
+
return (_a = this.spots) === null || _a === void 0 ? void 0 : _a.get(spotId);
|
15294
|
+
}
|
15295
|
+
getSpots() {
|
15296
|
+
if (!this.spots)
|
15297
|
+
return undefined;
|
15298
|
+
return this.mapToObj(this.spots);
|
15299
|
+
}
|
15262
15300
|
updateLocalStorage() {
|
15263
15301
|
if (!this.spots)
|
15264
|
-
return;
|
15302
|
+
return undefined;
|
15265
15303
|
const data = this.mapToObj(this.spots);
|
15266
15304
|
localStorage.setItem(LocalStorage.localStorageKey, JSON.stringify(data));
|
15267
15305
|
}
|
@@ -18056,6 +18094,73 @@ class PubSub {
|
|
18056
18094
|
* unsubscribeLogin();
|
18057
18095
|
*/
|
18058
18096
|
|
18097
|
+
// @TODO: Add support for user to push events to our own data layer, if they don't use any analytics tool.
|
18098
|
+
// window.rmnDataLayer = window.rmnDataLayer || [];
|
18099
|
+
// For the moment, we will only focus on sites that use Google Analytics,
|
18100
|
+
// but we will add support for other analytics tools in the future.
|
18101
|
+
var AnalyticsTool;
|
18102
|
+
(function (AnalyticsTool) {
|
18103
|
+
AnalyticsTool["GoogleAnalytics"] = "google-analytics";
|
18104
|
+
AnalyticsTool["Other"] = "Other";
|
18105
|
+
})(AnalyticsTool || (AnalyticsTool = {}));
|
18106
|
+
class UserMonitor {
|
18107
|
+
constructor() {
|
18108
|
+
const analyticsTool = this.detectAnalyticsTool();
|
18109
|
+
console.info({ analyticsTool });
|
18110
|
+
switch (analyticsTool) {
|
18111
|
+
case AnalyticsTool.GoogleAnalytics:
|
18112
|
+
this.implementedMonitor = DataLayerMonitor.getInstance();
|
18113
|
+
break;
|
18114
|
+
case AnalyticsTool.Other:
|
18115
|
+
default:
|
18116
|
+
console.warn('This site uses an unsupported analytics tool.');
|
18117
|
+
break;
|
18118
|
+
}
|
18119
|
+
if (analyticsTool === AnalyticsTool.Other) {
|
18120
|
+
return;
|
18121
|
+
}
|
18122
|
+
this.localStorage = LocalStorage.getInstance();
|
18123
|
+
}
|
18124
|
+
static getInstance() {
|
18125
|
+
if (!UserMonitor.instance) {
|
18126
|
+
UserMonitor.instance = new UserMonitor();
|
18127
|
+
}
|
18128
|
+
return UserMonitor.instance;
|
18129
|
+
}
|
18130
|
+
start() {
|
18131
|
+
if (!this.implementedMonitor)
|
18132
|
+
return;
|
18133
|
+
this.implementedMonitor.setListener((pushedEvent) => {
|
18134
|
+
var _a;
|
18135
|
+
console.info({ pushedEvent });
|
18136
|
+
console.info({ spots: (_a = this.localStorage) === null || _a === void 0 ? void 0 : _a.getSpots() });
|
18137
|
+
});
|
18138
|
+
this.implementedMonitor.start();
|
18139
|
+
}
|
18140
|
+
detectAnalyticsTool() {
|
18141
|
+
let analyticsTool = AnalyticsTool.Other;
|
18142
|
+
// Check for Google Analytics
|
18143
|
+
if (typeof window.ga !== 'undefined') {
|
18144
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18145
|
+
}
|
18146
|
+
// Check for Google Analytics 4
|
18147
|
+
if (typeof window.gtag !== 'undefined') {
|
18148
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18149
|
+
}
|
18150
|
+
// Check for Google Tag Manager
|
18151
|
+
if (typeof window.google_tag_manager !== 'undefined') {
|
18152
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18153
|
+
}
|
18154
|
+
// @TODO: Add support for other analytics tools
|
18155
|
+
// Check for Heap Analytics
|
18156
|
+
// Check for Mixpanel
|
18157
|
+
// Check for Woopra
|
18158
|
+
// Check for Segment
|
18159
|
+
// Check for Amplitude
|
18160
|
+
return analyticsTool;
|
18161
|
+
}
|
18162
|
+
}
|
18163
|
+
|
18059
18164
|
class EventService {
|
18060
18165
|
constructor() {
|
18061
18166
|
this.pubSub = PubSub.getInstance();
|
@@ -18063,6 +18168,8 @@ class EventService {
|
|
18063
18168
|
this.activeSpots = new Map();
|
18064
18169
|
this.spotStates = new Map();
|
18065
18170
|
this.intersectionObserver = new IntersectionObserverService();
|
18171
|
+
// Start the user monitor, which will track and check user interactions
|
18172
|
+
UserMonitor.getInstance().start();
|
18066
18173
|
}
|
18067
18174
|
static getInstance() {
|
18068
18175
|
if (!EventService.instance) {
|
@@ -18507,6 +18614,10 @@ class LiquidCommerceRmnClient {
|
|
18507
18614
|
*/
|
18508
18615
|
async injectSpotElement(params) {
|
18509
18616
|
var _a;
|
18617
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
18618
|
+
console.warn('LiquidCommerce Rmn Sdk: Methods which create elements are only available in browser environments.');
|
18619
|
+
return;
|
18620
|
+
}
|
18510
18621
|
const config = params.config;
|
18511
18622
|
let inject = params.inject;
|
18512
18623
|
if (!inject.length) {
|
package/dist/index.esm.js
CHANGED
@@ -15164,6 +15164,40 @@ const GFONT_CORMORANT = `
|
|
15164
15164
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Cormorant:ital,wght@0,300..700;1,300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap">
|
15165
15165
|
`;
|
15166
15166
|
|
15167
|
+
class DataLayerMonitor {
|
15168
|
+
constructor() {
|
15169
|
+
if (!window.dataLayer) {
|
15170
|
+
return;
|
15171
|
+
}
|
15172
|
+
this.originalPush = window.dataLayer.push;
|
15173
|
+
}
|
15174
|
+
static getInstance() {
|
15175
|
+
if (!DataLayerMonitor.instance) {
|
15176
|
+
DataLayerMonitor.instance = new DataLayerMonitor();
|
15177
|
+
}
|
15178
|
+
return DataLayerMonitor.instance;
|
15179
|
+
}
|
15180
|
+
setListener(listener) {
|
15181
|
+
this.listener = listener;
|
15182
|
+
}
|
15183
|
+
start() {
|
15184
|
+
window.dataLayer.push = (...args) => {
|
15185
|
+
const result = this.originalPush.apply(window.dataLayer, args);
|
15186
|
+
const pushedEvent = args[0];
|
15187
|
+
if (this.listener) {
|
15188
|
+
this.listener(pushedEvent);
|
15189
|
+
}
|
15190
|
+
return result;
|
15191
|
+
};
|
15192
|
+
}
|
15193
|
+
stop() {
|
15194
|
+
if (this.originalPush) {
|
15195
|
+
window.dataLayer.push = this.originalPush;
|
15196
|
+
}
|
15197
|
+
this.listener = undefined;
|
15198
|
+
}
|
15199
|
+
}
|
15200
|
+
|
15167
15201
|
class IntersectionObserverService {
|
15168
15202
|
constructor(defaultOptions = {}) {
|
15169
15203
|
this.observers = new Map();
|
@@ -15242,24 +15276,28 @@ class LocalStorage {
|
|
15242
15276
|
}
|
15243
15277
|
}
|
15244
15278
|
setSpot(spotId, data) {
|
15245
|
-
|
15246
|
-
return;
|
15279
|
+
var _a;
|
15247
15280
|
data.createdAt = Date.now();
|
15248
|
-
this.spots.set(spotId, data);
|
15281
|
+
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.set(spotId, data);
|
15249
15282
|
this.updateLocalStorage();
|
15250
15283
|
}
|
15251
|
-
getSpot(spotId) {
|
15252
|
-
var _a;
|
15253
|
-
return (_a = this.spots) === null || _a === void 0 ? void 0 : _a.get(spotId);
|
15254
|
-
}
|
15255
15284
|
removeSpot(spotId) {
|
15256
15285
|
var _a;
|
15257
15286
|
(_a = this.spots) === null || _a === void 0 ? void 0 : _a.delete(spotId);
|
15258
15287
|
this.updateLocalStorage();
|
15259
15288
|
}
|
15289
|
+
getSpot(spotId) {
|
15290
|
+
var _a;
|
15291
|
+
return (_a = this.spots) === null || _a === void 0 ? void 0 : _a.get(spotId);
|
15292
|
+
}
|
15293
|
+
getSpots() {
|
15294
|
+
if (!this.spots)
|
15295
|
+
return undefined;
|
15296
|
+
return this.mapToObj(this.spots);
|
15297
|
+
}
|
15260
15298
|
updateLocalStorage() {
|
15261
15299
|
if (!this.spots)
|
15262
|
-
return;
|
15300
|
+
return undefined;
|
15263
15301
|
const data = this.mapToObj(this.spots);
|
15264
15302
|
localStorage.setItem(LocalStorage.localStorageKey, JSON.stringify(data));
|
15265
15303
|
}
|
@@ -18054,6 +18092,73 @@ class PubSub {
|
|
18054
18092
|
* unsubscribeLogin();
|
18055
18093
|
*/
|
18056
18094
|
|
18095
|
+
// @TODO: Add support for user to push events to our own data layer, if they don't use any analytics tool.
|
18096
|
+
// window.rmnDataLayer = window.rmnDataLayer || [];
|
18097
|
+
// For the moment, we will only focus on sites that use Google Analytics,
|
18098
|
+
// but we will add support for other analytics tools in the future.
|
18099
|
+
var AnalyticsTool;
|
18100
|
+
(function (AnalyticsTool) {
|
18101
|
+
AnalyticsTool["GoogleAnalytics"] = "google-analytics";
|
18102
|
+
AnalyticsTool["Other"] = "Other";
|
18103
|
+
})(AnalyticsTool || (AnalyticsTool = {}));
|
18104
|
+
class UserMonitor {
|
18105
|
+
constructor() {
|
18106
|
+
const analyticsTool = this.detectAnalyticsTool();
|
18107
|
+
console.info({ analyticsTool });
|
18108
|
+
switch (analyticsTool) {
|
18109
|
+
case AnalyticsTool.GoogleAnalytics:
|
18110
|
+
this.implementedMonitor = DataLayerMonitor.getInstance();
|
18111
|
+
break;
|
18112
|
+
case AnalyticsTool.Other:
|
18113
|
+
default:
|
18114
|
+
console.warn('This site uses an unsupported analytics tool.');
|
18115
|
+
break;
|
18116
|
+
}
|
18117
|
+
if (analyticsTool === AnalyticsTool.Other) {
|
18118
|
+
return;
|
18119
|
+
}
|
18120
|
+
this.localStorage = LocalStorage.getInstance();
|
18121
|
+
}
|
18122
|
+
static getInstance() {
|
18123
|
+
if (!UserMonitor.instance) {
|
18124
|
+
UserMonitor.instance = new UserMonitor();
|
18125
|
+
}
|
18126
|
+
return UserMonitor.instance;
|
18127
|
+
}
|
18128
|
+
start() {
|
18129
|
+
if (!this.implementedMonitor)
|
18130
|
+
return;
|
18131
|
+
this.implementedMonitor.setListener((pushedEvent) => {
|
18132
|
+
var _a;
|
18133
|
+
console.info({ pushedEvent });
|
18134
|
+
console.info({ spots: (_a = this.localStorage) === null || _a === void 0 ? void 0 : _a.getSpots() });
|
18135
|
+
});
|
18136
|
+
this.implementedMonitor.start();
|
18137
|
+
}
|
18138
|
+
detectAnalyticsTool() {
|
18139
|
+
let analyticsTool = AnalyticsTool.Other;
|
18140
|
+
// Check for Google Analytics
|
18141
|
+
if (typeof window.ga !== 'undefined') {
|
18142
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18143
|
+
}
|
18144
|
+
// Check for Google Analytics 4
|
18145
|
+
if (typeof window.gtag !== 'undefined') {
|
18146
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18147
|
+
}
|
18148
|
+
// Check for Google Tag Manager
|
18149
|
+
if (typeof window.google_tag_manager !== 'undefined') {
|
18150
|
+
analyticsTool = AnalyticsTool.GoogleAnalytics;
|
18151
|
+
}
|
18152
|
+
// @TODO: Add support for other analytics tools
|
18153
|
+
// Check for Heap Analytics
|
18154
|
+
// Check for Mixpanel
|
18155
|
+
// Check for Woopra
|
18156
|
+
// Check for Segment
|
18157
|
+
// Check for Amplitude
|
18158
|
+
return analyticsTool;
|
18159
|
+
}
|
18160
|
+
}
|
18161
|
+
|
18057
18162
|
class EventService {
|
18058
18163
|
constructor() {
|
18059
18164
|
this.pubSub = PubSub.getInstance();
|
@@ -18061,6 +18166,8 @@ class EventService {
|
|
18061
18166
|
this.activeSpots = new Map();
|
18062
18167
|
this.spotStates = new Map();
|
18063
18168
|
this.intersectionObserver = new IntersectionObserverService();
|
18169
|
+
// Start the user monitor, which will track and check user interactions
|
18170
|
+
UserMonitor.getInstance().start();
|
18064
18171
|
}
|
18065
18172
|
static getInstance() {
|
18066
18173
|
if (!EventService.instance) {
|
@@ -18505,6 +18612,10 @@ class LiquidCommerceRmnClient {
|
|
18505
18612
|
*/
|
18506
18613
|
async injectSpotElement(params) {
|
18507
18614
|
var _a;
|
18615
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
18616
|
+
console.warn('LiquidCommerce Rmn Sdk: Methods which create elements are only available in browser environments.');
|
18617
|
+
return;
|
18618
|
+
}
|
18508
18619
|
const config = params.config;
|
18509
18620
|
let inject = params.inject;
|
18510
18621
|
if (!inject.length) {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare class DataLayerMonitor {
|
2
|
+
private static instance;
|
3
|
+
private readonly originalPush;
|
4
|
+
private listener?;
|
5
|
+
private constructor();
|
6
|
+
static getInstance(): DataLayerMonitor;
|
7
|
+
setListener(listener: (data: any) => void): void;
|
8
|
+
start(): void;
|
9
|
+
stop(): void;
|
10
|
+
}
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import type { RMN_SPOT_TYPE } from 'enums';
|
2
2
|
import type { ISpotEvent } from 'modules/selection';
|
3
|
+
export type LocalStorageSpotsMapType = Map<string, // spotId
|
4
|
+
ILocalStorageSpot>;
|
5
|
+
export type LocalStorageSpotsObjType = Record<string, // spotId
|
6
|
+
ILocalStorageSpot>;
|
3
7
|
export interface ILocalStorageSpot {
|
4
8
|
spotId: string;
|
5
9
|
spotType: RMN_SPOT_TYPE;
|
@@ -16,10 +20,11 @@ export declare class LocalStorage {
|
|
16
20
|
static getInstance(): LocalStorage;
|
17
21
|
private syncLocalStorage;
|
18
22
|
setSpot(spotId: string, data: ILocalStorageSpot): void;
|
19
|
-
getSpot(spotId: string): ILocalStorageSpot | undefined;
|
20
23
|
removeSpot(spotId: string): void;
|
24
|
+
getSpot(spotId: string): ILocalStorageSpot | undefined;
|
25
|
+
getSpots(): LocalStorageSpotsObjType | undefined;
|
21
26
|
private updateLocalStorage;
|
22
|
-
clearLocalStorage
|
27
|
+
private clearLocalStorage;
|
23
28
|
private removeExpiredSpots;
|
24
29
|
private mapToObj;
|
25
30
|
private objToMap;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export declare enum AnalyticsTool {
|
2
|
+
GoogleAnalytics = "google-analytics",
|
3
|
+
Other = "Other"
|
4
|
+
}
|
5
|
+
export declare class UserMonitor {
|
6
|
+
private static instance;
|
7
|
+
private readonly implementedMonitor?;
|
8
|
+
private readonly localStorage?;
|
9
|
+
private constructor();
|
10
|
+
static getInstance(): UserMonitor;
|
11
|
+
start(): void;
|
12
|
+
private detectAnalyticsTool;
|
13
|
+
}
|
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.5",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|