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

[WooCommerce Analytics] Support for Search and Landing Page #40698

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Dec 20, 2024

Proposed changes:

  • Add support for woocommerceanalytics_search event
  • Rename woocommerceanalytics_session_id into woocommerceanalytics_session since now it stores more data
  • Refactor session data adding landing_page to it.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

Prerequisites

--

  1. Enter any page on the site and verify woocommerceanalytics_session_started is triggered with a session_id and landing_page prop with a clean URL.
  2. Navigate further over a product detail page and verify the events are trigger with the same session_id and landing_page props
  3. Perform a search (can be done by URL using ?s={query} or by adding Search Products block somewhere)
  4. See woocommerceanalytics_search is triggered with a search_query prop indicating the search query and qty prop indicating the results count. Also, session_id and landing_page props match the expected.
  5. Change your permalinks structure to use a Plain structure
  6. Remove woocommerceanalytics_session session cookie
  7. Repeat step 1. This structure should work as well.

@puntope puntope requested review from jeherve and ianlin December 20, 2024 10:20
@puntope puntope self-assigned this Dec 20, 2024
Copy link
Contributor

github-actions bot commented Dec 20, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the add/search-event branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/search-event
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Dec 20, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added [Feature] WooCommerce Analytics [Package] WooCommerce Analytics Enhanced analytics for WooCommerce users [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Dec 20, 2024
@puntope puntope added [Pri] Normal [Status] Needs Team Review [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Dec 20, 2024
@ianlin
Copy link
Member

ianlin commented Dec 24, 2024

Thanks for adding support for landing page and search.

I tested entering all the pages and the session_started event with landing page prop works well, but there's one case that might need to be checked. Here's my step:

  1. Open an incognito page, enter cart page directly: https://mysite.example.com/cart/
  2. There are two events being sent: session_started and cart_view
  3. The session_started event has session_id and landing_page correctly
  4. But the cart_view event does not have values for both props
Screenshot 2024-12-24 at 13 29 34

There's also another case that session_started event was not triggered by looking in Tracks Vigilante Chrome extension:

  1. Open an incognito page, go to the checkout page directly: https://mysite.example.com/checkout/
  2. Since there is no products added to cart, checkout page will return 302 and redirect to cart page
  3. The cart_view event is sent but no session_started event
  4. However, the cart_view event includes session_id and the landing_page prop correctly, so I guess the session_started might be sent somewhere, but did not display in Tracks Vigilante Chrome extension

@puntope
Copy link
Contributor Author

puntope commented Dec 24, 2024

Thanks @ianlin for catching that. It seems to be an inherited issue. The object was not accessible in the checkout-flow file. I merge those actions inside the universal file.

Now it should work

Can we have another round?

@ianlin
Copy link
Member

ianlin commented Dec 26, 2024

Thanks for the change.

I tested the first scenario from the #40698 (comment) above:

  1. Open an incognito page, enter cart page directly: https://mysite.example.com/cart/
  2. There are two events being sent: session_started and cart_view
  3. The session_started event has session_id and landing_page correctly
  4. But the cart_view event does not have values for both props

Right now the cart_view includes the expected props, but the session_started event is not fired. I searched on the Tracks Live View using my user ID _ui for session_started and cart_view, and there was not result for the session_started event.

Screenshot 2024-12-26 at 11 00 36 Screenshot 2024-12-26 at 11 01 03

@puntope
Copy link
Contributor Author

puntope commented Dec 26, 2024

Right now the cart_view includes the expected props, but the session_started event is not fired. I searched on the Tracks Live View using my user ID _ui for session_started and cart_view, and there was not result for the session_started event.

Thanks @ianlin for the review. I cannot reproduce the error you mentioned.

recording.mov

Can you make sure you tested by removing the session from the cookie? The reason it doesn't appear in Tracks is because the lifetime of the tracks is 2h maximum so maybe your session_started was recorded before that.

@ianlin
Copy link
Member

ianlin commented Dec 27, 2024

Can you make sure you tested by removing the session from the cookie?

Thanks for the hint, I did not manually remove the session cookie, I only closed and reopened the incognito page.

So here's what I've discovered:

Scenario A: Remove session cookie and go to cart page

  1. Remove session cookie
  2. Go to cart page
  3. session_started and cart_view are sent

Scenario B: Do not remove session cookie, close and reopen incognito page, and go the cart page

  1. Do not remove session cookie
  2. Close the incognito page, the reopen one
  3. Go to cart page
  4. Only cart_view is sent, and the session ID is different from the one in step one

Scenario C: Remove session cookie and go to checkout page

  1. Remove session cookie
  2. Go to checkout page
  3. It will 302 redirect to cart page automatically
  4. The cart_view event is sent with session_id and landing_page props, but session_started event is not sent

Scenario D: Remove session cookie, close and reopen incognito page, and go the checkout page

  1. Remove session cookie
  2. Close the incognito page, the reopen one
  3. Go to cart page
  4. Only cart_view is sent, and the session ID and the _uid are different from the ones before removing the session cookie
  5. Search In Track Live Events by the _uid after 5 minutes, only cart_view event appears

Sorry if I mistakenly test this functionality 🙏, I was trying to test all the cases that I can think of.

Also, what I have done to apply your new commits was:

  1. Pull the new commits
  2. Rebuild jetpack by running jetpack build plugins/jetpack
  3. Start testing

Did I miss something?

@puntope
Copy link
Contributor Author

puntope commented Dec 30, 2024

Hey @ianlin Thanks again for testing the PR. I appreciate the thorough testing :)

I will go over your cases one by one:

Scenario B: Do not remove session cookie, close and reopen incognito page, and go the cart page

Worked for me. Attached video:

Screen.Recording.2024-12-30.at.19.31.58.mov

Scenario C: Remove session cookie and go to checkout page

Very tricky to solve this. And a good catch on your side. Seems that the session was sent before the redirect happened. So the cookie is set and record_event method is called. However, is never sending an event because the redirect prevents wp_enqueue_js to load.

In the next request to cart, after the redirection happens. The session cookie is set already, but session_started record_event never happens as explained before.

Now I fixed it using template_redirect hook. It should work now.

Screen.Recording.2024-12-30.at.21.07.23.mov

Scenario D: Remove session cookie, close and reopen incognito page, and go the checkout page

This I'm a bit confused. In title, you mention "go the checkout page". So it means is same as scenario C. However, in the details, you mention "Go to cart page" so it's scenario B.

In any case, I believe now it's working finally. Can we test one round more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WooCommerce Analytics [Package] WooCommerce Analytics Enhanced analytics for WooCommerce users [Pri] Normal [Status] Needs Team Review [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants