Display actual number of users coming from search in refactored "Unique Visitors (from Search)" widget
The refactored version of the "Unique Visitors from Search" widget currently uses "Unique Visitors" title, since the widget is (and has always been 🤦♂️ ) displaying the total number of users. This is actually wrong, and it should display the number of users that came from Organic Search.
This is a bug in the legacy widget primarily, but it should only be fixed in the refactored version, since that will roll out anyway.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The Analytics
DashboardUniqueVisitorsWidget(visible when enablingwidgets.dashboard/widgets.pageDashboardfeature flags) should be updated as follows:- It should be renamed to
DashboardSearchVisitorsWidgetthroughout the codebase (also related references, e.g. Storybook name). - Its title should be changed to "Unique Visitors from Search".
- It should display metrics for only users that came from Organic Search instead of all users (i.e. for
dimensionNameofga:channelGroupinganddimensionValueofOrganic Search). - Its source link should be updated accordingly:
- It should link to a specific version of the
acquisition-channelsreport. - The URL's
_r.drilldownargument should includeanalytics.trafficChannel:Organic%20Search. - The URL should otherwise include the current date parameters and, if relevant, the
analytics.pagePathfor the current entity URL within_r.drilldown.- Multiple
_r.drilldownparameters can be included by concatenating with a comma, e.g._r.drilldown=analytics.trafficChannel:Organic%20Search,analytics.pagePath:~2F.
- Multiple
- It should link to a specific version of the
- It should be renamed to
- The legacy "Unique Visitors from Search" widget does not need to be updated, even though the same thing is broken there too.
Implementation Brief
Rename assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js to assets/js/modules/analytics/components/dashboard/DashboardSearchVisitorsWidget.js
Update references in:
- stories/module-analytics-components.stories.js
- assets/js/modules/analytics/index.js
Change title and label in https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js#L149 and in
https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js#L125 to
Unique Visitors from Search
Update the commonArgs as both the regular report and sparkline will need to filter for users that only come from organic search,
in https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js#L63
add these after the date params:
dimensions: ['ga:channelGrouping']
dimensionFilters: { 'ga:channelGrouping': 'Organic Search'}
Also make sure that sparklineArgs also retains ga:date dimension
Update serviceURL from visitors-overview to acquisition-channels
https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js#L102
Update _r.drilldown param https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/components/dashboard/DashboardUniqueVisitorsWidget.js#L103 as specified in AC. No need to urlencode params as there is a function that takes care of that (so it will do the " " -> %20 and "/" -> %2F -> ~2F ). For reference the function is located in /assets/js/modules/analytics/util/report-args.js and looking at the tests for it can give an idea of expected inputs and outputs.:
https://github.com/google/site-kit-wp/blob/c85a22563e5a78d0cbe4c53b0f50489eb48a5f97/assets/js/modules/analytics/util/report-args.js#L53
Test Coverage
- Update backstop screenshots as the component will be updated, you may also need to update the storybook stories.
Visual Regression Changes
- Labels will update on the widget, requiring a new screenshot.
QA Brief
- Go to the Site Kit dashboard and find the 'Search Funnel' widget
- The 'Unique Visitors' widget should now be renamed to 'Unique Visitors from Search'
- It should also be displaying metrics only for users that came from Organic Search (instead of all users).
- The source link to 'Analytics' under the sparkline should now point to
acquisition-channelsrather thanvisitors-overview.
Changelog entry
- Update Unique Visitors widget to display the actual number of users coming from search
Thanks @ivankruchkoff – a few things to address yet.
- The IB does not currently address the change to displayed metric itself
It should display metrics for only users that came from Organic Search instead of all users (i.e. for
dimensionNameofga:channelGroupinganddimensionValueofOrganic Search). - It's important to note that
serviceReportURLargument values (e.g.analytics.trafficChannel:Organic%20Search) should not be URL encoded to avoid double encoding- This includes
/->~2Ffor the page path which is also handled by the selector
- This includes
Thanks @ivankruchkoff – a few things to address yet.
The IB does not currently address the change to displayed metric itself
It should display metrics for only users that came from Organic Search instead of all users (i.e. for
dimensionNameofga:channelGroupinganddimensionValueofOrganic Search).It's important to note that
serviceReportURLargument values (e.g.analytics.trafficChannel:Organic%20Search) should not be URL encoded to avoid double encoding
- This includes
/->~2Ffor the page path which is also handled by the selector
@aaemnnosttv I've made an update, can you confirm that the common report args are the right place to add dimensionName and dimensionValue.
I also added another label that needs updating.
@ivankruchkoff report selectors don't have arguments for dimensionName or dimensionValue. We need to pass these to the dimensions and dimensionFilters respectively, but it's not a 1-1 change. See the docs for these options here: https://github.com/google/site-kit-wp/blob/e465574ad2be4bfcdca30f744c0dc0be208e17e2/assets/js/modules/analytics/datastore/report.js#L138-L139
I think you also worked on the backend for the dimensionFilters at one point too.
can you confirm that the common report args are the right place to add
Yes it looks like it since these args are shared between reports used for the main data (stat) and for the sparkline chart 👍
@ivankruchkoff report selectors don't have arguments for
dimensionNameordimensionValue. We need to pass these to thedimensionsanddimensionFiltersrespectively, but it's not a 1-1 change. See the docs for these options here:https://github.com/google/site-kit-wp/blob/e465574ad2be4bfcdca30f744c0dc0be208e17e2/assets/js/modules/analytics/datastore/report.js#L138-L139
I think you also worked on the backend for the
dimensionFiltersat one point too.can you confirm that the common report args are the right place to add
Yes it looks like it since these args are shared between reports used for the main data (stat) and for the sparkline chart 👍
Updated, and yes git blame certainly points at me :) 2421
LGTM 😄
IB ✅
QA Update: Fail ❌
@johnPhillips three observations:
-
the organic search in the pie chart is displaying 472 users, where the Unique Visitors from Search' data shows 551 unique visitors. Should these be the same? When I ran the report directly in Analytics, 551 was the result, but would like to check because I wonder if the difference will create confusion?
-
When I click on the
Source: Analyticslink it takes me to thevisitors-overviewreport in Analytics, but according to the QAB it should beacquisition-channels -
The default period for the report in Analytics is 7 days, but in Site Kit, the period was set to 28 days, is this correct?

