Skip to content

Commit

Permalink
fix: Allow title override in page attributes (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
qhanam authored Feb 12, 2024
1 parent 0967327 commit a6a1ad8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/sessions/PageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type Page = {
};

export type Attributes = {
title: string;
pageId: string;
parentPageId?: string;
interaction?: number;
Expand Down Expand Up @@ -187,7 +186,9 @@ export class PageManager {
customPageAttributes?: PageAttributes
) {
this.attributes = {
title: document.title,
title: customPageAttributes?.pageAttributes?.title
? customPageAttributes.pageAttributes.title
: document.title,
pageId: page.pageId
};

Expand Down
57 changes: 57 additions & 0 deletions src/sessions/__tests__/PageManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,63 @@ describe('PageManager tests', () => {
);
});

test('when title attribute is provided then provided title takes precedence', async () => {
// Init
const pageManager: PageManager = new PageManager(
{
...DEFAULT_CONFIG,
allowCookies: true
},
record
);

pageManager.recordPageView({
pageId: '/rum/home',
pageAttributes: {
title: 'testingOverride'
}
});

// Assert
expect(record.mock.calls[0][0]).toEqual(PAGE_VIEW_EVENT_TYPE);
expect(pageManager.getAttributes()).toMatchObject({
pageId: '/rum/home',
title: 'testingOverride'
});

window.removeEventListener(
'popstate',
(pageManager as any).popstateListener
);
});

test('when no title attribute is provided then document.title is used', async () => {
// Init
const pageManager: PageManager = new PageManager(
{
...DEFAULT_CONFIG,
allowCookies: true
},
record
);

pageManager.recordPageView({
pageId: '/rum/home'
});

// Assert
expect(record.mock.calls[0][0]).toEqual(PAGE_VIEW_EVENT_TYPE);
expect(pageManager.getAttributes()).toMatchObject({
pageId: '/rum/home',
title: 'Amazon AWS Console'
});

window.removeEventListener(
'popstate',
(pageManager as any).popstateListener
);
});

test('when there is no pageId difference then no pages are created', async () => {
// Init
const config: Config = {
Expand Down

0 comments on commit a6a1ad8

Please sign in to comment.