diff --git a/plugins/home/src/components/VisitListener.test.tsx b/plugins/home/src/components/VisitListener.test.tsx
index 7a0ce57de5..72c530071a 100644
--- a/plugins/home/src/components/VisitListener.test.tsx
+++ b/plugins/home/src/components/VisitListener.test.tsx
@@ -53,7 +53,6 @@ describe('', () => {
afterEach(jest.resetAllMocks);
it('registers a visit', async () => {
- jest.spyOn(document, 'title', 'get').mockReturnValue('MockedTitle');
const pathname = '/catalog/default/component/playback-order';
await renderInTestApp(
@@ -68,7 +67,7 @@ describe('', () => {
visit: {
pathname,
entityRef: 'component:default/playback-order',
- name: 'MockedTitle',
+ name: 'playback-order',
},
});
});
@@ -86,7 +85,6 @@ describe('', () => {
});
it('is able to override how visit names are defined', async () => {
- jest.spyOn(document, 'title', 'get').mockReturnValue('MockedTitle');
const pathname = '/catalog/default/component/playback-order';
const visitNameOverride = ({ pathname: path }: { pathname: string }) =>
@@ -111,7 +109,6 @@ describe('', () => {
});
it('is able to override how entityRefs are defined', async () => {
- jest.spyOn(document, 'title', 'get').mockReturnValue('MockedTitle');
const pathname = '/catalog/default/component/playback-order';
const toEntityRefOverride = ({ pathname: path }: { pathname: string }) =>
@@ -129,7 +126,7 @@ describe('', () => {
visit: {
pathname,
entityRef: pathname,
- name: 'MockedTitle',
+ name: 'playback-order',
},
}),
);
diff --git a/plugins/home/src/components/VisitListener.tsx b/plugins/home/src/components/VisitListener.tsx
index 4cddd307c5..de7d16e44f 100644
--- a/plugins/home/src/components/VisitListener.tsx
+++ b/plugins/home/src/components/VisitListener.tsx
@@ -54,17 +54,23 @@ const getToEntityRef =
/**
* @public
* This function returns an implementation of visitName which is responsible
- * for receiving a pathname and returning a string (name). The default
- * implementation ignores the pathname and uses the document.title .
+ * for receiving a pathname and returning a string (name).
*/
export const getVisitName =
({ rootPath = 'catalog', document = global.document } = {}) =>
({ pathname }: { pathname: string }) => {
+ // If it is a catalog entity, get the name from the path
const regex = new RegExp(
`^\/${rootPath}\/(?[^\/]+)\/(?[^\/]+)\/(?[^\/]+)`,
);
- const result = regex.exec(pathname);
+ let result = regex.exec(pathname);
if (result && result?.groups) return result.groups.name;
+
+ // If it is a root pathname, get the name from there
+ result = /^\/(?[^\/]+)$/.exec(pathname);
+ if (result && result?.groups) return result.groups.name;
+
+ // Fallback to document title
return document.title;
};