Closed tofumatt closed 6 months ago
@tofumatt do you mind adding an estimate to this ticket if possible?
- [ ] Using the
useRef
hook, add aref
to the renderedWidget
components (for bothWidget
components that rendersAdSenseLinkCTA
and the unconditionally rendered widget content).
@nfmohit, why not to implement event tracking in the CTA itself? The same way how we do it in the KeyMetricsCTAContent
component. In this case, we won't need to change the Widget
component.
In
assets/js/googlesitekit/widgets/components/Widget.js
:
- [ ] Accept additional (spread) props in the
Widget
component and pass any additional props passed intoWidget
to thediv.googlesitekit-widget
element.
If we really need this, then the component should be updated using the forwardRef
approach. https://react.dev/reference/react/forwardRef
- In the rendered
AdSenseLinkCTA
component, add anonClick
prop and track theclick_learn_more_link
event according to the ACs.
Let's expand this a little bit more and add more details to make sure that we have an agreement as to what we mean by "according to the ACs".
Hi @eugene-manuilov. As discussed, I have mentioned the usage of forwardRef
, and addressed other feedback. IB updated, thank you!
Ok, thanks. IB ✔️
I have been working on this today and have implemented it with one small addition to the IB; updating assets/js/googlesitekit/widgets/util/get-widget-component-props.js
to forward the ref through to the underlaying Widget
component.
However while testing this I found that if I scrolled down on the dashboard slowly the event would not trigger. It would only trigger if I scrolled to this section quickly, or clicked on "Monetization" then scrolled down from there. (I have a video I can share of this occurring I will share directly).
Debugging this a little, it seems the DashboardTopEarningPagesWidgetGA4
component does not get the updated node reference to the underlaying Widget
in this case as it's not rendered immediately and useRef does not trigger re-rendering when the underlaying node is created.
I could not repeat this bug with the /DashboardPageSpeed
widget.
I began looking at using useCallback
instead of useRef
, as in this React doc, to get the updated node, however this would not work with the useIntersection
hook so would required much additional work.
The simplest solution would instead to wrap the components with <div ref={ trackingRef }></div>
, within the DashboardTopEarningPagesWidgetGA4
, avoiding the use of forwardRef
entirely.
@tofumatt @eugene-manuilov, what is the best approach in your view?
Huh, good catch!
The simplest solution would instead to wrap the components with
<div ref={ trackingRef }></div>
, within theDashboardTopEarningPagesWidgetGA4
, avoiding the use offorwardRef
entirely.
Which components would need wrapping exactly? We need Widget
/WidgetNull
to be the top-level components that are returned for the widget layout code to work, but if you need to wrap anything insight I don't have a problem with that. 👍🏻
I've tried wrapping the internals of both of the Widgets
with <div ref={ trackingRef }></div>
, however the same bug occurs. trackingRef
does not pass the correct dom element to IntersectionObserver
.
The way I could resolve this was to intercept the ref
function and force the DashboardTopEarningPagesWidgetGA4
component to re-render when it received the DOM element:
Over to CR now.
View_notification
and 'click_learn_more_link'
events are getting trigger as per AC.@benbowler Since https://github.com/google/site-kit-wp/issues/8049 has not been merged yet we are using the code snippet provided under QAB to load the widget. However, I have noticed that when users view the 'Top earning pages'
widget then event 'view_widget'
is not being triggered. . Could you please investigate whether the event is not being triggered because we are forcibly displaying it through the code snippet, or if it is actually an issue with the event not being triggered under any circumstances?
View_notification
and 'click_learn_more_link'
and 'view_widget'
events are getting trigger as per AC.
Feature Description
GA events (eg.
trackEvent
calls) should be added to the new GA4-powered "Top Earning Pages" widget in its "setup"/CTA version. There should be one when a user views the widget, and one when they click the "Learn more" link in the widget, which serves as the CTA button.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
trackEvent
calls should be made:trackEvent( `${viewContext}_top-earning-pages-widget`, 'view_notification' )
when the widget is scrolled into view/is seen by the user (not when the component is mounted, but when it is seen)trackEvent( `${viewContext}_top-earning-pages-widget`, 'click_learn_more_link' )
when the user clicks the "Learn more" linktrackEvent
calls should be made:trackEvent( `${viewContext}_top-earning-pages-widget`, 'view_widget' )
when the widget is scrolled into view/is seen by the user (not when the component is mounted, but when it is seen)CTA widget screenshot:
Implementation Brief
assets/js/googlesitekit/widgets/components/Widget.js
:Widget
component usingforwardRef
and pass the receivedref
to thediv.googlesitekit-widget
element.assets/js/modules/analytics-4/components/common/AdSenseLinkCTA.js
:onClick
with an empty function as default.onClick
function to a newonClick
prop in the renderedCTA
component.assets/js/modules/adsense/components/dashboard/DashboardTopEarningPagesWidgetGA4.js
:useRef
hook, add aref
to the renderedWidget
components (for bothWidget
components that rendersAdSenseLinkCTA
and the unconditionally rendered widget content).useEffect
hook similar to theassets/js/components/KeyMetrics/KeyMetricsCTAContent.js
component and find out if the component is in view (for the first time). See: https://github.com/google/site-kit-wp/blob/5913a7fde140271d2ad64b02a5c34505d97e59a2/assets/js/components/KeyMetrics/KeyMetricsCTAContent.js#L69-L91.view_notification
event in the${viewContext}_top-earning-pages-widget
category.view_widget
event in the${viewContext}_top-earning-pages-widget
category.AdSenseLinkCTA
component, add anonClick
prop. In theonClick
prop function, track theclick_learn_more_link
event in the${viewContext}_top-earning-pages-widget
category.Test Coverage
QA Brief
ga4AdSenseIntegration
feature flag.To QA the linked state before #8049 is merged you can run
googlesitekit.data.dispatch('modules/analytics-4').setAdSenseLinked(true)
in the developer console and you will see the widgets load the report data if there are earnings for your test site and you can test the tracking events in this state.Changelog entry