Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/#8144-handle-new-and-returnin…
Browse files Browse the repository at this point in the history
…g-visitors.
  • Loading branch information
hussain-t committed Sep 10, 2024
2 parents cceea37 + f13fb02 commit a96449d
Show file tree
Hide file tree
Showing 29 changed files with 35 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
/**
* WordPress dependencies
*/
import { _x, sprintf, _n, __ } from '@wordpress/i18n';
import { _x, sprintf, _n } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -40,11 +39,9 @@ import Sparkline from '../../../../components/Sparkline';
import SourceLink from '../../../../components/SourceLink';
import whenActive from '../../../../util/when-active';
import { calculateOverallPageMetricsData } from '../../utils/overall-page-metrics';
import { getURLPath, trackEvent } from '../../../../util';
import { getURLPath } from '../../../../util';
import WidgetHeaderTitle from '../../../../googlesitekit/widgets/components/WidgetHeaderTitle';
import useViewOnly from '../../../../hooks/useViewOnly';
import useViewContext from '../../../../hooks/useViewContext';
import NewBadge from '../../../../components/NewBadge';
import DataBlockGroup from '../../../../components/DataBlockGroup';

function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {
Expand All @@ -53,7 +50,6 @@ function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {
);

const viewOnlyDashboard = useViewOnly();
const viewContext = useViewContext();

const dates = useSelect( ( select ) =>
select( CORE_USER ).getDateRangeDates( {
Expand Down Expand Up @@ -139,18 +135,6 @@ function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {
select( CORE_USER ).getDateRangeNumberOfDays()
);

const sessionsLearnMoreURL = useSelect( ( select ) =>
select( CORE_SITE ).getGoogleSupportURL( {
path: '/analytics/answer/9191807',
} )
);

const engagementRateLearnMoreURL = useSelect( ( select ) =>
select( CORE_SITE ).getGoogleSupportURL( {
path: '/analytics/answer/12195621',
} )
);

function Header() {
return (
<WidgetHeaderTitle
Expand Down Expand Up @@ -179,10 +163,6 @@ function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {
);
}

const onGA4NewBadgeLearnMoreClick = useCallback( () => {
trackEvent( `${ viewContext }_ga4-new-badge`, 'click_learn_more_link' );
}, [ viewContext ] );

if ( isLoading || isGatheringData === undefined ) {
return (
<Widget Footer={ Footer }>
Expand All @@ -201,37 +181,6 @@ function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {

const data = calculateOverallPageMetricsData( report, dates.startDate );

const badges = {
sessions: (
<NewBadge
tooltipTitle={ __(
'Visitor interactions with your site within a given time frame (30 min by default).',
'google-site-kit'
) }
learnMoreLink={ sessionsLearnMoreURL }
onLearnMoreClick={ onGA4NewBadgeLearnMoreClick }
/>
),
engagementRate: (
<NewBadge
tooltipTitle={ __(
'Sessions which lasted 10 seconds or longer, had 1 or more conversion events, or 2 or more page views.',
'google-site-kit'
) }
learnMoreLink={ engagementRateLearnMoreURL }
onLearnMoreClick={ onGA4NewBadgeLearnMoreClick }
/>
),
};

// Check if any of the data blocks have a badge.
//
// If no data blocks have a badge, we shouldn't even render an
// empty badge container, and save some vertical space in the `DataBlock`.
const hasMetricWithBadge = data.some( ( { metric } ) => {
return !! badges[ metric ];
} );

return (
<Widget Header={ Header } Footer={ Footer }>
<Grid>
Expand Down Expand Up @@ -260,9 +209,6 @@ function DashboardOverallPageMetricsWidgetGA4( { Widget, WidgetReportError } ) {
gatheringData={ isGatheringData }
/>
}
badge={
badges[ metric ] || hasMetricWithBadge
}
/>
</Cell>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ export default function PublicationOnboardingStateNotice() {

const serviceURL = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).getServiceURL( {
path: '/reader-revenue-manager',
publicationID,
path: 'reader-revenue-manager',
query: {
publication: publicationID,
},
} )
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ describe( 'PublicationOnboardingStateNotice', () => {
const expectedServiceURL = registry
.select( MODULES_READER_REVENUE_MANAGER )
.getServiceURL( {
path: '/reader-revenue-manager',
publicationID: 'ABCDEFGH',
path: 'reader-revenue-manager',
query: {
publication: 'ABCDEFGH',
},
} );

// Ensure that CTA is present and class name is correct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function RRMSetupSuccessSubtleNotification() {

const serviceURL = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).getServiceURL( {
publicationID,
path: 'reader-revenue-manager',
query: {
publication: publicationID,
},
} )
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default function SettingsView() {

const serviceURL = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).getServiceURL( {
path: '/reader-revenue-manager',
publicationID,
path: 'reader-revenue-manager',
query: {
publication: publicationID,
},
} )
);

Expand Down
18 changes: 6 additions & 12 deletions assets/js/modules/reader-revenue-manager/datastore/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const selectors = {
* Returns a link to the Reader Revenue Manager platform.
*
* @since 1.132.0
* @since n.e.x.t Removed `publicationID` arg.
*
* @param {Object} state Data store's state.
* @param {Object} [args] Object containing optional publication ID, path and query args.
Expand All @@ -42,25 +43,18 @@ const selectors = {
*/
getServiceURL: createRegistrySelector(
( select ) =>
( state, { path, query, publicationID } = {} ) => {
( state, { path, query } = {} ) => {
let serviceURL = 'https://publishercenter.google.com';

// Always add the utm_source.
query = {
...query,
utm_source: 'sitekit',
};

if ( publicationID ) {
query.publication = publicationID;
}

if ( path ) {
const sanitizedPath = `/${ path.replace( /^\//, '' ) }`;
serviceURL = `${ serviceURL }${ sanitizedPath }`;
}

serviceURL = addQueryArgs( serviceURL, query );
serviceURL = addQueryArgs( serviceURL, {
...query,
utm_source: 'sitekit', // Always add the utm_source.
} );

const accountChooserBaseURI =
select( CORE_USER ).getAccountChooserURL( serviceURL );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ describe( 'modules/reader-revenue-manager service store', () => {
);
} );

it( 'should append a publication ID to the URL', () => {
const publicationID = 'ABCDEFG';

const serviceURL = registry
.select( MODULES_READER_REVENUE_MANAGER )
.getServiceURL( {
publicationID,
} );

const query = {
publication: publicationID,
utm_source: 'sitekit',
};

expect( decodeServiceURL( serviceURL ) ).toMatchQueryParameters(
query
);
} );

it( 'should add the path parameter', () => {
const serviceURL = registry
.select( MODULES_READER_REVENUE_MANAGER )
Expand All @@ -104,6 +85,7 @@ describe( 'modules/reader-revenue-manager service store', () => {
const query = {
param1: '1',
param2: '2',
publicationID: 'ABCDEFG',
};

const serviceURL = registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,6 @@ export default function Overview( props ) {
4: quarterCellProps,
};

// Check if any of the data blocks have a badge.
//
// If no data blocks have a badge, we shouldn't even render an
// empty badge container, and save some vertical space in the `DataBlock`.
const hasMetricWithBadge = dataBlocks.some( ( { badge } ) => {
return !! badge;
} );

return (
<Grid>
<Row>
Expand Down Expand Up @@ -367,9 +359,6 @@ export default function Overview( props ) {
}
handleStatSelection={ handleStatsSelection }
gatheringData={ dataBlock.isGatheringData }
badge={
dataBlock.badge || hasMetricWithBadge
}
/>
</Cell>
) ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public function __construct(
}

/**
* Checks for available events and save them in settings.
* Syncs detected events into settings.
*
* @since 1.135.0
*/
public function check_for_events() {
public function sync_detected_events() {
$report = $this->get_report();
$detected_events = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class Conversion_Reporting_Provider {
private Conversion_Reporting_Cron $cron;

/**
* Conversion_Reporting_Events_Check instance.
* Conversion_Reporting_Events_Sync instance.
*
* @var Conversion_Reporting_Events_Check
* @var Conversion_Reporting_Events_Sync
*/
private Conversion_Reporting_Events_Sync $events_check;
private Conversion_Reporting_Events_Sync $events_sync;

/**
* Constructor.
Expand All @@ -68,8 +68,8 @@ public function __construct(
$this->user_options = $user_options;
$this->analytics = $analytics;

$this->events_check = new Conversion_Reporting_Events_Sync( $settings, $this->analytics );
$this->cron = new Conversion_Reporting_Cron( fn() => $this->cron_callback() );
$this->events_sync = new Conversion_Reporting_Events_Sync( $settings, $this->analytics );
$this->cron = new Conversion_Reporting_Cron( fn() => $this->cron_callback() );
}

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function cron_callback() {
$owner_id = $this->analytics->get_owner_id();
$restore_user = $this->user_options->switch_user( $owner_id );

$this->events_check->check_for_events();
$this->events_sync->sync_detected_events();

$restore_user();
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function set_up() {
/**
* @dataProvider report_dimensions
*/
public function test_check_for_events( $detected_events, $report_rows ) {
public function test_sync_detected_events( $detected_events, $report_rows ) {
$this->setup_fake_handler_and_analytics( $report_rows );

$event_check = $this->get_instance();
$event_check->check_for_events();
$event_check->sync_detected_events();

$this->assertEquals( $detected_events, $this->settings->get()['detectedEvents'] );
}
Expand Down

0 comments on commit a96449d

Please sign in to comment.