releasebird-javascript-sdk 1.0.20 → 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,6 +116,40 @@ 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;
package/src/index.js CHANGED
@@ -86,6 +86,14 @@ class Rbird {
86
86
  }
87
87
  }
88
88
 
89
+ static trackEvent(name, data) {
90
+ try {
91
+ RbirdSessionManager.getInstance().trackEvent(name, data);
92
+ } catch (e) {
93
+ console.error(e);
94
+ }
95
+ }
96
+
89
97
  static identify(identify, hash) {
90
98
  try {
91
99
  RbirdSessionManager.getInstance().identifyUser(identify, hash);