google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 291 forks source link

Copy over relevant parts of the `Analytics` class into `Analytics_4` #7926

Closed nfmohit closed 8 months ago

nfmohit commented 11 months ago

Feature Description

In an effort to use analytics-4 as the singular Analytics module, the goal is to make the Analytics class obsolete and only use the Analytics_4 class going forward.

Even though most of the Analytics class is no longer relevant after the removal of UA, there are still some parts that are still relevant, and thus should be copied over to Analytics_4. Some notable pieces are:

  1. handle_provisioning_callback method: This method co-exists between both Analytics and Analytics_4 classes. They should be merged into one removing the need to use a hook to trigger the other.
  2. get_debug_fields method: Since the accountID setting will be a part of Analytics_4, its get_debug_fields method should be updated to include debug information for this setting.
  3. register method: This method includes different callbacks to hooks that should be carefully evaluated and merged.
  4. is_tracking_disabled & print_tracking_opt_out methods: These methods implement the Analytics tracking opt-out for certain user groups. They should be merged accordingly.
  5. Analytics\Advanced_Tracking class: This class should be migrated to the Analytics_4 namespace, but not be instantiated, as it will be updated to work with GA4 as a part of #7145.

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

QA Eng

Changelog entry

tofumatt commented 11 months ago

@nfmohit Because this deals with functionality after the removal of UA, but doesn't explicitly specify what that is in the AC nor is blocked by a UA removal issue, can you add the points you mention in the issue description to the ACs? Just so it's extra-clear what should be moved over and what shouldn't be 🙂

Then this should be good-to-go 👍🏻

nfmohit commented 11 months ago

@nfmohit Because this deals with functionality after the removal of UA, but doesn't explicitly specify what that is in the AC nor is blocked by a UA removal issue, can you add the points you mention in the issue description to the ACs? Just so it's extra-clear what should be moved over and what shouldn't be 🙂

Then this should be good-to-go 👍🏻

Thank you for the kind review, @tofumatt. I intentionally wanted to leave this out as open-ended so that the specific discovery could be a part of the IB process. There might be other small pieces still needed outside of the methods/pieces that are mentioned in the issue description which might've been missed while authoring the design doc. According to your feedback, I have included them in the ACs, but also left another point about being cautious of any other piece that might still be needed. LMKWYT, thanks!

tofumatt commented 11 months ago

Sounds good, that makes sense 👍🏻

Moving to IB 🙂

techanvil commented 11 months ago

Hey @zutigrm, thanks for drafting this IB. A few notes:

zutigrm commented 11 months ago

@techanvil Thank you for the review.

exception_to_error

This seems to be needed, as it is used in Analytics 4 method here

I think we'll still need the GET:accounts-properties-profiles endpoint until we fully move from the analytics getAccounts() to analytics-4 getAccountSummaries(), please could you check this and update as necessary?

This is being done as part of #7637, which is switching to account summaries, so GET:accounts-properties-profiles doesn't seem to be needed

We'll also need to migrate the check for accountID in is_connected().

This will be done as part of #7932 where final migration and removal of old analytics module is done, which also turns off the internal property and makes it only Analytics module, which makes more sense that is_connected will be checked against accountID, but I can include it here is well, if it makes sense to be done as part of this issue?

Let me know what you think

techanvil commented 11 months ago

Thanks @zutigrm.

exception_to_error

This seems to be needed, as it is used in Analytics 4 method here

This Analytics_4 method calls the version of exception_to_error() defined in the superclass, it doesn't need the overridden version that Analytics provides.

I think we'll still need the GET:accounts-properties-profiles endpoint until we fully move from the analytics getAccounts() to analytics-4 getAccountSummaries(), please could you check this and update as necessary?

This is being done as part of #7637, which is switching to account summaries, so GET:accounts-properties-profiles doesn't seem to be needed

Good spot there, however, if you review the search results for Analytics getAccounts() vs the IB for #7637, there will still be some remaining usage of it. As the description for that issue alludes to, it's just a start of the migration from getAccounts() to getAccountSummaries() so we'll still need this in the short term at least.

We'll also need to migrate the check for accountID in is_connected().

This will be done as part of #7932 where final migration and removal of old analytics module is done, which also turns off the internal property and makes it only Analytics module, which makes more sense that is_connected will be checked against accountID, but I can include it here is well, if it makes sense to be done as part of this issue?

Good spot, and seeing as the change to is_connected() is specced in the IB for that issue, we can leave it out of this one.

zutigrm commented 11 months ago

@techanvil Got it, thanks! IB updated

techanvil commented 11 months ago

Thanks @zutigrm! IB LGTM. :white_check_mark:

techanvil commented 11 months ago

Hey @jimmymadon @zutigrm - apologies for missing this during the IB review, but I've just realised we are creating a GA4 version of getAccounts() in https://github.com/google/site-kit-wp/issues/7637, which uses accountSummaries under the hood, so we should in fact no longer need the GET:accounts-properties-profiles endpoint after all.

nfmohit commented 10 months ago

@aaemnnosttv @jimmymadon I have added the following to the ACs for clarification:

  • If a piece copied to Modules\Analytics_4 retains its functionality even without being present in the Modules\Analytics class, and if it is deemed safe to remove it from Modules\Analytics, it should be eliminated.
  • It should be ensured that no duplication is introduced due to the migration here, e.g. duplicate tags, duplicate hooks, etc.

Please let me know if that looks good, thank you!

mohitwp commented 9 months ago

QA Update ⚠️

@jimmymadon I noticed that under on dev environment under Site health info new field "Analytics 4 ads conversion ID" is added. This field is not exist on latest environment. I added Ads conversion id under settings and it also showing under Analytics 4 snippet but site heath info field still shows "None" even after adding the Ad conversion id.

image

image

image

GA4 snippet with Key metrics ![image](https://github.com/google/site-kit-wp/assets/94359491/088657a0-a69d-4436-8354-4c6a2b830dfd) Ga4 snippet with Ads conversion ![image](https://github.com/google/site-kit-wp/assets/94359491/ae9a2d32-1b63-4c30-8489-4d5e576ad384) GA4 opt out snippet ![image](https://github.com/google/site-kit-wp/assets/94359491/d8137d4d-3c01-40f4-bf9e-376b1fb9aec0)
jimmymadon commented 9 months ago

@mohitwp This is normal as when you edited the settings above as a regression test, you were still editing the settings of the old Analytics module (not the Analytics 4) module. I have just updated the QAB to add a note for QA Eng to test this by saving Analytics 4 module settings.

mohitwp commented 9 months ago

QA Update ✅

Thanks @jimmymadon !

GA4 snippet with Key metrics ![image](https://github.com/google/site-kit-wp/assets/94359491/088657a0-a69d-4436-8354-4c6a2b830dfd) Ga4 snippet with Ads conversion ![image](https://github.com/google/site-kit-wp/assets/94359491/ae9a2d32-1b63-4c30-8489-4d5e576ad384) GA4 opt out snippet ![image](https://github.com/google/site-kit-wp/assets/94359491/d8137d4d-3c01-40f4-bf9e-376b1fb9aec0)
mxbclang commented 9 months ago

@mohitwp Should this now be in Approval? Thanks!

mohitwp commented 9 months ago

@bethanylang It's require QA:Engreview.

mxbclang commented 9 months ago

@mohitwp Ah, missed that, thank you!

hussain-t commented 9 months ago

QA:Eng Verified ✅

Screenshot 2024-02-13 at 9 41 52 PM

Screenshot 2024-02-13 at 9 41 25 PM