Skip to content
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

Adjust event tracking for the creating and claim buttons of Google Ads account #2419

Conversation

eason9487
Copy link
Member

@eason9487 eason9487 commented May 30, 2024

Changes proposed in this Pull Request:

PT: pcTzPl-2iK-p2

Since the context property of most event tracking is currently hardcoded, and there is no proper way to obtain state or data from far away components when sending event tracking, this PR tries to implement it via @wordpress/hooks. The goal is to avoid passing event properties in a prop drilling fashion, e.g. context and step at the <Stepper> layer in this PR need to be sent together in buttons several layers away.

Due to the number of files being changed, to avoid this PR getting too large, I would like to use two tracking events to show how the mechanism works, and then add the remaining event tracking in a subsequent PR.

📌 Mechanism:

  • Add a React hook useEventPropertiesFilter to handle event properties across multiple layers of components via @wordpress/hooks.

📌 Event tracking:

  • Add context and step event properties to Extension and Ads onboarding steppers for use by their subcomponents.
  • Add event tracking to ClaimAccountButton.
  • Add context and step event properties to the click event tracking in TermsModal.

📌 Extra change:

  • Reuse ClaimAccountButton to reduce the duplicate implementation.
  • Adjust jest config and setup so that tests related to event tracking don't have to validate global event properties.

Screenshots:

📷 Event tracking when clicking on button to create Google Ads account in the Extension onboarding

1

📷 Event tracking when clicking on button to open the claim page of Google Ads account in the Extension onboarding

2

📷 Event tracking when clicking on button to create Google Ads account in the Ads onboarding

3

📷 Event tracking when clicking on button to open the claim page of Google Ads account in the Ads onboarding

4

Detailed test instructions:

  1. Open the Console tab in the browser DevTool, and run localStorage.setItem( 'debug', 'wc-admin:*' ) to enable tracking debugging mode.
  2. Disconnect Google Ads account if there is a connected one.
  3. Go to step 1 of the Extension onboarding.
  4. Create a new Google Ads account.
  5. Check if the gla_ads_account_create_button_click event is sent with context and step
  6. Click the "Claim account" button to open the invitation link in a pop-up window for the newly created Google Ads account.
    • It doesn't need to proceed with the claim process here
  7. Check if the gla_ads_account_create_button_click event is sent with context and step.
  8. Disconnect Google Ads account if there is a connected one.
  9. Go to step 1 of the Ads onboarding.
  10. Repeat test steps 4-7

Changelog entry

Tweak - Adjust event tracking for the creating and claim buttons of Google Ads account.

@eason9487 eason9487 requested a review from a team May 30, 2024 11:21
@eason9487 eason9487 self-assigned this May 30, 2024
@github-actions github-actions bot added the changelog: tweak Small change, that isn't actually very important. label May 30, 2024
Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.

Project coverage is 62.6%. Comparing base (c5fe2d8) to head (1179f5b).

Additional details and impacted files

Impacted file tree graph

@@                             Coverage Diff                             @@
##             feature/seamlessly-conversion-tracking   #2419      +/-   ##
===========================================================================
- Coverage                                      64.0%   62.6%    -1.4%     
===========================================================================
  Files                                           778     321     -457     
  Lines                                         21854    5019   -16835     
  Branches                                       1212    1216       +4     
===========================================================================
- Hits                                          13987    3141   -10846     
+ Misses                                         7698    1709    -5989     
  Partials                                        169     169              
