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.23k stars 279 forks source link

Reduce frequency of AdsLinks checks #9141

Open aaemnnosttv opened 1 month ago

aaemnnosttv commented 1 month ago

Feature Description

Synchronization of the presence of AdsLinks for a GA4 property was added in #8382 for the purpose of better informing when Consent Mode should be recommended. It currently queries the state once per day, however, due to the only other condition being GA4 connected it has become the most requested endpoint of the Admin API. Since this state is not highly time-sensitive, or likely to change often, we should greatly reduce the frequency in which it is called.


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

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

  1. Install Advanced Cron Manager plugin.

  2. Make sure Ads module is deactivated and Analytics 4 module is connected.

  3. Go to Tools > Cron Manager, search for googlesitekit_cron_synchronize_ads_linked_data. If it is present, delete it.

  4. Go to Site Kit dashboard, let it load completely.

  5. Go to Tools > Cron Manager again and search for googlesitekit_cron_synchronize_ads_linked_data. It should be available with the next execution set to 7 days (a week).

Changelog entry

neehhaa06 commented 1 month ago

Hello @aaemnnosttv

fix: 9141

optimizing AdsLinks checks for GA4 properties in Site Kit to ### improve efficiency and reduce API load.

eugene-manuilov commented 1 month ago
  • Replace current timestamp to use WEEK_IN_SECONDS instead of a day

@zutigrm, this will be applied only to the new SK installations, everyone else who has already had that cron job active won't switch to the weekly schedule. We need to unregister the existing schedule and re-register it again if the existing schedule is daily.

  • Check if Ads module is connected to return early. You can use googlesitekit_is_module_connected filter for the check

This should happen in the cron job hook itself.

zutigrm commented 1 month ago

@eugene-manuilov

Replace current timestamp to use WEEK_IN_SECONDS instead of a day @zutigrm, this will be applied only to the new SK installations, everyone else who has already had that cron job active won't switch to the weekly schedule. We need to unregister the existing schedule and re-register it again if the existing schedule is daily.

It won't be necessary, because we only schedule this as a single non-repeating event each time. So if they have something scheduled for that day, as soon as that last event is executed, starting from next one, they will all be scheduled on a weekly basis.

Check if Ads module is connected to return early. You can use googlesitekit_is_module_connected filter for the check This should happen in the cron job hook itself.

Thanks, IB updated

eugene-manuilov commented 1 month ago

Replace current timestamp to use WEEK_IN_SECONDS instead of a day @zutigrm, this will be applied only to the new SK installations, everyone else who has already had that cron job active won't switch to the weekly schedule. We need to unregister the existing schedule and re-register it again if the existing schedule is daily.

It won't be necessary, because we only schedule this as a single non-repeating event each time. So if they have something scheduled for that day, as soon as that last event is executed, starting from next one, they will all be scheduled on a weekly basis.

Ah... Yes, you are correct. 👍

IB ✔️

wpdarren commented 1 day ago

QA Update: ✅

Verified:

Followed the steps in the QAB:

image