Skip to content

Commit 9812152

Browse files
committed
Cleanup.
1 parent c415154 commit 9812152

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/Gleap.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,14 @@ class Gleap {
10381038
}
10391039

10401040
static startProductTour(tourId, config) {
1041+
GleapProductTours.getInstance().startWithConfig(tourId, config, (data) => {
1042+
const comData = {
1043+
tourId: data.tourId,
1044+
};
10411045

1042-
GleapProductTours.getInstance().startWithConfig(tourId, config);
1046+
GleapEventManager.notifyEvent("productTourCompleted", comData);
1047+
Gleap.trackEvent(`tour-${data.tourId}-completed`, comData);
1048+
});
10431049
}
10441050

10451051
static showBanner(data) {

src/GleapProductTours.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import GleapTours from "./GleapTours";
44
export default class GleapProductTours {
55
productTourData = undefined;
66
productTourId = undefined;
7+
onCompletion = undefined;
78

89
// GleapReplayRecorder singleton
910
static instance;
@@ -18,9 +19,10 @@ export default class GleapProductTours {
1819

1920
constructor() { }
2021

21-
startWithConfig(tourId, config) {
22+
startWithConfig(tourId, config, onCompletion) {
2223
this.productTourId = tourId;
2324
this.productTourData = config;
25+
this.onCompletion = onCompletion;
2426

2527
return this.start();
2628
}
@@ -32,6 +34,7 @@ export default class GleapProductTours {
3234
}
3335

3436
const steps = config.steps;
37+
const self = this;
3538

3639
var driverSteps = [];
3740

@@ -71,7 +74,7 @@ export default class GleapProductTours {
7174
driverSteps.push(driverStep);
7275
}
7376

74-
const driverObj = GleapTours({
77+
const gleapTourObj = GleapTours({
7578
showProgress: true,
7679
steps: driverSteps,
7780
allowClose: config.allowClose,
@@ -81,25 +84,26 @@ export default class GleapProductTours {
8184
'next',
8285
'close'
8386
],
87+
onDestroyStarted: () => {
88+
if (!gleapTourObj.hasNextStep()) {
89+
gleapTourObj.destroy();
90+
91+
if (self.onCompletion) {
92+
self.onCompletion({
93+
tourId: self.productTourId
94+
});
95+
}
96+
}
97+
},
8498
onPopoverRender: (popoverElement) => {
8599
// Fix for images and videos.
86100
if (popoverElement) {
87101
const mediaElements = document.querySelectorAll('.gleap-tour-popover-description img, .gleap-tour-popover-description video');
88102

89103
const performRequentialRefresh = () => {
90-
driverObj.refresh();
91-
92-
setTimeout(() => {
93-
driverObj.refresh();
94-
}, 250);
95-
96-
setTimeout(() => {
97-
driverObj.refresh();
98-
}, 500);
99-
100104
setTimeout(() => {
101-
driverObj.refresh();
102-
}, 1000);
105+
gleapTourObj.refresh();
106+
}, 750);
103107
};
104108

105109
for (let i = 0; i < mediaElements.length; i++) {
@@ -154,6 +158,6 @@ export default class GleapProductTours {
154158
}
155159
}
156160
});
157-
driverObj.drive();
161+
gleapTourObj.drive();
158162
}
159163
}

0 commit comments

Comments
 (0)