Skip to content

Commit 1f9c92d

Browse files
committed
v14.2.14
- Fixed issue with next.js - Added page filter
1 parent e8aa37c commit 1f9c92d

15 files changed

Lines changed: 555 additions & 415 deletions

.DS_Store

0 Bytes
Binary file not shown.

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.

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

published/14.2.14/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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ import GleapAudioManager from "./GleapAudioManager";
2828
import GleapTagManager from "./GleapTagManager";
2929
import GleapAdminManager from "./GleapAdminManager";
3030
import GleapProductTours from "./GleapProductTours";
31+
import { checkPageFilter } from "./GleapPageFilter";
3132

3233
if (
34+
typeof window !== "undefined" &&
3335
typeof HTMLCanvasElement !== "undefined" &&
3436
HTMLCanvasElement.prototype &&
3537
HTMLCanvasElement.prototype.__originalGetContext === undefined
@@ -1138,8 +1140,19 @@ class Gleap {
11381140
performActions(actions) {
11391141
for (let i = 0; i < actions.length; i++) {
11401142
const action = actions[i];
1141-
11421143
if (action && action.actionType) {
1144+
if (action.pageFilter && window && window.location) {
1145+
const passed = checkPageFilter(
1146+
window.location.href,
1147+
action.pageFilter,
1148+
action.pageFilterType
1149+
);
1150+
1151+
if (!passed) {
1152+
continue;
1153+
}
1154+
}
1155+
11431156
if (action.actionType === "notification") {
11441157
if (action?.data?.checklist?.popupType === "widget") {
11451158
Gleap.openChecklist(action.data.checklist.id, true);
@@ -1308,4 +1321,5 @@ export {
13081321
GleapProductTours,
13091322
handleGleapLink,
13101323
};
1311-
export default Gleap;
1324+
1325+
export default Gleap;

src/GleapPageFilter.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export const checkPageFilter = (currentUrl, pageFilter, pageFilterType) => {
2+
// If any parameter is missing, consider the filter passed.
3+
if (!currentUrl || !pageFilter || !pageFilterType) {
4+
return true;
5+
}
6+
7+
// Helper to remove trailing slashes.
8+
const removeTrailingSlash = (url) => url.replace(/\/$/, "");
9+
10+
// Generates a regex from a match string by replacing dynamic segments (e.g., {id}).
11+
const generateRegex = (match) => {
12+
if (!match) return null;
13+
try {
14+
const dynamicPattern = /{\w+}/g;
15+
const regexPattern = match.replace(dynamicPattern, "[\\w-]+");
16+
return new RegExp(regexPattern, "i");
17+
} catch (e) {
18+
return null;
19+
}
20+
};
21+
22+
// Checks if the provided URL matches the given match string.
23+
const isMatchingUrl = (url, match) => {
24+
if (!url || !match) return false;
25+
try {
26+
// First, a simple substring check.
27+
if (url.includes(match)) {
28+
return true;
29+
}
30+
} catch (e) {
31+
// Continue to regex matching.
32+
}
33+
const regex = generateRegex(match);
34+
if (!regex) return false;
35+
try {
36+
return regex.test(url);
37+
} catch (e) {
38+
return false;
39+
}
40+
};
41+
42+
let matched = false;
43+
44+
// Check matching based on the provided pageFilterType.
45+
switch (pageFilterType) {
46+
case "is":
47+
matched =
48+
removeTrailingSlash(currentUrl) === removeTrailingSlash(pageFilter);
49+
break;
50+
case "contains":
51+
matched = isMatchingUrl(currentUrl, pageFilter);
52+
break;
53+
case "startswith":
54+
matched = currentUrl.startsWith(pageFilter);
55+
break;
56+
case "endswith":
57+
matched = currentUrl.endsWith(pageFilter);
58+
break;
59+
default:
60+
matched = false;
61+
}
62+
63+
return matched;
64+
};

src/GleapStreamedEvent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default class GleapStreamedEvent {
102102
try {
103103
if (message.name === 'update') {
104104
const { a, u } = message.data;
105-
105+
106106
if (!GleapFrameManager.getInstance().isOpened()) {
107107
if (a) {
108108
Gleap.getInstance().performActions(a);

src/GleapTagManager.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { gleapDataParser } from "./GleapHelper";
2-
31
export default class GleapTagManager {
42
tags = [];
53

0 commit comments

Comments
 (0)