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

Copy over analytics module settings to analytics-4 #7923

Closed
nfmohit opened this issue Nov 29, 2023 · 8 comments
Closed

Copy over analytics module settings to analytics-4 #7923

nfmohit opened this issue Nov 29, 2023 · 8 comments
Labels
Module: Analytics Google Analytics module related issues P2 Low priority Type: Enhancement Improvement of an existing feature

Comments

@nfmohit
Copy link
Collaborator

nfmohit commented Nov 29, 2023

Feature Description

Module settings in the analytics module that are still relevant after the removal of UA should be copied over to the analytics-4 module. Namely:

  1. accountID
  2. adsConversionID
  3. canUseSnippet
  4. ownerID
  5. trackingDisabled
  6. useSnippet

A runtime process migration should be introduced in the Analytics_4 class that migrates the settings data from analytics to analytics-4. For example, accountID setting data in googlesitekit_analytics_settings should be migrated over to googlesitekit_analytics-4_settings.


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

Acceptance criteria

  • The following module settings in the analytics module should be copied over to the analytics-4 module:
    • accountID
    • adsConversionID
    • canUseSnippet
    • trackingDisabled
    • adsenseLinked
  • When the value for one of these copied settings is queried and it doesn't exist in the googlesitekit_analytics-4_settings option, it should fallback to the data stored in the googlesitekit_analytics_settings option (if it exists there).
    • The existing ownerID setting should also be treated in the same way, instead of how it is currently always synced between the two modules.

