Skip to content

Commit

Permalink
v13.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
boehlerlukas committed Jan 31, 2024
1 parent 6ee238b commit defd5fc
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 14 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,12 @@ export namespace Gleap {
): void;
function identify(
userId: string,
customerData: {
name?: string;
email?: string;
phone?: string;
value?: number;
companyId?: string;
companyName?: string;
plan?: string;
customData?: object;
createdAt?: Date;
},
customerData: any,
userHash?: string
): void;
function updateContact(
customerData: any,
): void;
function getInstance(): any;
function open(): void;
function openChecklists(showBackButton?: boolean): void;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gleap",
"version": "13.1.4",
"version": "13.2.0",
"main": "build/index.js",
"scripts": {
"start": "webpack serve",
Expand Down
1 change: 1 addition & 0 deletions published/13.2.0/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion published/latest/index.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/Gleap.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ class Gleap {
);
}

/**
* Indentifies the user session
* @param {*} userData
*/
static updateContact(userData) {
return GleapSession.getInstance().updateSession(
gleapDataParser(userData),
);
}

/**
* Clears the current user session
*/
Expand Down Expand Up @@ -516,6 +526,11 @@ class Gleap {
if (Gleap.getInstance().initialized) {
setTimeout(() => {
Gleap.getInstance().softReInitialize();

// Update language for contact.
Gleap.updateContact({
lang: language,
});
}, 1000);
}
}
Expand Down
52 changes: 52 additions & 0 deletions src/GleapSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,58 @@ export default class GleapSession {
return false;
};

updateSession = (userData) => {
const self = this;
return new Promise((resolve, reject) => {
// Wait for gleap session to be ready.
this.setOnSessionReady(function () {
if (!self.session.gleapId || !self.session.gleapHash) {
return reject("Session not ready yet.");
}

const http = new XMLHttpRequest();
http.open("POST", self.apiUrl + "/sessions/partialupdate");
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
http.setRequestHeader("Api-Token", self.sdkKey);
try {
http.setRequestHeader("Gleap-Id", self.session.gleapId);
http.setRequestHeader("Gleap-Hash", self.session.gleapHash);
} catch (exp) { }

http.onerror = () => {
reject();
};
http.onreadystatechange = function (e) {
if (http.readyState === 4) {
if (http.status === 200 || http.status === 201) {
try {
const sessionData = JSON.parse(http.responseText);
self.validateSession(sessionData);
resolve(sessionData);
} catch (exp) {
reject(exp);
}
} else {
reject();
}
}
};

http.send(
JSON.stringify({
data: {
...userData,
lang: GleapTranslationManager.getInstance().getActiveLanguage(),
},
type: 'js',
sdkVersion: SDK_VERSION,
ws: true,
})
);
});
});
};

identifySession = (userId, userData, userHash) => {
const sessionNeedsUpdate = this.checkIfSessionNeedsUpdate(userId, userData);
if (!sessionNeedsUpdate) {
Expand Down

0 comments on commit defd5fc

Please sign in to comment.