From 6bad19afe325aa8c10efee8a47fe5a7d1a410cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20B=C3=B6hler?= Date: Mon, 23 Mar 2026 12:49:06 +0100 Subject: [PATCH] allow multiple page rules --- package.json | 2 +- src/Gleap.js | 6 +++--- src/GleapPageFilter.js | 8 ++++++++ src/GleapTooltipManager.js | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d5eda86..391604c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gleap", - "version": "15.2.6", + "version": "15.2.7", "main": "build/cjs/index.js", "module": "build/esm/index.mjs", "exports": { diff --git a/src/Gleap.js b/src/Gleap.js index c2c39a7..12d4fe5 100755 --- a/src/Gleap.js +++ b/src/Gleap.js @@ -26,7 +26,7 @@ import GleapAudioManager from './GleapAudioManager'; import GleapTagManager from './GleapTagManager'; import GleapAdminManager from './GleapAdminManager'; import GleapProductTours from './GleapProductTours'; -import { checkPageFilter } from './GleapPageFilter'; +import { checkPageFilter, checkPageRules } from './GleapPageFilter'; import { registerGleapChecklist } from './GleapChecklist'; import ChecklistNetworkManager from './ChecklistNetworkManager'; @@ -1241,8 +1241,8 @@ class Gleap { for (let i = 0; i < actions.length; i++) { const action = actions[i]; if (action && action.actionType) { - if (action.pageFilter && window && window.location) { - const passed = checkPageFilter(window.location.href, action.pageFilter, action.pageFilterType); + if ((action.pageRules?.length > 0 || action.pageFilter) && window && window.location) { + const passed = checkPageRules(window.location.href, action); if (!passed) { continue; diff --git a/src/GleapPageFilter.js b/src/GleapPageFilter.js index 2d92777..f006bf9 100644 --- a/src/GleapPageFilter.js +++ b/src/GleapPageFilter.js @@ -81,3 +81,11 @@ export const checkPageFilter = (currentUrl, pageFilter, pageFilterType) => { return matched; }; + +export const checkPageRules = (currentUrl, action) => { + const rules = action.pageRules && action.pageRules.length > 0 + ? action.pageRules + : (action.pageFilter ? [{ pageFilter: action.pageFilter, pageFilterType: action.pageFilterType }] : []); + if (rules.length === 0) return true; + return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType)); +}; diff --git a/src/GleapTooltipManager.js b/src/GleapTooltipManager.js index daee391..5532c1a 100644 --- a/src/GleapTooltipManager.js +++ b/src/GleapTooltipManager.js @@ -1,7 +1,7 @@ import { arrow, autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom'; import { GleapSession } from './Gleap'; import { loadIcon } from './UI'; -import { checkPageFilter } from './GleapPageFilter'; +import { checkPageFilter, checkPageRules } from './GleapPageFilter'; export default class GleapTooltipManager { tooltips = []; @@ -427,6 +427,10 @@ export default class GleapTooltipManager { const currentUrl = window.location.href; return this.tooltips.filter((tooltip) => { + if (tooltip.pageRules && tooltip.pageRules.length > 0) { + return checkPageRules(currentUrl, { pageRules: tooltip.pageRules }); + } + if (!tooltip.page || tooltip.page.length === 0) { return true; }