-
Notifications
You must be signed in to change notification settings - Fork 293
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
Create the "Top converting traffic source" key metric widget tile. #7253
Merged
aaemnnosttv
merged 9 commits into
develop
from
enhancement/6255-top-converting-traffic-source
Jul 10, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f2594a1
Flesh out the TopConvertingTrafficSourceWidget.
techanvil 04186ec
Add support for sessionConversionRate metric to GA4 mock data generator.
techanvil 89bb0bd
Add stories for TopConvertingTrafficSourceWidget.
techanvil bb333fa
Update translator comment.
techanvil af7f070
Add VRT reference images for TopConvertingTrafficSourceWidget.
techanvil ced0833
Add tests for TopConvertingTrafficSourceWidget.
techanvil 96cf061
Tidy up.
techanvil 40216c5
Merge branch 'develop' into enhancement/6255-top-converting-traffic-s…
techanvil d4f9491
Remove unneeded initialisation of global data.
techanvil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
assets/js/modules/analytics-4/components/widgets/TopConvertingTrafficSourceWidget.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* TopConvertingTrafficSourceWidget Component Stories. | ||
* | ||
* Site Kit by Google, Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
provideKeyMetrics, | ||
provideModules, | ||
} from '../../../../../../tests/js/utils'; | ||
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util'; | ||
import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup'; | ||
import TopConvertingTrafficSourceWidget from './TopConvertingTrafficSourceWidget'; | ||
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants'; | ||
import { MODULES_ANALYTICS_4 } from '../../datastore/constants'; | ||
import { | ||
getAnalytics4MockResponse, | ||
provideAnalytics4MockReport, | ||
} from '../../utils/data-mock'; | ||
import { replaceValuesInAnalytics4ReportWithZeroData } from '../../../../../../.storybook/utils/zeroReports'; | ||
|
||
const reportOptions = { | ||
compareStartDate: '2020-07-14', | ||
compareEndDate: '2020-08-10', | ||
startDate: '2020-08-11', | ||
endDate: '2020-09-07', | ||
dimensions: [ 'sessionDefaultChannelGroup' ], | ||
metrics: [ | ||
{ | ||
name: 'sessionConversionRate', | ||
}, | ||
], | ||
limit: 1, | ||
orderBy: 'sessionConversionRate', | ||
}; | ||
|
||
const WidgetWithComponentProps = withWidgetComponentProps( | ||
'kmAnalyticsTopTrafficSource' | ||
)( TopConvertingTrafficSourceWidget ); | ||
|
||
const Template = ( { setupRegistry, ...args } ) => ( | ||
<WithRegistrySetup func={ setupRegistry }> | ||
<WidgetWithComponentProps { ...args } /> | ||
</WithRegistrySetup> | ||
); | ||
|
||
export const Ready = Template.bind( {} ); | ||
Ready.storyName = 'Ready'; | ||
Ready.args = { | ||
setupRegistry: ( registry ) => { | ||
provideAnalytics4MockReport( registry, reportOptions ); | ||
}, | ||
}; | ||
Ready.scenario = { | ||
label: 'KeyMetrics/TopConvertingTrafficSourceWidget/Ready', | ||
}; | ||
|
||
export const Loading = Template.bind( {} ); | ||
Loading.storyName = 'Loading'; | ||
Loading.args = { | ||
setupRegistry: ( { dispatch } ) => { | ||
dispatch( MODULES_ANALYTICS_4 ).startResolution( 'getReport', [ | ||
reportOptions, | ||
] ); | ||
}, | ||
}; | ||
Loading.scenario = { | ||
label: 'KeyMetrics/TopConvertingTrafficSourceWidget/Loading', | ||
}; | ||
Loading.decorators = [ | ||
( Story ) => { | ||
// Ensure the animation is paused for VRT tests to correctly capture the loading state. | ||
return ( | ||
<div className="googlesitekit-vrt-animation-paused"> | ||
<Story /> | ||
</div> | ||
); | ||
}, | ||
]; | ||
|
||
export const ZeroData = Template.bind( {} ); | ||
ZeroData.storyName = 'Zero Data'; | ||
ZeroData.args = { | ||
setupRegistry: ( { dispatch } ) => { | ||
dispatch( MODULES_ANALYTICS_4 ).receiveGetReport( | ||
replaceValuesInAnalytics4ReportWithZeroData( | ||
getAnalytics4MockResponse( reportOptions ) | ||
), | ||
{ | ||
options: reportOptions, | ||
} | ||
); | ||
}, | ||
}; | ||
ZeroData.scenario = { | ||
label: 'KeyMetrics/TopConvertingTrafficSourceWidget/ZeroData', | ||
}; | ||
|
||
export default { | ||
title: 'Key Metrics/TopConvertingTrafficSourceWidget', | ||
decorators: [ | ||
( Story, { args } ) => { | ||
const setupRegistry = ( registry ) => { | ||
provideModules( registry, [ | ||
{ | ||
slug: 'analytics-4', | ||
active: true, | ||
connected: true, | ||
}, | ||
] ); | ||
|
||
registry.dispatch( CORE_USER ).setReferenceDate( '2020-09-08' ); | ||
|
||
provideKeyMetrics( registry ); | ||
|
||
// Call story-specific setup. | ||
args.setupRegistry( registry ); | ||
}; | ||
|
||
return ( | ||
<WithRegistrySetup func={ setupRegistry }> | ||
<Story /> | ||
</WithRegistrySetup> | ||
); | ||
}, | ||
], | ||
}; |
91 changes: 91 additions & 0 deletions
91
assets/js/modules/analytics-4/components/widgets/TopConvertingTrafficSourceWidget.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* TopConvertingTrafficSourceWidget component tests. | ||
* | ||
* Site Kit by Google, Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { render } from '../../../../../../tests/js/test-utils'; | ||
import { provideKeyMetrics } from '../../../../../../tests/js/utils'; | ||
import { provideAnalytics4MockReport } from '../../utils/data-mock'; | ||
import { getWidgetComponentProps } from '../../../../googlesitekit/widgets/util'; | ||
import { | ||
CORE_USER, | ||
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE, | ||
} from '../../../../googlesitekit/datastore/user/constants'; | ||
import TopConvertingTrafficSourceWidget from './TopConvertingTrafficSourceWidget'; | ||
|
||
describe( 'TopConvertingTrafficSourceWidget', () => { | ||
const { Widget, WidgetNull } = getWidgetComponentProps( | ||
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE | ||
); | ||
|
||
it.each( [ undefined, true ] )( | ||
'renders null when isKeyMetricsWidgetHidden() returns %s', | ||
async ( isWidgetHidden ) => { | ||
const { container, waitForRegistry } = render( | ||
<TopConvertingTrafficSourceWidget | ||
Widget={ Widget } | ||
WidgetNull={ WidgetNull } | ||
/>, | ||
{ | ||
setupRegistry: ( registry ) => { | ||
provideKeyMetrics( registry, { isWidgetHidden } ); | ||
}, | ||
} | ||
); | ||
await waitForRegistry(); | ||
|
||
expect( container ).toBeEmptyDOMElement(); | ||
} | ||
); | ||
|
||
it( 'renders correctly with the expected metrics when the Key Metrics widget is not hidden', async () => { | ||
const { container, waitForRegistry } = render( | ||
<TopConvertingTrafficSourceWidget | ||
Widget={ Widget } | ||
WidgetNull={ WidgetNull } | ||
/>, | ||
{ | ||
setupRegistry: ( registry ) => { | ||
registry | ||
.dispatch( CORE_USER ) | ||
.setReferenceDate( '2020-09-08' ); | ||
|
||
provideKeyMetrics( registry ); | ||
provideAnalytics4MockReport( registry, { | ||
compareStartDate: '2020-07-14', | ||
compareEndDate: '2020-08-10', | ||
startDate: '2020-08-11', | ||
endDate: '2020-09-07', | ||
dimensions: [ 'sessionDefaultChannelGroup' ], | ||
metrics: [ | ||
{ | ||
name: 'sessionConversionRate', | ||
}, | ||
], | ||
limit: 1, | ||
orderBy: 'sessionConversionRate', | ||
} ); | ||
}, | ||
} | ||
); | ||
await waitForRegistry(); | ||
|
||
expect( container ).toMatchSnapshot(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must have been scaffolded before, but there is a utility used by other widget tiles to simplify this which also prevents side effects from the widget rendering without the need to have conditional selects
site-kit-wp/assets/js/modules/analytics-4/components/widgets/LoyalVisitorsWidget.js
Line 128 in 96cf061
It might not be worth changing at this point as this should be covered by #7061
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aaemnnosttv, that's useful to know. It does seem this should conceptually be covered by #7061, but looking at the IB, it only specifies the removal of the
whenKeyMetricsWidgetVisible
HOC, with the only reference tokeyMetricsWidgetHidden
being in a struck-out line.Noting that there are other widgets currently doing a similar check with
isKeyMetricsWidgetHidden()
, and furthermore that #7061 is currently in execution with @jimmymadon, I'd say it's probably not worth updating this widget, but rather getting it merged while Jimmy's still working on #7061, and dropping him a line to make sure he mergesdevelop
into his branch and updates all of these widgets to remove the checks based onisKeyMetricsWidgetHidden()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - actually, I should have looked into #7061 a bit more deeply, I've now seen there's an open PR in which @jimmymadon is already addressing those
isKeyMetricsWidgetHidden()
checks in the other widgets. So this really just becomes a question about timing and if it makes sense to merge this PR while #7061 is in progress...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Having spoken to Jimmy on Slack he's happy to take the approach of merging
develop
into his branch once this one's merged, and updating this component along with the others.