Flag Coverage Δ
js-unit-tests 62.6% <98.1%> (+0.8%) ⬆️
php-unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ts/google-ads-account-card/claim-account-button.js 100.0% <100.0%> (+50.0%) ⬆️
...mponents/google-ads-account-card/create-account.js 65.6% <100.0%> (ø)
...nents/google-ads-account-card/terms-modal/index.js 100.0% <100.0%> (+88.9%) ⬆️
js/src/hooks/useEventPropertiesFilter.js 100.0% <100.0%> (ø)
js/src/setup-ads/ads-stepper/index.js 100.0% <100.0%> (ø)
.../src/setup-mc/setup-stepper/saved-setup-stepper.js 87.8% <100.0%> (+0.3%) ⬆️
...ectComponentToRecordEventWithFilteredProperties.js 100.0% <100.0%> (ø)
js/src/utils/tracks.js 75.8% <100.0%> (+6.5%) ⬆️
...nts/google-ads-account-card/claim-account-modal.js 16.7% <50.0%> (+8.3%) ⬆️

... and 460 files with indirect coverage changes

@tomalec
Copy link
Member

tomalec commented May 30, 2024

At step 7. on onboardign flow, I didn't get context and step properties
image
Screencast from 30.05.2024 21:45:13.webm

I don't get it when I click "Claim Account" button in the modal in the main flow just after creating a new account.
Once I reload the page after account creation and click "Calim Account" the properties are set correctly.

@eason9487
Copy link
Member Author

Hi @tomalec, thanks for catching this.

At step 7. on onboardign flow, I didn't get context and step properties
I don't get it when I click "Claim Account" button in the modal in the main flow just after creating a new account. Once I reload the page after account creation and click "Calim Account" the properties are set correctly.

Sorry, I tested each event tracking separately but missed the interaction between useEventPropertiesFilter instances. The issue should have been fixed in 2129e87.

Could you help with a new round?

@eason9487
Copy link
Member Author

Added JS tests for the useEventPropertiesFilter hook. 8dd83ab

Copy link
Member

@tomalec tomalec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and reviewed the code LGTM.

Left some non-blocking comments and questions.

js/src/hooks/useEventPropertiesFilter.js Outdated Show resolved Hide resolved
} );

it( 'should record click events and be aware of extra event properties from filters', async () => {
await expectEventWithPropertiesFilter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅
I read expectEventWithPropertiesFilter as I'd read expect(event_with_properties_filter), so something that starts an expectation to which I can attach matches.
But then, in this usage, "I expect the event with properties filter to do what?"

Here, the function already applies matches and actually tests.

WDYT, of renaming the function to expect___To___(). I hope such a notion could help me with the below.
Actually, I had a hard time understanding even after reading the source code, what entity we attach the expectation to: an event, a component, a filter.; and what is the behavior we expect: to be recorded, to be recorded with given properties, to be clicked, to be filtered?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it that we "expect the given component, to record an event of given name, with given properties filtered by given filter, once clicked on a target"?
So something like expect( Component ).toRecordEventWithFilteredPropertiesOnceClicked(eventName, properties, filterName, clickTarget )
Or do I miss something?

Copy link
Member Author

@eason9487 eason9487 Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it that we "expect the given component, to record an event of given name, with given properties filtered by given filter, once clicked on a target"?

Yes.

WDYT, of renaming the function to expect___To___(). I hope such a notion could help me with the below.
Actually, I had a hard time understanding even after reading the source code, what entity we attach the expectation to: an event, a component, a filter.; and what is the behavior we expect: to be recorded, to be recorded with given properties, to be clicked, to be filtered?

Thanks for the suggestion! Made some changes in 8348389:

  • Added JSDoc
  • Changed the use of the queryElement callback and renamed it to performAction
    • The action of triggering an event tracking is completely moved from this function to the callers
    • This should make the use of this function more flexible and the naming does not need to carry the “OnceClicked”
  • Renamed expectEventWithPropertiesFilter to expectComponentToRecordEventWithFilteredProperties

js/src/hooks/useEventPropertiesFilter.js Outdated Show resolved Hide resolved
@eason9487 eason9487 merged commit fade6ca into feature/seamlessly-conversion-tracking Jun 5, 2024
7 checks passed
@eason9487 eason9487 deleted the tweak/2215-event-tracking-part-1 branch June 5, 2024 08:43
@mikkamp mikkamp mentioned this pull request Jun 10, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: tweak Small change, that isn't actually very important.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants