Skip to content

Commit defd5fc

Browse files
committed
v13.2.0
1 parent 6ee238b commit defd5fc

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

.DS_Store

0 Bytes
Binary file not shown.

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,12 @@ export namespace Gleap {
8787
): void;
8888
function identify(
8989
userId: string,
90-
customerData: {
91-
name?: string;
92-
email?: string;
93-
phone?: string;
94-
value?: number;
95-
companyId?: string;
96-
companyName?: string;
97-
plan?: string;
98-
customData?: object;
99-
createdAt?: Date;
100-
},
90+
customerData: any,
10191
userHash?: string
10292
): void;
93+
function updateContact(
94+
customerData: any,
95+
): void;
10396
function getInstance(): any;
10497
function open(): void;
10598
function openChecklists(showBackButton?: boolean): void;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "13.1.4",
3+
"version": "13.2.0",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

published/13.2.0/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

published/latest/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Gleap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ class Gleap {
271271
);
272272
}
273273

274+
/**
275+
* Indentifies the user session
276+
* @param {*} userData
277+
*/
278+
static updateContact(userData) {
279+
return GleapSession.getInstance().updateSession(
280+
gleapDataParser(userData),
281+
);
282+
}
283+
274284
/**
275285
* Clears the current user session
276286
*/
@@ -516,6 +526,11 @@ class Gleap {
516526
if (Gleap.getInstance().initialized) {
517527
setTimeout(() => {
518528
Gleap.getInstance().softReInitialize();
529+
530+
// Update language for contact.
531+
Gleap.updateContact({
532+
lang: language,
533+
});
519534
}, 1000);
520535
}
521536
}

src/GleapSession.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,58 @@ export default class GleapSession {
253253
return false;
254254
};
255255

256+
updateSession = (userData) => {
257+
const self = this;
258+
return new Promise((resolve, reject) => {
259+
// Wait for gleap session to be ready.
260+
this.setOnSessionReady(function () {
261+
if (!self.session.gleapId || !self.session.gleapHash) {
262+
return reject("Session not ready yet.");
263+
}
264+
265+
const http = new XMLHttpRequest();
266+
http.open("POST", self.apiUrl + "/sessions/partialupdate");
267+
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
268+
http.setRequestHeader("Api-Token", self.sdkKey);
269+
try {
270+
http.setRequestHeader("Gleap-Id", self.session.gleapId);
271+
http.setRequestHeader("Gleap-Hash", self.session.gleapHash);
272+
} catch (exp) { }
273+
274+
http.onerror = () => {
275+
reject();
276+
};
277+
http.onreadystatechange = function (e) {
278+
if (http.readyState === 4) {
279+
if (http.status === 200 || http.status === 201) {
280+
try {
281+
const sessionData = JSON.parse(http.responseText);
282+
self.validateSession(sessionData);
283+
resolve(sessionData);
284+
} catch (exp) {
285+
reject(exp);
286+
}
287+
} else {
288+
reject();
289+
}
290+
}
291+
};
292+
293+
http.send(
294+
JSON.stringify({
295+
data: {
296+
...userData,
297+
lang: GleapTranslationManager.getInstance().getActiveLanguage(),
298+
},
299+
type: 'js',
300+
sdkVersion: SDK_VERSION,
301+
ws: true,
302+
})
303+
);
304+
});
305+
});
306+
};
307+
256308
identifySession = (userId, userData, userHash) => {
257309
const sessionNeedsUpdate = this.checkIfSessionNeedsUpdate(userId, userData);
258310
if (!sessionNeedsUpdate) {

0 commit comments

Comments
 (0)