Skip to content

Commit

Permalink
fix: handle root-path comparision @ trackers#matchPathPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
paras-verma committed May 17, 2024
1 parent c7c202c commit 5a30dab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/trackers/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class Trackers {
**/
registerTrackers() {
(this.events || []).forEach((eventConfig) => {
if (!eventConfig.location) return;
if (!matchPathPattern(location.pathname, eventConfig.location)) return;
if (!eventConfig.location) return this.#debug("Ignoring event, missing location");
if (!matchPathPattern(location.pathname, eventConfig.location)) return this.#debug("Event not related to current path...", location.pathname, eventConfig.location);

const tree = getNodeTree(eventConfig.jsPath, document);
const elements = tree.destinations;
Expand Down Expand Up @@ -110,6 +110,7 @@ export class Trackers {
if (!Boolean(node)) return;

try {
console.log("observer", this.observer);
this.observer?.observe((node! as Element).shadowRoot || node!, { subtree: true, attributes: true, childList: true });
this.#debug("Registering observer on target: ", (node as ShadowRoot)?.host || node);
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/trackers/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function getSelectorForShadowRootJsPath(jsPath: string = "") {
* @returns {boolean}
**/
export function matchPathPattern(path: string | string[], pattern: string | string[]): boolean {
if (path.toString() === "/" && pattern.toString() === "/") return true;
if (!Array.isArray(path)) path = path.split("/").filter(Boolean);
if (!Array.isArray(pattern)) pattern = pattern.split("/").filter(Boolean);

Expand Down

0 comments on commit 5a30dab

Please sign in to comment.