-
Notifications
You must be signed in to change notification settings - Fork 295
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 GA4 DashboardAllTrafficWidget. #6514
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
a6f5835
Add initial DashboardAllTrafficWidgetGA4 widget, still using UA data.
techanvil 46b7fac
Add initial DashboardAllTrafficWidgetGA4 stories, still using UA data.
techanvil 2837424
Add initial GA4 DimensionTabs and UserDimensionsPieChart (still UA da…
techanvil 53fd40a
Add GA4 isGatheringData and hasZeroData selectors, and isZeroData fun…
techanvil 5a3cf8c
Add initial GA4 TotalUserCount and UserCountGraph (still UA data).
techanvil 0e5a5f9
Fix GA4 mock data utility.
techanvil 2a189b4
Update to use GA4 report options and selectors.
techanvil 53fe19d
Add GA4 extractAnalyticsDataForPieChart function (still UA data).
techanvil 32afa85
Update DashboardAllTrafficWidgetGA4 to use GA4 report data.
techanvil 18cdc86
Prevent getAnalytics4MockResponse from mutating passed options.
techanvil 36623fa
Update DashboardAllTrafficWidgetGA4 stories to use GA4 data.
techanvil 2cf72f3
Update DashboardAllTrafficWidgetGA4 stories.
techanvil 223aafa
Rename story file.
techanvil 3a9b81d
Add Entity Dashboard stories for DashboardAllTrafficWidgetGA4.
techanvil 5eebd0c
Improve date range handling in getAnalytics4MockResponse.
techanvil 69cced1
Rename story files.
techanvil 92578fd
Specify "Main Dashboard" rather than just "Dashboard".
techanvil 146308b
Fix getAnalytics4MockResponse for multiple date ranges.
techanvil 64974b5
Fix report args in DashboardAllTrafficWidgetGA4 story.
techanvil ed3b9ab
Add tests for GA4 isZeroReport.
techanvil f4ea986
Add tests for isSingleSliceGA4.
techanvil a6a0b07
Add tests for GA4 isGatheringData and hasZeroData.
techanvil ca3414d
Add TODO comments.
techanvil 7fbce1a
Fix typo.
techanvil 8492da8
Fix DashboardAllTrafficWidgetGA4 Loading VRT scenarios.
techanvil 2f56fb8
Fix VRT animation rules.
techanvil 7bf4e11
Add VRT reference images for DashboardAllTrafficWidgetGA4.
techanvil afa014c
Restore UA All Traffic widget on Dashboard.
techanvil d44b5a1
Add comment.
techanvil c5ca3a4
Fix typo.
techanvil 16ae1bb
Fix copyright year in file headers.
techanvil d8ef488
Merge branch 'develop' into enhancement/6216-ga4-all-traffic-widget.
techanvil bebd5a3
Update orderby to use new shape.
techanvil 0b3363b
Order line chart by date.
techanvil 09d4dba
Fix merge error.
techanvil d974e42
Avoid creating a new `util` directory where there is `utils`.
techanvil 87b7c0d
Rename file.
techanvil dcc30d0
Move isSingleSliceGA4 to isSingleSlice in GA4 module.
techanvil 611fc5a
Fix "one row of data" stories.
techanvil 12deb97
Merge branch 'develop' into enhancement/6216-ga4-all-traffic-widget.
techanvil b81f9e4
Fix DashboardAllTrafficWidgetGA4 Data Unavailable and Zero Data stories.
techanvil af96125
Fix rendering of UserCountGraph chart ticks for empty reports.
techanvil e46af58
Update VRT reference images.
techanvil bda3284
Only add zero data rows for the zero data case, and not for gathering…
techanvil 9ae3bd1
Remove commented out lines.
techanvil 729d642
Update VRT reference images.
techanvil 208e9f3
Avoid abbreviated variable name.
techanvil 87e2e64
Use tab dimensionName rather than index for key and in select value.
techanvil e19ffcf
Clarify comment.
techanvil ff3f09b
Restore use of index in option value.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,16 @@ | |
#root *, | ||
#root *::before, | ||
#root *::after { | ||
animation-duration: 0ms !important; | ||
transition-duration: 0ms !important; | ||
} | ||
|
||
/* We only want to override animation-duration if _not_ pausing the animations via the .googlesitekit-vrt-animation-paused class. */ | ||
#root:not( :has( .googlesitekit-vrt-animation-paused ) ) *, | ||
#root:not( :has( .googlesitekit-vrt-animation-paused ) ) *::before, | ||
#root:not( :has( .googlesitekit-vrt-animation-paused ) ) *::after { | ||
animation-duration: 0ms !important; | ||
} | ||
|
||
/** | ||
* While the rules above set animation-duration to 0ms for VRT builds, there can be times where this is not appropriate. | ||
* For example if there is a constant animation in a story, it results in the animation running constantly at top speed and the VRT screengrab becomes somewhat undeterministic. | ||
|
@@ -18,4 +24,15 @@ | |
animation: none !important; | ||
transition: none !important; | ||
} | ||
|
||
/** | ||
* An alternative scenario is that the VRT scenario does not render correctly unless the animation is active but paused. | ||
* In this case, we can apply the following .googlesitekit-vrt-animation-paused class to a story wrapper element to pause animations for a given story. | ||
* Please note, this only applies to animations and not transitions which don't have an equivalent paused state. | ||
*/ | ||
#root .googlesitekit-vrt-animation-paused *, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class has been added to allow the |
||
#root .googlesitekit-vrt-animation-paused *::before, | ||
#root .googlesitekit-vrt-animation-paused *::after { | ||
animation-play-state: paused !important; | ||
} | ||
</style> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* Analytics utility functions. | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Extracts data required for a pie chart from the Analytics 4 report information. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param {Array} report The report data. | ||
* @param {Object} [options] Optional. Data extraction options. | ||
* @param {number} [options.keyColumnIndex] Optional. The number of a column to extract metrics data from. | ||
* @param {number} [options.maxSlices] Optional. Limit the number of slices to display. | ||
* @param {boolean} [options.withOthers] Optional. Whether to add "Others" record to the data map. Only relevant | ||
* if `maxSlices` is passed. If passed, the final slice will be the | ||
* "Others" slice, i.e. the number of actual row slices will be | ||
* `maxSlices - 1`. | ||
* @param {Function} [options.tooltipCallback] Optional. A callback function for tooltip column values. | ||
* @return {Array} Extracted data. | ||
*/ | ||
export function extractAnalyticsDataForPieChart( report, options = {} ) { | ||
const { | ||
keyColumnIndex = 0, | ||
maxSlices, | ||
withOthers = false, | ||
tooltipCallback, | ||
} = options; | ||
|
||
const { rows = [], totals = [] } = report || {}; | ||
|
||
const withTooltips = typeof tooltipCallback === 'function'; | ||
const columns = [ 'Source', 'Percent' ]; | ||
if ( withTooltips ) { | ||
columns.push( { | ||
type: 'string', | ||
role: 'tooltip', | ||
p: { | ||
html: true, | ||
}, | ||
} ); | ||
} | ||
|
||
const totalUsers = | ||
totals?.[ 0 ]?.metricValues?.[ keyColumnIndex ]?.value || 0; | ||
const dataMap = [ columns ]; | ||
|
||
const currentDateRangeRows = rows.filter( | ||
( { dimensionValues } ) => dimensionValues[ 1 ].value === 'date_range_0' | ||
); | ||
|
||
let hasOthers = withOthers; | ||
let rowsNumber = currentDateRangeRows.length; | ||
let others = 1; | ||
if ( maxSlices > 0 ) { | ||
hasOthers = withOthers && currentDateRangeRows.length > maxSlices; | ||
rowsNumber = Math.min( | ||
currentDateRangeRows.length, | ||
hasOthers ? maxSlices - 1 : maxSlices | ||
); | ||
} else { | ||
hasOthers = false; | ||
rowsNumber = currentDateRangeRows.length; | ||
} | ||
|
||
for ( let i = 0; i < rowsNumber; i++ ) { | ||
const row = currentDateRangeRows[ i ]; | ||
const users = row.metricValues[ keyColumnIndex ].value; | ||
const percent = totalUsers > 0 ? users / totalUsers : 0; | ||
|
||
others -= percent; | ||
|
||
const rowData = [ row.dimensionValues[ 0 ].value, percent ]; | ||
if ( withTooltips ) { | ||
const previousDateRangeRow = rows.find( | ||
( { dimensionValues } ) => | ||
dimensionValues[ 1 ].value === 'date_range_1' && | ||
dimensionValues[ 0 ].value === | ||
row.dimensionValues[ 0 ].value | ||
); | ||
|
||
rowData.push( | ||
tooltipCallback( row, previousDateRangeRow, rowData ) | ||
); | ||
} | ||
|
||
dataMap.push( rowData ); | ||
} | ||
|
||
if ( hasOthers && others > 0 ) { | ||
const rowData = [ __( 'Others', 'google-site-kit' ), others ]; | ||
if ( withTooltips ) { | ||
rowData.push( tooltipCallback( null, null, rowData ) ); | ||
} | ||
|
||
dataMap.push( rowData ); | ||
} | ||
|
||
return dataMap; | ||
} | ||
|
||
/** | ||
* Checks if there is a single row of data or one row of the provided GA4 report is contributing 100% of the total for a given dimension. | ||
* | ||
* Note that chart reports will be in the multi-date range format. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param {Object} report The report data object. | ||
* @return {(boolean|undefined)} Returns undefined if report is undefined, true/false for the above conditions. | ||
*/ | ||
export const isSingleSlice = ( report ) => { | ||
if ( report === undefined ) { | ||
return undefined; | ||
} | ||
|
||
const currentDateRangeRows = ( report?.rows || [] ).filter( | ||
( { dimensionValues } ) => dimensionValues[ 1 ].value === 'date_range_0' | ||
); | ||
|
||
if ( | ||
currentDateRangeRows?.length === 1 || | ||
currentDateRangeRows?.[ 0 ]?.metricValues?.[ 0 ]?.value === | ||
report?.totals?.[ 0 ]?.metricValues?.[ 0 ]?.value | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; |
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.
Please remember to review the notes in Relevant technical choices in the PR description.