Implement/refactor GA tracking events for help menu and URL search
See original GitHub issueFeature Description
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
click_outgoing_link
GA event in theglobal_help_menu
category should have its category adjusted to use{viewContext}_headerbar_helpmenu
instead, where{viewContext}
should be the current view context (see #4006 for related infrastructure). - The help menu feature tour (also using
global_help_menu
as GA event category currently) should have its category adjusted todashboard_headerbar_helpmenu
(usingVIEW_CONTEXT_DASHBOARD
for the “dashboard” part). If straightforward, it would be actually preferable to also use{viewContext}_headerbar_helpmenu
here (so that it automatically uses the current context), however hard-codingVIEW_CONTEXT_DASHBOARD
is acceptable since the feature tour can currently only render there anyway. - A new GA event
open_urldetails
should be added to the URL search widget in the Site Kit dashboard.- It should be triggered when the user actually submits, i.e. navigates away to that URL’s details page.
- The event category for this should be “dashboard_urlsearch-widget” (using
VIEW_CONTEXT_DASHBOARD
for the “dashboard” part).
- Note that these events should be present in both the old and new header bar (see #4048).
Implementation Brief
Inside assets/js/components/help/HelpMenuLink.js
:
- Import the View Context from
assets/js/components/Root/ViewContextContext.js
- Pass this to the
useContext
hook to get theviewContext
for the component:
import ViewContextContext from 'assets/js/components/Root/ViewContextContext';
import { useContext } from '@wordpress/element';
const viewContext = useContext( ViewContextContext );
- Refactor the call to
trackEvent
so that the category (first argument) is${viewContext}_headerbar_helpmenu
instead of'global_help_menu'
Inside assets/js/components/TourTooltips.js
:
-
As above, use the
useContext
hook and theViewContextContext
to determine the component’sviewContext
. -
Add the following logic to the
trackAllTourEvents
function:- Create a variable,
eventCategory
- test the
typeof gaEventCategory
. If it is a'function'
, call the function, passing in theviewContext
as an argument. Assign the result toeventCategory
. - Otherwise, fall back to the default, current behaviour and assign
gaEventCategory
- Refactor the rest of the logic in this function, replacing
gaEventCategory
references with the neweventCategory
variable. - Update the documentation for the
trackAllTourEvents
function to reflect thatgaEventCategory
can now be a string or a function that takes theviewContext
string and returns a string.
- Create a variable,
-
Inside
assets/js/components/TourTooltips.test.js
- Make sure the existing tests still pass now that the component uses context
- Add a test to cover the new scenario where a tour passes a function as
gaEventCategory
instead of a string
Inside assets/js/feature-tours/help-visibility.js
:
- refactor the
gaEventCategory
property to be a function that takes aviewContext
string and returns the following string:${viewContext}_headerbar_helpmenu
Inside assets/js/googlesitekit/widgets/components/URLSearchWidget.js
:
- Import
trackEvent
fromassets/js/util/tracking/index.js
- As above, use the
useContext
hook and theViewContextContext
to determine the component’sviewContext
. - Inside the
onClick
callback, before the call tonavigateTo
, calltrackEvent( viewContext, 'open_urldetails' )
Test Coverage
- As described in the IB.
QA Brief
- The help menu links and the help menu feature tour should use the new events described in the AC.
- The
URLSearchWidget
(the search bar entitled 'Search for individual page or post information` on the dashboard) should use the new event as per the AC.
Changelog entry
- N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Google Analytics Event Tracking Tutorial - Optimize Smart
Google Analytics event tracking allows you to track a specific user's activity with a web page element. Get the FREE ebook on 'Event...
Read more >Using Google Analytics Event Tracking - Hallam Internet
Google Analytics Event tracking is a useful feature in Google Analytics that allows users to record interactions a website to record PDF ...
Read more >[GA4] Automatically collected events - Analytics Help
Automatically collected events are triggered by basic interactions with your app and/or site (as indicated under the event name in the table below)....
Read more >How to use Google Analytics Event Tracking to capture ... - V&A
It shows how Google Analytics Event Tracking has been set up to capture data whenever visitors use the various navigation features on the...
Read more >How to Set Up Google Analytics Event Tracking - Hootsuite Blog
Step 1: Link your site to Google Analytics · Step 2: Add event tracking code to your website · Step 3: Find your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@eugene-manuilov I just spoke to @tofumatt and my understanding is that the final AC here is more of an FYI, as the header will likely use the same existing URL search component. I don’t think it requires anything in the IB.
QA: ✔️
Tested on
main
. LGTM!click_outgoing_links
events are being fired with the correct{viewContext}_headerbar_helpmenu
event category with theviewContext
being correctly inferred asdashboard
.module
andpageDasboard
accordingly.open_urldetails
is firing with thedashboard_urlsearch-widget
as category instead ofdashboard_urlsearch-widget
.