Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into enhancement/8180-c…
Browse files Browse the repository at this point in the history
…hanging-analytics-property-name-AS.
  • Loading branch information
benbowler committed Sep 16, 2024
2 parents 6ec3ab6 + ee34866 commit bcee091
Show file tree
Hide file tree
Showing 199 changed files with 3,515 additions and 1,061 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ _Do not alter or remove anything below. The following sections will be managed b
- [ ] Ensure CI checks pass.
- [ ] Check Storybook where applicable.
- [ ] Ensure there is a QA Brief.
- [ ] Ensure there are no unexpected significant changes to file sizes.

## Merge Reviewer Checklist

Expand Down
43 changes: 43 additions & 0 deletions assets/js/components/KeyMetrics/key-metrics-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_POPULAR_PRODUCTS,
KM_ANALYTICS_TOP_CITIES,
KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
KM_ANALYTICS_TOP_COUNTRIES,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_ANALYTICS_PAGES_PER_VISIT,
Expand All @@ -50,6 +51,7 @@ import {
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';
import { isFeatureEnabled } from '../../features';

/**
* Determines whether to show a widget the requires Analytics 4 and AdSense to be linked.
Expand Down Expand Up @@ -122,6 +124,30 @@ function shouldDisplayWidgetWithCustomDimensions(
);
}

/**
* Determines whether to display a widget that requires conversion reporting events
* in the key metrics selection panel.
*
* This function is attached to the widget object that requires the conversion reporting events and
* has the `requiredConversionEventName` property.
*
* @since n.e.x.t
*
* @param {Function} select Data store select function.
* @return {boolean} Whether to display the widget.
*/
function shouldDisplayWidgetWithConversionEvent( select ) {
if ( ! isFeatureEnabled( 'conversionReporting' ) ) {
return false;
}

return select( MODULES_ANALYTICS_4 ).hasConversionReportingEvents(
// This property is available to the widget object that requires the
// conversion reporting events, where the function is attached.
this.requiredConversionEventName
);
}

const KEY_METRICS_WIDGETS = {
[ KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT ]: {
title: __( 'Top earning pages', 'google-site-kit' ),
Expand Down Expand Up @@ -330,6 +356,23 @@ const KEY_METRICS_WIDGETS = {
'google-site-kit'
),
},
[ KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS ]: {
title: __( 'Top cities driving leads', 'google-site-kit' ),
description: __(
'Cities driving the most contact form submissions',
'google-site-kit'
),
infoTooltip: __(
'Cities driving the most contact form submissions',
'google-site-kit'
),
requiredConversionEventName: [
'submit_lead_form',
'contact',
'generate_lead',
],
displayInList: shouldDisplayWidgetWithConversionEvent,
},
[ KM_ANALYTICS_TOP_COUNTRIES ]: {
title: __( 'Top countries driving traffic', 'google-site-kit' ),
description: __(
Expand Down
3 changes: 3 additions & 0 deletions assets/js/components/SelectionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import classnames from 'classnames';
import { Checkbox } from 'googlesitekit-components';

export default function SelectionBox( {
badge,
checked,
children,
disabled,
Expand All @@ -52,12 +53,14 @@ export default function SelectionBox( {
value={ value }
>
{ title }
{ badge }
</Checkbox>
</div>
);
}

SelectionBox.propTypes = {
badge: PropTypes.node,
checked: PropTypes.bool,
children: PropTypes.node,
disabled: PropTypes.bool,
Expand Down
3 changes: 3 additions & 0 deletions assets/js/components/SelectionPanel/SelectionPanelItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export default function SelectionPanelItem( {
onCheckboxChange,
subtitle,
suffix,
badge,
} ) {
return (
<div className="googlesitekit-selection-panel-item">
<SelectionBox
badge={ badge }
checked={ isItemSelected }
disabled={ isItemDisabled }
id={ id }
Expand Down Expand Up @@ -76,4 +78,5 @@ SelectionPanelItem.propTypes = {
onCheckboxChange: PropTypes.func,
subtitle: PropTypes.string,
suffix: PropTypes.node,
badge: PropTypes.node,
};
19 changes: 18 additions & 1 deletion assets/js/components/SelectionPanel/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import NewBadge from '../NewBadge';
import SelectionPanel from './SelectionPanel';
import SelectionPanelFooter from './SelectionPanelFooter';
import SelectionPanelHeader from './SelectionPanelHeader';
import SelectionPanelItem from './SelectionPanelItem';
import SelectionPanelItems from './SelectionPanelItems';

function Template( { availableSavedItems = {}, savedItemSlugs = [] } ) {
function Template( {
availableSavedItems = {},
savedItemSlugs = [],
itemComponentProps = {},
} ) {
const [ selectedItems, setSeletectedItems ] = useState(
Object.keys( availableSavedItems )
);
Expand All @@ -55,6 +60,7 @@ function Template( { availableSavedItems = {}, savedItemSlugs = [] } ) {
slug,
title: `Item ${ current }`,
description: `Description for item ${ current }`,
...itemComponentProps,
},
};
}, {} );
Expand Down Expand Up @@ -153,6 +159,17 @@ withZeroUnsavedItems.args = {
};
withZeroUnsavedItems.scenario = {};

export const WithNewBadges = Template.bind( {} );
WithNewBadges.storyName = 'With "New" badges';
WithNewBadges.args = {
itemComponentProps: {
badge: <NewBadge />,
},
};
WithNewBadges.scenario = {
label: 'Components/SelectionPanel/WithNewBadges',
};

export default {
title: 'Components/Selection Panel',
component: SelectionPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import ErrorText from '../../components/ErrorText';
import LoadingWrapper from '../LoadingWrapper';
import ConfirmDisableConversionTrackingDialog from './ConfirmDisableConversionTrackingDialog';
import { useFeature } from '../../hooks/useFeature';
import useViewContext from '../../hooks/useViewContext';
import { trackEvent } from '../../util';
import PropTypes from 'prop-types';

export default function ConversionTrackingToggle( { children, loading } ) {
const viewContext = useViewContext();
const iceEnabled = useFeature( 'conversionInfra' );
const [ saveError ] = useState( null );
const [ showConfirmDialog, setShowConfirmDialog ] = useState( false );

Expand All @@ -50,10 +48,6 @@ export default function ConversionTrackingToggle( { children, loading } ) {

const { setConversionTrackingEnabled } = useDispatch( CORE_SITE );

if ( ! iceEnabled ) {
return null;
}

return (
<Fragment>
<LoadingWrapper loading={ loading } width="180px" height="21.3px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ Enabled.scenario = {
label: 'Components/Conversion Tracking/ConversionTrackingToggle/Enabled',
delay: 250,
};
Enabled.parameters = {
features: [ 'conversionInfra' ],
};
Enabled.decorators = [
( Story, { parameters } ) => {
const setupRegistry = ( registry ) => {
Expand Down Expand Up @@ -76,9 +73,6 @@ Default.scenario = {
label: 'Components/Conversion Tracking/ConversionTrackingToggle/Default',
delay: 250,
};
Default.parameters = {
features: [ 'conversionInfra' ],
};
Default.decorators = [
( Story, { parameters } ) => {
const setupRegistry = ( registry ) => {
Expand Down
2 changes: 0 additions & 2 deletions assets/js/components/notifications/SubtleNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Fragment } from '@wordpress/element';
* Internal dependencies
*/
import { useFeature } from '../../hooks/useFeature';
import { SetupSuccessSubtleNotification } from '../../modules/ads/components/notifications/';
import AudienceSegmentationSetupSuccessSubtleNotification from '../../modules/analytics-4/components/audience-segmentation/dashboard/AudienceSegmentationSetupSuccessSubtleNotification';
import { RRMSetupSuccessSubtleNotification } from '../../modules/reader-revenue-manager/components/dashboard';
import GA4AdSenseLinkedNotification from './GA4AdSenseLinkedNotification';
Expand All @@ -51,7 +50,6 @@ export default function SubtleNotifications() {
<AudienceSegmentationSetupSuccessSubtleNotification />
) }
<GA4AdSenseLinkedNotification />
<SetupSuccessSubtleNotification />
{ rrmModuleEnabled && <RRMSetupSuccessSubtleNotification /> }
<Notifications
viewContext={ viewContext }
Expand Down
15 changes: 10 additions & 5 deletions assets/js/components/settings/SettingsAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { __ } from '@wordpress/i18n';
*/
import { useSelect } from 'googlesitekit-data';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import { MODULES_SEARCH_CONSOLE } from '../../modules/search-console/datastore/constants';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import Layout from '../layout/Layout';
Expand All @@ -43,6 +44,9 @@ import { useFeature } from '../../hooks/useFeature';
export default function SettingsAdmin() {
const audienceSegmentationEnabled = useFeature( 'audienceSegmentation' );

const configuredAudiences = useSelect( ( select ) =>
select( CORE_USER ).getConfiguredAudiences()
);
const isAnalyticsConnected = useSelect( ( select ) =>
select( CORE_MODULES ).isModuleConnected( 'analytics-4' )
);
Expand Down Expand Up @@ -146,11 +150,12 @@ export default function SettingsAdmin() {
</Cell>
) }

{ audienceSegmentationEnabled && isAnalyticsConnected && (
<Cell size={ 12 }>
<SettingsCardVisitorGroups />
</Cell>
) }
{ audienceSegmentationEnabled &&
( isAnalyticsConnected || !! configuredAudiences ) && (
<Cell size={ 12 }>
<SettingsCardVisitorGroups />
</Cell>
) }

<Cell size={ 12 }>
<Layout
Expand Down
10 changes: 10 additions & 0 deletions assets/js/components/settings/SettingsApp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ describe( 'SettingsApp', () => {
new RegExp( '^/google-site-kit/v1/modules/analytics-4/data' )
);

registry.dispatch( CORE_USER ).receiveGetAudienceSettings( {
configuredAudiences: null,
isAudienceSegmentationWidgetHidden: false,
} );

history.push( '/admin-settings' );

const { getAllByRole, waitForRegistry } = render( <SettingsApp />, {
Expand Down Expand Up @@ -170,6 +175,11 @@ describe( 'SettingsApp', () => {
new RegExp( '^/google-site-kit/v1/modules/analytics-4/data' )
);

registry.dispatch( CORE_USER ).receiveGetAudienceSettings( {
configuredAudiences: null,
isAudienceSegmentationWidgetHidden: false,
} );

await registry.dispatch( CORE_USER ).setTrackingEnabled( false );

const { getAllByRole, waitForRegistry } = render( <SettingsApp />, {
Expand Down
5 changes: 5 additions & 0 deletions assets/js/components/settings/SettingsModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ describe( 'SettingsModules', () => {

await registry.dispatch( CORE_USER ).setTrackingEnabled( false );

registry.dispatch( CORE_USER ).receiveGetAudienceSettings( {
configuredAudiences: null,
isAudienceSegmentationWidgetHidden: false,
} );

history.push( '/admin' );

const { waitForRegistry } = render( <SettingsModules />, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import GoogleChart from '../GoogleChart';
import { UNIQUE_VISITORS_CHART_OPTIONS } from './chart-options';
import { extractAnalytics4DashboardData } from '../../modules/analytics-4/utils/extract-dashboard-data';
import { stringToDate } from '../../util';

export default function WPDashboardUniqueVisitorsChartGA4( props ) {
const { WPDashboardReportError } = props;
Expand Down Expand Up @@ -140,7 +141,7 @@ export default function WPDashboardUniqueVisitorsChartGA4( props ) {
);

if ( isZeroChart ) {
options.hAxis.ticks = [ refDate ];
options.hAxis.ticks = [ stringToDate( refDate ) ];
}

return (
Expand Down
20 changes: 9 additions & 11 deletions assets/js/googlesitekit/datastore/user/audience-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import {
commonActions,
combineStores,
} from 'googlesitekit-data';
import {
AUDIENCE_TYPE_SORT_ORDER,
MODULES_ANALYTICS_4,
} from '../../../modules/analytics-4/datastore/constants';
import { MODULES_ANALYTICS_4 } from '../../../modules/analytics-4/datastore/constants';
import { createFetchStore } from '../../data/create-fetch-store';
import { createValidatedAction } from '../../data/utils';
import { createReducer } from '../../data/create-reducer';
Expand Down Expand Up @@ -140,17 +137,18 @@ const baseActions = {
const sortedConfiguredAudiences = [
...finalSettings.configuredAudiences,
].sort( ( audienceNameA, audienceNameB ) => {
const audienceTypeA = availableAudiences?.find(
const audienceIndexA = availableAudiences.findIndex(
( audience ) => audience.name === audienceNameA
)?.audienceType;
const audienceTypeB = availableAudiences?.find(
);
const audienceIndexB = availableAudiences.findIndex(
( audience ) => audience.name === audienceNameB
)?.audienceType;
);

const weightA = AUDIENCE_TYPE_SORT_ORDER[ audienceTypeA ] || 0;
const weightB = AUDIENCE_TYPE_SORT_ORDER[ audienceTypeB ] || 0;
if ( audienceIndexA === -1 || audienceIndexB === -1 ) {
return 0;
}

return weightA - weightB;
return audienceIndexA - audienceIndexB;
} );

finalSettings.configuredAudiences = sortedConfiguredAudiences;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe( 'modules/analytics-4 audience settings', () => {
};

audienceSettingsSortedResponse = {
configuredAudiences: [ 'audienceB', 'audienceA' ],
configuredAudiences: [ 'audienceA', 'audienceB' ],
isAudienceSegmentationWidgetHidden: false,
};

Expand Down Expand Up @@ -139,9 +139,7 @@ describe( 'modules/analytics-4 audience settings', () => {
.setAvailableAudiences( availableAudiences );
registry
.dispatch( CORE_USER )
.setConfiguredAudiences(
audienceSettingsResponse.configuredAudiences
);
.setConfiguredAudiences( [ 'audienceB', 'audienceA' ] );
registry
.dispatch( CORE_USER )
.setAudienceSegmentationWidgetHidden(
Expand Down
3 changes: 3 additions & 0 deletions assets/js/googlesitekit/datastore/user/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const KM_ANALYTICS_POPULAR_CONTENT = 'kmAnalyticsPopularContent';
export const KM_ANALYTICS_POPULAR_PRODUCTS = 'kmAnalyticsPopularProducts';
export const KM_ANALYTICS_RETURNING_VISITORS = 'kmAnalyticsReturningVisitors';
export const KM_ANALYTICS_TOP_CITIES = 'kmAnalyticsTopCities';
export const KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS =
'kmAnalyticsTopCitiesDrivingLeads';
export const KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE =
'kmAnalyticsTopConvertingTrafficSource';
export const KM_ANALYTICS_TOP_COUNTRIES = 'kmAnalyticsTopCountries';
Expand Down Expand Up @@ -87,6 +89,7 @@ export const keyMetricsGA4Widgets = [
KM_ANALYTICS_RETURNING_VISITORS,
KM_ANALYTICS_TOP_CATEGORIES,
KM_ANALYTICS_TOP_CITIES,
KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_ANALYTICS_TOP_COUNTRIES,
KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES,
Expand Down
Loading

0 comments on commit bcee091

Please sign in to comment.