Skip to content

Commit

Permalink
Merge pull request #40 from GleapSDK/tooltipsnew
Browse files Browse the repository at this point in the history
Tooltips
  • Loading branch information
boehlerlukas authored Apr 22, 2024
2 parents 570813b + 65a29bc commit e407f25
Show file tree
Hide file tree
Showing 15 changed files with 682 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/cjs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/esm/index.mjs

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ <h2 class="sub-headline">
}

</script>

<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: "vm8dcoo6"
};
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Gleap.on("tool-execution", (tool) => {
Gleap.setTicketAttribute("notes", "This is a test value.");*/

Gleap.initialize("ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV");
Gleap.initialize("Vx0SXWPHGU7Af54CabNL07k6HRELKTxu");
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gleap",
"version": "13.5.16",
"version": "13.6.0",
"main": "build/cjs/index.js",
"module": "build/esm/index.mjs",
"exports": {
Expand Down Expand Up @@ -70,7 +70,8 @@
}
},
"dependencies": {
"@floating-ui/dom": "^1.6.3",
"pick-dom-element": "^0.2.3",
"unique-selector": "^0.5.0"
}
}
}
2 changes: 1 addition & 1 deletion published/13.5.16/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions published/13.6.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.

45 changes: 45 additions & 0 deletions src/Gleap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,50 @@ if (typeof window !== "undefined") {
}
}

const handleGleapLink = (href) => {
try {
// gleap://article/123
const urlParts = href.split('/');
const type = urlParts[2];
if (type === 'article') {
const identifier = urlParts[3];
Gleap.openHelpCenterArticle(identifier);
}

if (type === 'collection') {
const identifier = urlParts[3];
Gleap.openHelpCenterCollection(identifier);
}

if (type === 'survey') {
const identifier = urlParts[3];
Gleap.showSurvey(identifier);
}

if (type === 'bot') {
const identifier = urlParts[3];
Gleap.startBot(identifier);
}

if (type === 'news') {
const identifier = urlParts[3];
Gleap.openNews(identifier);
}

if (type === 'checklist') {
const identifier = urlParts[3];
Gleap.startChecklist(identifier);
}

if (type === 'tour') {
const identifier = urlParts[3];
Gleap.startProductTour(identifier);
}
} catch (e) {
console.error("Failed to handle Gleap link: ", href);
}
}

export {
GleapNetworkIntercepter,
GleapAudioManager,
Expand All @@ -1206,5 +1250,6 @@ export {
GleapFrameManager,
GleapMetaDataManager,
GleapTagManager,
handleGleapLink,
};
export default Gleap;
18 changes: 16 additions & 2 deletions src/GleapAdminManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ export default class GleapAdminManager {
self.configData = data.data;
self.initAdminHelper();
}

if (data.name === "smartlink-search-result") {
this.sendMessageToTourBuilder({
name: "smartlink-search-result",
data: data.data,
});
}
}

if (data.type === "tourbuilder") {
Expand All @@ -116,6 +123,13 @@ export default class GleapAdminManager {
});
}

if (data.name === "smartlink-search") {
this.sendMessage({
name: "smartlink-search",
data: data.data,
});
}

if (data.name === "save") {
this.sendMessage({
name: "save",
Expand All @@ -141,7 +155,7 @@ export default class GleapAdminManager {
}
}
}
} catch (exp) {}
} catch (exp) { }
});

this.sendMessage({
Expand Down Expand Up @@ -226,7 +240,7 @@ export default class GleapAdminManager {
var elem = document.createElement("div");
elem.className =
"gleap-admin-frame-container";
elem.innerHTML = `<iframe src="https://app.gleap.io/producttourbuilder" class="gleap-admin-frame" scrolling="no" title="Gleap Admin Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe>`;
elem.innerHTML = `<iframe src="https://app.gleap.io/${this?.configData?.type === 'tooltips' ? 'tooltipbuilder' : 'producttourbuilder'}" class="gleap-admin-frame" scrolling="no" title="Gleap Admin Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe>`;
document.body.appendChild(elem);

this.gleapFrameContainer = elem;
Expand Down
15 changes: 11 additions & 4 deletions src/GleapClickListener.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GleapConsoleLogManager, GleapFrameManager } from "./Gleap";
import { GleapConsoleLogManager, GleapFrameManager, handleGleapLink } from "./Gleap";
import { getDOMElementDescription } from "./GleapHelper";

export default class GleapClickListener {
Expand All @@ -11,14 +11,21 @@ export default class GleapClickListener {
}

start() {
document.addEventListener("click", (event) => {
if (!event.target) {
document.addEventListener("click", (e) => {
if (!e.target) {
return;
}

if (e.target.tagName === 'A' && e.target.protocol === 'gleap:') {
e.preventDefault();

const href = e.target.href;
handleGleapLink(href);
}

if (!GleapFrameManager.getInstance().isOpened()) {
GleapConsoleLogManager.getInstance().addLog(
getDOMElementDescription(event.target),
getDOMElementDescription(e.target),
"CLICK"
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/GleapSession.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GleapEventManager, GleapTranslationManager, GleapFrameManager, GleapNotificationManager, GleapStreamedEvent, GleapBannerManager } from "./Gleap";
import { eraseGleapCookie, getGleapCookie, loadFromGleapCache, saveToGleapCache, setGleapCookie } from "./GleapHelper";
import GleapTooltipManager from "./GleapTooltipManager";

export default class GleapSession {
apiUrl = "https://api.gleap.io";
Expand Down Expand Up @@ -201,6 +202,9 @@ export default class GleapSession {

// Initially track.
GleapStreamedEvent.getInstance().restart();

// Load tooltips.
GleapTooltipManager.getInstance().load();
} catch (exp) { }
} else {
if (http.status !== 429) {
Expand Down Expand Up @@ -341,6 +345,8 @@ export default class GleapSession {
// Initially track.
GleapStreamedEvent.getInstance().restart();

// Load tooltips.
GleapTooltipManager.getInstance().load();
resolve(sessionData);
} catch (exp) {
reject(exp);
Expand Down
Loading

0 comments on commit e407f25

Please sign in to comment.