Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(page-meta): provide options to override automatically created pageId's #923

Merged
merged 18 commits into from
Jan 30, 2025

Conversation

codecapitano
Copy link
Collaborator

@codecapitano codecapitano commented Jan 29, 2025

Why

With this PR we provide a convenient way to the user to change the page-meta.
This is mostly useful to give users and option to provide a custom template for pageID parsing.

If the page-meta contains an id attribute, the Faro receiver will use this ID instead.

API

Page tracking can be configured during initialisation via the Faro options

pageTracking?: {
    page?: MetaPage;
    generatePageId?: (location: Location) => string;
  };
  • The page property can be used to set the initial page-meta.
  • The generatePageId() function is used to define a template parsers which consistently updates the page id. It is to satisfy advanced use cases

** Explicitly set a the page via the setPage(page: string) function.

setPage is an overloaded function. If the page parameter is of type string, Faro updates the current active page meta with the given page id.

What

  • Provide a setPage(meta) function to set/override the page-meta and getPage() function to receiver it.
  • Provide an option to define a pageID template parser which is called on every URL change. It receiver the browser Location object as a parameter and is expected to return a string.
  • The defaultMetas object is removed and such not exported anymore because pageMeta creation changed. This can break if users used that export for some reasons. It was never meant to be used outside Faro so we decided to remove it anyways.

Links

Screenshots

Manually testing the pageId parser using a custom parser which attaches a random id to the pageId URL string.
Jest doesn't play well with manually changing the URLs.
Location isn't updated on the code side

Screen.Recording.2025-01-29.at.13.39.37.mov

Checklist

  • Tests added
  • Changelog updated
  • Documentation updated

@codecapitano codecapitano linked an issue Jan 29, 2025 that may be closed by this pull request
@codecapitano codecapitano changed the title 707 create api to set page feat(page-meta): provide options to override automatically created pageId's Jan 29, 2025
@codecapitano codecapitano self-assigned this Jan 29, 2025
@codecapitano codecapitano added the feature Request a new feature label Jan 29, 2025
@codecapitano codecapitano force-pushed the 707-create-api-to-set-page_id branch from e5986bd to dbcbf0f Compare January 29, 2025 15:28
Copy link
Collaborator

@eskirk eskirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, one comment about a potential solution to your testing issue

@cedricziel
Copy link
Contributor

The desired API usage would be:

Ad hoc usage:

faro.api.setPage('product-list');

Init usage:

initializeFaro({
  page: {
    id: 'product-list'
  }
});

@codecapitano codecapitano merged commit 1b5cc70 into main Jan 30, 2025
9 checks passed
@codecapitano codecapitano deleted the 707-create-api-to-set-page_id branch January 30, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create API to set page_id
3 participants