releasebird-javascript-sdk 1.0.37 → 1.0.38

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.
@@ -30,6 +30,9 @@ export default class RbirdSessionManager {
30
30
  };
31
31
 
32
32
  init(apiKey) {
33
+ if (typeof window === 'undefined') {
34
+ return Promise.resolve(null);
35
+ }
33
36
  this.apiKey = apiKey;
34
37
  this.identify = this.getState()?.identify;
35
38
 
@@ -96,6 +99,7 @@ export default class RbirdSessionManager {
96
99
  }
97
100
 
98
101
  getState() {
102
+ if (typeof window === 'undefined') return null;
99
103
  let state = window.localStorage.getItem('rbird_state');
100
104
  if (state) {
101
105
  return JSON.parse(state);
@@ -110,6 +114,7 @@ export default class RbirdSessionManager {
110
114
  }
111
115
 
112
116
  logout() {
117
+ if (typeof window === 'undefined') return;
113
118
  window.localStorage.removeItem('rbird_state');
114
119
  const i = this.generateRandomString();
115
120
  window.localStorage.setItem('Rbird_I', i);
@@ -117,6 +122,7 @@ export default class RbirdSessionManager {
117
122
  }
118
123
 
119
124
  trackEvent(name, data) {
125
+ if (typeof window === 'undefined') return;
120
126
  if (window.localStorage.getItem('rbird_state')) {
121
127
  let state = JSON.parse(window.localStorage.getItem('rbird_state'));
122
128
 
@@ -151,6 +157,7 @@ export default class RbirdSessionManager {
151
157
  }
152
158
 
153
159
  identifyUser(identify, hash) {
160
+ if (typeof window === 'undefined') return;
154
161
  let state = this.getState();
155
162
  state.identify.properties = identify;
156
163
  state.identify.hash = hash;
@@ -44,12 +44,18 @@ export default class RbirdWebsiteWidget {
44
44
  }
45
45
 
46
46
  isMobileDevice = () => {
47
+ if (typeof window === 'undefined') return false;
47
48
  const mobileMaxWidth = 768; // Definiert die maximale Breite für mobile Geräte, z.B. Tablets und Smartphones
48
49
  return window.innerWidth <= mobileMaxWidth;
49
50
  }
50
51
 
51
52
  renderWebsiteWidget() {
52
53
  return new Promise((resolve, reject) => {
54
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
55
+ resolve();
56
+ return;
57
+ }
58
+
53
59
  // Überprüfen, ob das Widget bereits sichtbar ist
54
60
  if (this.websiteWidgetVisible) {
55
61
  resolve(); // Wenn das Widget bereits sichtbar ist, wird das Promise sofort aufgelöst
@@ -100,6 +106,7 @@ export default class RbirdWebsiteWidget {
100
106
  }
101
107
 
102
108
  openWebsiteWidget() {
109
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
103
110
  RbirdUtils.addClass(this.widgetContent, "cta__modal--visible");
104
111
  RbirdUtils.addClass(this.backdrop, "cta__modal-dimmer--visible");
105
112
 
@@ -157,6 +164,7 @@ export default class RbirdWebsiteWidget {
157
164
  }
158
165
 
159
166
  countNotifications() {
167
+ if (typeof window === 'undefined') return;
160
168
  if (RbirdSessionManager.getInstance().identify?.people || RbirdSessionManager.getInstance().anonymousIdentifier) {
161
169
  const http = new XMLHttpRequest();
162
170
  http.open("GET", `${API}/ewidget/unread`);
@@ -213,6 +221,7 @@ export default class RbirdWebsiteWidget {
213
221
  }
214
222
 
215
223
  showButton(showButton) {
224
+ if (typeof window === 'undefined') return;
216
225
  if (showButton && !this.noButton) {
217
226
  this.websiteWidget.style.display = 'block';
218
227
  if (this.hideWidgetButton && !this.noButton) {
@@ -227,6 +236,7 @@ export default class RbirdWebsiteWidget {
227
236
  }
228
237
 
229
238
  closeWebsiteWidget() {
239
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
230
240
  if (this.iframe) {
231
241
  this.iframe.contentWindow?.postMessage({
232
242
  type: 'close',
@@ -304,6 +314,7 @@ export default class RbirdWebsiteWidget {
304
314
  }
305
315
 
306
316
  styleWidget() {
317
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
307
318
  this.websiteWidget.className=RbirdSessionManager.getInstance().widgetSettings.launcher === 5 ? 'launcherButton5' : 'launcherButton' ;
308
319
  this.initButton();
309
320
 
package/src/index.js CHANGED
@@ -6,6 +6,7 @@ import { ReleasebirdConsoleLogger } from "./ReleasebirdConsoleLogger";
6
6
  class Rbird {
7
7
 
8
8
  static isMobileDevice = () => {
9
+ if (typeof window === 'undefined') return false;
9
10
  const mobileMaxWidth = 768; // Definiert die maximale Breite für mobile Geräte, z.B. Tablets und Smartphones
10
11
  return window.innerWidth <= mobileMaxWidth;
11
12
  }
@@ -18,6 +19,7 @@ class Rbird {
18
19
  spaceLeftRight = 30,
19
20
  spaceBottom = 30
20
21
  ) {
22
+ if (typeof window === 'undefined') return;
21
23
  runFunctionWhenDomIsReady(() => {
22
24
  injectStyledCSS(
23
25
  backgroundColor,
@@ -54,6 +56,7 @@ class Rbird {
54
56
  }
55
57
 
56
58
  static showButton(showButton) {
59
+ if (typeof window === 'undefined') return;
57
60
  RbirdWebsiteWidget.getInstance().showButton(showButton);
58
61
  }
59
62
 
@@ -62,6 +65,7 @@ class Rbird {
62
65
  }
63
66
 
64
67
  static initialize(apiKey, showButton) {
68
+ if (typeof window === 'undefined') return;
65
69
  try {
66
70
  if (showButton === undefined) {
67
71
  showButton = true;
@@ -85,6 +89,7 @@ class Rbird {
85
89
  }
86
90
 
87
91
  static showWidget() {
92
+ if (typeof window === 'undefined') return;
88
93
  try {
89
94
  RbirdWebsiteWidget.getInstance().openWebsiteWidget();
90
95
  } catch (e) {
@@ -93,6 +98,7 @@ class Rbird {
93
98
  }
94
99
 
95
100
  static identify(identify, hash) {
101
+ if (typeof window === 'undefined') return;
96
102
  try {
97
103
  RbirdSessionManager.getInstance().identifyUser(identify, hash);
98
104
  } catch (e) {
@@ -101,6 +107,7 @@ class Rbird {
101
107
  }
102
108
 
103
109
  static logout() {
110
+ if (typeof window === 'undefined') return;
104
111
  try {
105
112
  RbirdSessionManager.getInstance().logout();
106
113
  } catch (e) {
@@ -111,6 +118,7 @@ class Rbird {
111
118
  }
112
119
 
113
120
  export const runFunctionWhenDomIsReady = (callback) => {
121
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
114
122
  if (
115
123
  document.readyState === "complete" ||
116
124
  document.readyState === "loaded" ||