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

setPageMetadata metadata on first page load #2040

Open
jschuler opened this issue Sep 14, 2022 · 5 comments
Open

setPageMetadata metadata on first page load #2040

jschuler opened this issue Sep 14, 2022 · 5 comments

Comments

@jschuler
Copy link
Contributor

setPageMetadata does not currently send out additional metadata on first page load. This is also already called out here:
http://front-end-docs-insights.apps.ocp4.prod.psi.redhat.com/analytics

I'm creating this issue primarily for QE to reference since this has come up in our project testing (OCM). But it would be great to work on a fix!

@Hyperkid123
Copy link
Contributor

The reason for this is that the route change and thus page event is fired before the JS module is loaded and can customize the page load event.

We have an option to leverage the module first page vent via the module definition in cloud service config (and frontend operator). The issue with this approach is that the module will not have total freedom in what data we pass to the page event. Anything static is good. But any dynamic data has to be restricted.

Do we know the nature of the data we want to send via the page event? Is this something dynamic? (requires async request etc.)

@jschuler
Copy link
Contributor Author

jschuler commented Sep 15, 2022

Generally, once the route is mounted in OCM we send some additional metadata like:

ocm_resource_type: 'all' | 'moa' | 'ocp' | 'ocptrial' | and more based on product
path: some paths are overwritten, like cluster details paths (to strip out the unique IDs in the path name
// next 2 fields are sent from cluster details
ocm_cluster_id: cluster ID
resource_id: external cluster ID

This information is available after a route change. Using react-router-dom we send additional information like this:

const { pathname } = useLocation();
const { setPageMetadata } = useAnalytics();
useEffect(() => {
    setPageMetadata({
      // additional metadata here
    });
}, [pathname]);

No async call is needed as of now, as the redux store is updated with the information we need before the route mounts

@Hyperkid123
Copy link
Contributor

Do you think it would be possible to create a route-based static specification of the data? Something like

{
  "eventConfig": {
    "routes": {
      "/foo/bar": {
       "ocm_resource_type": "something",
       ...
      },
      ...
    }
  }
}

@jschuler
Copy link
Contributor Author

jschuler commented Sep 15, 2022

That could work for the ocm_resource_type field if wildcards are supported as well. You can see the implementation on gitlab here (VPN required)

@Hyperkid123
Copy link
Contributor

Hyperkid123 commented Sep 15, 2022

We can use the router match notation to get the correct value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants