releasebird-javascript-sdk 1.0.19 → 1.0.21

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.
@@ -116,10 +116,44 @@ export default class RbirdSessionManager {
116
116
  RbirdWebsiteWidget.getInstance().updateIframe(`${CONTENT_URL}/widget?apiKey=${RbirdSessionManager.getInstance().apiKey}&tab=HOME&people=null&hash=null&ai=${i}`);
117
117
  }
118
118
 
119
+ trackEvent(name, data) {
120
+
121
+ let state = window.localStorage.getItem('rbird_state');
122
+
123
+ let request = {}
124
+ request.name = name;
125
+ request.peopleId = state?.identify?.people;
126
+ request.data = data || {};
127
+ const http = new XMLHttpRequest();
128
+ http.open("POST", `${API}/events`);
129
+ http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
130
+ http.setRequestHeader("timezone", Intl.DateTimeFormat().resolvedOptions().timeZone);
131
+ http.setRequestHeader("apiKey", this.apiKey);
132
+ http.onerror = (error) => {
133
+ //handle error
134
+ };
135
+ let self = this;
136
+ http.onreadystatechange = function (e) {
137
+ if (http.readyState === 4) {
138
+ if (http.status === 200 || http.status === 201) {
139
+ try {
140
+ //handle success
141
+ } catch (exp) {
142
+ //handle error
143
+ }
144
+ } else {
145
+ //handle error
146
+ }
147
+ }
148
+ };
149
+ http.send(JSON.stringify(state));
150
+
151
+ }
152
+
119
153
  identifyUser(identify, hash) {
120
154
  let state = this.getState();
121
155
  state.identify.properties = identify;
122
- state.identify.hash = identify.hash;
156
+ state.identify.hash = hash;
123
157
  const http = new XMLHttpRequest();
124
158
  http.open("POST", `${API}/ewidget/identify`);
125
159
  http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
package/src/index.js CHANGED
@@ -52,7 +52,6 @@ class Rbird {
52
52
  }
53
53
 
54
54
  static initialize(apiKey) {
55
- console.log('bin in init');
56
55
  initialize(apiKey, true);
57
56
  }
58
57
 
@@ -61,7 +60,6 @@ class Rbird {
61
60
  if (showButton === undefined) {
62
61
  showButton = true;
63
62
  }
64
- console.log('bin in init');
65
63
  const instance = this.getInstance();
66
64
  if (instance.initialized) {
67
65
  console.warn("Rbird already initialized.");
@@ -71,7 +69,6 @@ class Rbird {
71
69
  RbirdSessionManager.getInstance().init(apiKey).then(() => {
72
70
  instance.initialized = true;
73
71
  if (showButton) {
74
- console.log('bin in show button');
75
72
  RbirdWebsiteWidget.getInstance().showButton(showButton);
76
73
  }
77
74
  })
@@ -89,6 +86,14 @@ class Rbird {
89
86
  }
90
87
  }
91
88
 
89
+ static trackEvent(name, data) {
90
+ try {
91
+ RbirdSessionManager.getInstance().trackEvent(name, data);
92
+ } catch (e) {
93
+ console.error(e);
94
+ }
95
+ }
96
+
92
97
  static identify(identify, hash) {
93
98
  try {
94
99
  RbirdSessionManager.getInstance().identifyUser(identify, hash);