Skip to content

Commit

Permalink
Untangling: fire calypso_page_view event on global view page load (#9…
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Dec 4, 2024
1 parent 54cfa90 commit f30e309
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
8 changes: 7 additions & 1 deletion client/hosting/overview/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { removeQueryArgs } from '@wordpress/url';
import i18n from 'i18n-calypso';
import HostingActivate from 'calypso/hosting/server-settings/hosting-activate';
import Hosting from 'calypso/hosting/server-settings/main';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import HostingOverview from 'calypso/sites/overview/components/hosting-overview';
import { successNotice } from 'calypso/state/notices/actions';

export function hostingOverview( context: PageJSContext, next: () => void ) {
context.primary = <HostingOverview />;
context.primary = (
<>
<PageViewTracker path="/overview/:site" title="Site Overview" />
<HostingOverview />
</>
);
next();
}

Expand Down
2 changes: 0 additions & 2 deletions client/sites/overview/components/hosting-overview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { translate } from 'i18n-calypso';
import { FC } from 'react';
import NavigationHeader from 'calypso/components/navigation-header';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { isNotAtomicJetpack, isMigrationInProgress } from 'calypso/sites-dashboard/utils';
import { useSelector } from 'calypso/state';
import { getSelectedSite } from 'calypso/state/ui/selectors';
Expand Down Expand Up @@ -30,7 +29,6 @@ const HostingOverview: FC = () => {

return (
<div className="hosting-overview">
<PageViewTracker path="/overview/:site" title="Site Overview" />
<NavigationHeader
className="hosting-overview__navigation-header"
title={ translate( 'Overview' ) }
Expand Down
9 changes: 8 additions & 1 deletion client/sites/overview/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { getRouteFromContext } from 'calypso/utils';
import HostingOverview from './components/hosting-overview';
import type { Context as PageJSContext } from '@automattic/calypso-router';

export function overview( context: PageJSContext, next: () => void ) {
context.primary = <HostingOverview />;
context.primary = (
<>
<PageViewTracker title="Sites > Overview" path={ getRouteFromContext( context ) } />
<HostingOverview />
</>
);
next();
}
24 changes: 24 additions & 0 deletions client/sites/settings/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { __ } from '@wordpress/i18n';
import { useSelector } from 'react-redux';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { getRouteFromContext } from 'calypso/utils';
import { SidebarItem, Sidebar, PanelWithSidebar } from '../components/panel-sidebar';
import AdministrationSettings from './administration';
import useIsAdministrationSettingSupported from './administration/hooks/use-is-administration-setting-supported';
Expand Down Expand Up @@ -37,6 +39,7 @@ export function SettingsSidebar() {
export function siteSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker title="Sites > Settings > Site" path={ getRouteFromContext( context ) } />
<SettingsSidebar />
<SiteSettings />
</PanelWithSidebar>
Expand All @@ -47,6 +50,10 @@ export function siteSettings( context: PageJSContext, next: () => void ) {
export function administrationSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Administration"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<AdministrationSettings />
</PanelWithSidebar>
Expand All @@ -57,6 +64,10 @@ export function administrationSettings( context: PageJSContext, next: () => void
export function administrationToolResetSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Administration > Reset site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<ResetSite />
</PanelWithSidebar>
Expand All @@ -67,6 +78,10 @@ export function administrationToolResetSite( context: PageJSContext, next: () =>
export function administrationToolTransferSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Administration > Transfer site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<TransferSite />
</PanelWithSidebar>
Expand All @@ -77,6 +92,10 @@ export function administrationToolTransferSite( context: PageJSContext, next: ()
export function administrationToolDeleteSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Administration > Delete site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<DeleteSite />
</PanelWithSidebar>
Expand All @@ -87,6 +106,7 @@ export function administrationToolDeleteSite( context: PageJSContext, next: () =
export function cachingSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker title="Sites > Settings > Caching" path={ getRouteFromContext( context ) } />
<SettingsSidebar />
<CachingSettings />
</PanelWithSidebar>
Expand All @@ -97,6 +117,10 @@ export function cachingSettings( context: PageJSContext, next: () => void ) {
export function webServerSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Web server"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<WebServerSettings />
</PanelWithSidebar>
Expand Down
49 changes: 48 additions & 1 deletion client/sites/tools/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import page, { Context as PageJSContext } from '@automattic/calypso-router';
import { __ } from '@wordpress/i18n';
import { useSelector } from 'react-redux';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import HostingFeatures from 'calypso/sites/hosting-features/components/hosting-features';
import { getSelectedSite, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { getRouteFromContext } from 'calypso/utils';
import { SidebarItem, Sidebar, PanelWithSidebar } from '../components/panel-sidebar';
import { areHostingFeaturesSupported } from '../hosting-features/features';
import Database from './database/page';
Expand Down Expand Up @@ -49,13 +51,22 @@ export function tools( context: PageJSContext, next: () => void ) {
return page.redirect( `/sites/tools/staging-site/${ site?.slug }` );
}

context.primary = <HostingFeatures showAsTools />;
context.primary = (
<>
<PageViewTracker title="Sites > Advanced Tools" path={ getRouteFromContext( context ) } />
<HostingFeatures showAsTools />
</>
);
next();
}

export function stagingSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Staging site"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<StagingSite />
</PanelWithSidebar>
Expand All @@ -66,6 +77,10 @@ export function stagingSite( context: PageJSContext, next: () => void ) {
export function deployments( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Deployments"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<Deployments />
</PanelWithSidebar>
Expand All @@ -76,6 +91,10 @@ export function deployments( context: PageJSContext, next: () => void ) {
export function deploymentCreation( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Deployments > Create"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<DeploymentCreation />
</PanelWithSidebar>
Expand All @@ -94,6 +113,10 @@ export function deploymentManagement( context: PageJSContext, next: () => void )

context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Deployments > Manage"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<DeploymentManagement codeDeploymentId={ codeDeploymentId } />
</PanelWithSidebar>
Expand All @@ -112,6 +135,10 @@ export function deploymentRunLogs( context: PageJSContext, next: () => void ) {

context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Deployments > Run logs"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<DeploymentRunLogs codeDeploymentId={ codeDeploymentId } />
</PanelWithSidebar>
Expand All @@ -122,6 +149,10 @@ export function deploymentRunLogs( context: PageJSContext, next: () => void ) {
export function monitoring( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Monitoring"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<Monitoring />
</PanelWithSidebar>
Expand All @@ -132,6 +163,10 @@ export function monitoring( context: PageJSContext, next: () => void ) {
export function phpErrorLogs( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Logs > PHP"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<Logs logType="php" />
</PanelWithSidebar>
Expand All @@ -142,6 +177,10 @@ export function phpErrorLogs( context: PageJSContext, next: () => void ) {
export function webServerLogs( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Logs > Web"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<Logs logType="web" />
</PanelWithSidebar>
Expand All @@ -152,6 +191,10 @@ export function webServerLogs( context: PageJSContext, next: () => void ) {
export function sftpSsh( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > SFTP/SSH"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<SftpSsh />
</PanelWithSidebar>
Expand All @@ -162,6 +205,10 @@ export function sftpSsh( context: PageJSContext, next: () => void ) {
export function database( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Advanced Tools > Database"
path={ getRouteFromContext( context ) }
/>
<ToolsSidebar />
<Database />
</PanelWithSidebar>
Expand Down
11 changes: 11 additions & 0 deletions client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Context } from '@automattic/calypso-router';
import { addQueryArgs } from 'calypso/lib/url';
// Adapts route paths to also include wildcard
// subroutes under the root level section.
Expand Down Expand Up @@ -50,3 +51,13 @@ export function isEligibleForProductSampling( userId: number, percentage: number

return userSegment < percentage;
}

export function getRouteFromContext( context: Context ) {
let route = context.path;
for ( const [ key, value ] of Object.entries( context.params ) ) {
if ( key !== '0' ) {
route = route.replace( value, ':' + key );
}
}
return route;
}

0 comments on commit f30e309

Please sign in to comment.