Skip to content

Commit

Permalink
chore: remove # from being tracked in setCustomUrl (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Destinyyyy authored Aug 23, 2024
1 parent 18afc61 commit 071a4fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ onInitialization
✓ should work if the surcharge of the operator (1 ms)
router.routeChangeStart event
✓ should setReferrerUrl and setCustomUrl on route change start (1 ms)
✓ should setReferrerUrl and setCustomUrl on route change start and handle hashtag (by removing it)
✓ should use previousPath as referer on consecutive route change (1 ms)
✓ should work if the surcharge of the operator (3 ms)
router.routeChangeComplete event
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/matomo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ describe("router.routeChangeStart event", () => {
resolve();
});
});
test("should setReferrerUrl and setCustomUrl on route change start and handle hashtag (by removing it)", async () => {
init({ siteId: "42", url: "YO" });
window._paq = [];

Router.events.emit("routeChangeStart", "/path/to/hello#should-not-appear");

return new Promise<void>((resolve) => {
expect(window._paq).toEqual([
["setReferrerUrl", "/"],
["setCustomUrl", "/path/to/hello"],
["deleteCustomVariables", "page"],
]);

resolve();
});
});
test("should use previousPath as referer on consecutive route change", async () => {
document.title = "test page 2";

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export function init({

// We use only the part of the url without the querystring to ensure piwik is happy
// It seems that piwik doesn't track well page with querystring
const [pathname] = path.split("?");
let [pathname] = path.split("?");
pathname = pathname.replace(/#.*/, "");

if (previousPath) {
push(["setReferrerUrl", `${previousPath}`]);
Expand Down

0 comments on commit 071a4fb

Please sign in to comment.