Implementation Brief

  • In includes/Modules/Analytics_4/Settings.php:
    • Update the get_owned_keys method to include the accountID module setting.
    • Update the get_default method to include defaults for the module settings mentioned in the ACs. The default values can be copied from the Modules\Analytics\Settings class.
    • Update the get_sanitize_callback method to add sanitization for the canUseSnippet, trackingDisabled, and adsenseLinked module settings. These sanitization rules can be copied from the Modules\Analytics\Settings class.
    • Remove the merge_initial_owner_id method.
    • Remove the update_owner_id_in_settings method.
    • Update the get method:
      • Remove the existing logic that returns the analytics module setting value for the ownerID setting.
      • For all the module settings that are being copied as a part of this issue, add a fallback for them so that if data for them do not exist in the analytics-4 module but does exist in the googlesitekit_analytics_settings option, the value from the googlesitekit_analytics_settings option is served.
        • Instead of using the Analytics_Settings class as a way to access the googlesitekit_analytics_settings option, use the always available get_option WordPress function. This will ensure that this fallback works even after the Modules\Analytics class is removed in the future (currently planned as a part of #7932).
  • In assets/js/modules/analytics-4/datastore/base.js:
    • Include accountID in the ownedSettingsSlugs array.
    • Include all the module settings mentioned in the ACs to the settingSlugs array.

Test Coverage

  • In tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php:
    • Add test case(s) for the get method to verify the fallback behaviour for the copied settings.

QA Brief

  • Use existing website where Analytics was previously connected
  • Go to Analytics settings
  • Verify that data is still correct
  • Open console log, and paste googlesitekit.data.select('modules/analytics-4').getSettings(), hit enter. Expand the array, verify that keys listed in AC are present and have correct data
  • Edit settings, update something (like excluding/including logged in users in tracking) and save it. Verify that settings are still correctly saved
  • Refresh the page, paste the same snippet in console log, ensure that they reflect the change (Focus on new properties listed in AC)
  • Reset Site Kit, and set it up again with analytics, verify that all settings are correctly saved

Changelog entry

  • Update Analytics 4 settings to use Analytics settings if they are not migrated yet.
@nfmohit nfmohit added Type: Enhancement Improvement of an existing feature Module: Analytics Google Analytics module related issues labels Nov 29, 2023
@bethanylang bethanylang added the P1 Medium priority label Nov 29, 2023
@nfmohit nfmohit assigned nfmohit and unassigned nfmohit Nov 29, 2023
@tofumatt tofumatt self-assigned this Nov 29, 2023
@bethanylang bethanylang added the Next Up Issues to prioritize for definition label Nov 30, 2023
@tofumatt
Copy link
Collaborator

ACs here are good, moving to IB 👍🏻

@tofumatt tofumatt removed their assignment Nov 30, 2023
@nfmohit nfmohit self-assigned this Dec 1, 2023
@nfmohit
Copy link
Collaborator Author

nfmohit commented Dec 1, 2023

Update: After a discussion with @aaemnnosttv, I have updated the ACs of this issue so that instead of doing a once-off migration of the module settings, we fallback to the data stored in googlesitekit_analytics_settings option. This will prevent any data discrepancy until the two modules have been entirely separated, as this is an iterative process.

CC: @tofumatt

@nfmohit nfmohit removed their assignment Dec 9, 2023
@eugene-manuilov eugene-manuilov self-assigned this Dec 11, 2023
@eugene-manuilov
Copy link
Collaborator

IB ✔️

@zutigrm zutigrm assigned eugene-manuilov and unassigned zutigrm Dec 19, 2023
@zutigrm zutigrm assigned eugene-manuilov and unassigned zutigrm Dec 21, 2023
@eugene-manuilov eugene-manuilov removed their assignment Dec 21, 2023
@wpdarren wpdarren self-assigned this Dec 22, 2023
@wpdarren
Copy link
Collaborator

wpdarren commented Jan 2, 2024

QA Update: ✅

Verified:

  • Used an existing website where Analytics was previously connected
    • The data is still correct when updating the branch to develop
    • The array, verify that keys listed in AC are present and have correct data
    • Edited settings and are still correctly saved
  • Refreshed the page, pasted the same snippet in the console log, and they reflect the change as per AC
  • Reset Site Kit, and set it up again with analytics, and all settings are correctly saved.
Screenshots

image
image
image
image

@wpdarren wpdarren removed their assignment Jan 2, 2024
@nfmohit
Copy link
Collaborator Author

nfmohit commented Jan 12, 2024

Hi @wpdarren.

I was just working on reviewing some of the SAM work that is going out as part of this release, and I think this issue isn't working fully as expected.

The new GA4 settings are being correctly migrated if Analytics was set up before the PR for this issue was merged. However, if the Analytics module is connected after the PR is merged, the GA4 settings are not migrated. See:

image

The idea behind this issue was for the new analytics-4 settings to always fall back to whatever is set for their analytics counterparts if they are not set explicitly.

CC: @aaemnnosttv

@wpdarren
Copy link
Collaborator

@nfmohit, thanks for finding and sharing this issue. I left my thoughts on Slack about this. In short, I feel that we will rely a lot on the QAB for this epic because the changes are in the background. I'll bring it up in our retro to see what lessons we (I) can learn from this.

@bethanylang bethanylang added P2 Low priority and removed P1 Medium priority labels Jan 12, 2024
@nfmohit
Copy link
Collaborator Author

nfmohit commented Jan 12, 2024

Hi @wpdarren.

I was just working on reviewing some of the SAM work that is going out as part of this release, and I think this issue isn't working fully as expected.

The new GA4 settings are being correctly migrated if Analytics was set up before the PR for this issue was merged. However, if the Analytics module is connected after the PR is merged, the GA4 settings are not migrated. See:

image

The idea behind this issue was for the new analytics-4 settings to always fall back to whatever is set for their analytics counterparts if they are not set explicitly.

CC: @aaemnnosttv

We have taken a deeper look into this and found out that there isn't a simple way for this to work for new Analytics module setups. As a result, I have opened a new issue to perform a DB migration of the settings just when we ship the singular Analytics module - #8082.

@aaemnnosttv
Copy link
Collaborator

Thanks @nfmohit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Analytics Google Analytics module related issues P2 Low priority Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

8 participants