Skip to content

Commit 897c9b8

Browse files
committed
v14.2.1
1 parent 9f6ca40 commit 897c9b8

File tree

9 files changed

+327
-596
lines changed

9 files changed

+327
-596
lines changed

build/cjs/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.

build/esm/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

demo/index.html

Lines changed: 114 additions & 309 deletions
Large diffs are not rendered by default.

demo/index2.html

Lines changed: 135 additions & 270 deletions
Large diffs are not rendered by default.

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": "14.2.0",
3+
"version": "14.2.1",
44
"main": "build/cjs/index.js",
55
"module": "build/esm/index.mjs",
66
"exports": {

published/14.2.1/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/GleapProductTours.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { loadIcon } from "./UI";
22
import GleapTours from "./GleapTours";
3-
import Gleap, { GleapEventManager } from "./Gleap";
3+
import Gleap, { GleapEventManager, GleapSession } from "./Gleap";
44
import GleapCopilotTours from "./GleapCopilotTours";
55

66
const localStorageKey = "gleap-tour-data";
@@ -66,25 +66,38 @@ export default class GleapProductTours {
6666

6767
const self = this;
6868

69-
if (delay > 0) {
70-
return setTimeout(() => {
71-
self.start();
72-
}, delay);
73-
} else {
74-
return this.start();
75-
}
69+
// Validate product tour.
70+
GleapSession.getInstance()
71+
.validateProductTour(tourId)
72+
.then(() => {
73+
console.log("Product tour is live.");
74+
if (delay > 0) {
75+
return setTimeout(() => {
76+
self.start();
77+
}, delay);
78+
} else {
79+
return this.start();
80+
}
81+
})
82+
.catch((error) => {
83+
console.log("Product tour is not live. Cleaning up...");
84+
console.error(error);
85+
86+
self.onComplete(false);
87+
});
7688
}
7789

7890
onComplete(success = true) {
79-
if (success) {
80-
const comData = {
81-
tourId: this.productTourId,
82-
};
91+
const comData = {
92+
tourId: this.productTourId,
93+
};
8394

95+
if (success) {
8496
GleapEventManager.notifyEvent("productTourCompleted", comData);
8597
Gleap.trackEvent(`tour-${this.productTourId}-completed`, comData);
8698
} else {
87-
console.warn("[Product tour] Selector not found");
99+
GleapEventManager.notifyEvent("productTourQuit", comData);
100+
Gleap.trackEvent(`tour-${this.productTourId}-quit`, comData);
88101
}
89102

90103
// Clear data.

src/GleapSession.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,51 @@ export default class GleapSession {
483483
});
484484
});
485485
};
486+
487+
validateProductTour = (tourId) => {
488+
const self = this;
489+
return new Promise((resolve, reject) => {
490+
this.setOnSessionReady(function () {
491+
if (!self.session.gleapId || !self.session.gleapHash) {
492+
return reject("Session not ready yet.");
493+
}
494+
495+
const http = new XMLHttpRequest();
496+
http.open("POST", self.apiUrl + "/outbound/producttourvalidation");
497+
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
498+
http.setRequestHeader("Api-Token", self.sdkKey);
499+
try {
500+
http.setRequestHeader("Gleap-Id", self.session.gleapId);
501+
http.setRequestHeader("Gleap-Hash", self.session.gleapHash);
502+
} catch (exp) {}
503+
504+
http.onerror = () => {
505+
reject();
506+
};
507+
http.onreadystatechange = function (e) {
508+
if (http.readyState === 4) {
509+
if (http.status === 200 || http.status === 201) {
510+
try {
511+
const tourData = JSON.parse(http.responseText);
512+
if (tourData && tourData.status === "live") {
513+
resolve(tourData.config);
514+
} else {
515+
reject();
516+
}
517+
} catch (exp) {
518+
reject(exp);
519+
}
520+
} else {
521+
reject();
522+
}
523+
}
524+
};
525+
http.send(
526+
JSON.stringify({
527+
outboundId: tourId,
528+
})
529+
);
530+
});
531+
});
532+
};
486533
}

0 commit comments

Comments
 (0)