Verified:
The 'Unique Visitors' widget is now be renamed to 'Unique Visitors from Search' - Screenshot
@wpdarren Thanks for the review.
Something funny might be going on here, I think... This is my local environment - the figures match up:

The source link under 'Unique visitors from search' points at acquisition-channels, and the duration on the report is 28 days 🙈
Is it possible to share a link to the site you used here? Also, I wonder if it is worth checking whether there is some sort of cache issue. Perhaps the code on the site you are looking at needs a refresh? I don't know what your workflow is for QA but perhaps you could try clearing the browser cache, session storage etc.
If the code is up to date then this might require someone with a slightly better understanding than me about analytics reporting to have a little look as well. As far as I could see I implemented the IB correctly. CC @ivankruchkoff I don't know if you can spot any issues with my PR - happy to address them if so 🙏
@johnPhillips let me go through my test site and make sure it is not a caching issue.
QA Update: Pass ✅
Verified:
- The 'Unique Visitors' widget is now be renamed to 'Unique Visitors from Search'
- The 'Unique Visitors from Search' is displaying metrics only for users that came from Organic Search.
- The source link to 'Analytics' under the sparkline now points to
acquisition-channelsrather thanvisitors-overview.

@johnPhillips I figured out the issue with why the data was different (needed to set widgets.dashboard in the tester plugin on my test site)
Approval ❌
There is a problem here related to the source link: It only leads to the filtered view including only "Organic Search" in the single URL view. On the overall dashboard, it still leads to the overall channels view without the "Organic Search" filter like it should.
This is because in https://github.com/google/site-kit-wp/pull/3142/files#diff-05c312086666c0cdc8e39ab72ba4f96e393a1448ace9e0593c2b8618e9c091edR105 the required filter parameter is only added if a single entity URL is present, but it needs to always be added.
@johnPhillips @eugene-manuilov @wpdarren
With the additional fix merged, this works as expected now! ✅