-
Notifications
You must be signed in to change notification settings - Fork 293
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
Populate Google Tag data for existing site using GA4 #6082
Comments
Hi @nfmohit, this IB is looking good. I would suggest one small change. In the Test Coverage section, you have specified the following point:
However, |
Good catch. I've updated the IB. Thank you, @techanvil ! |
Thanks @nfmohit! IB ✅ |
NOTE: This issue is blocked by #6081 in Sprint 92. |
Thanks @techanvil, the approach you've outlined here would work well I think, I just have a few thoughts for your consideration. After thinking about this a bit more, using client-side cache alone would not be sufficient to prevent the request from being made more than once per hour. It would more/less accomplish this for the current user, but because client-side cache is per user, and now even per WP session, it could happen more frequently, especially for a site with multiple concurrent users. Also, since the relevant data we're checking is not user-specific, but specific to the tag configuration, it would make sense to manage the state in a more centralized location. Rather than introducing some separate value (as the transient was used for initially), we stored a The client side would then only need to read that timestamp and trigger a sync if the current time was outside of the 1 hour threshold.
A minor suggestion here – this reads as a good opportunity for a custom hook, something like Regarding your ideas around wiring up actions to our cache API is something I've been thinking about as well, so +1 to that. That part might not be necessary if you agree with the suggestions above but let's make sure we capture this in some new issues either way. |
Thanks @aaemnnosttv, great suggestion regarding the centralized timestamp, I've updated the IB to make use of a The only thing I'm not so sure about is the idea of creating a custom Also, it's worth bearing in mind that the AC does mention that "Eventually, this logic could be removed"... |
Thanks @techanvil ! IB overall reads great to me, just one last question. One thing I'm thinking about is the format of the |
Populate Google tag data for existing sites
QA Update
|
Thanks for raising this @mohitwp. I've investigated, and it's evident that following the QAB as detailed does not result in the GTE settings being immediately updated. Arguably though, this is following the spec to the letter, but this leads to a question for @felixarntz about whether we should change things to make it behave more intuitively. Following the QAB, setting up Site Kit with Analytics but without the Due to the way As mentioned this is in keeping with the spec but it raises the question, should we in fact make an exception for the It seems to be we probably should do this, but we should also consider that if the user does not grant the scope, maybe is unable to for some reason, we could end up in a situation where the sync attempt & scope request is made on every Dashboard load, which is something we're trying to avoid as per the spec. Alternatively we could add a bit more logic in so the sync is specifically reattempted only when returning from the OAuth flow via a store snapshot or similar... @felixarntz, please can you advise on how you want to proceed with this one? |
@techanvil Great catch! Thinking about this further, we may be best off not attempting any of the syncing logic if the user hasn't granted the scope yet. A few considerations here:
This also avoids the somewhat ugly experience of being on the dashboard and suddenly seeing this popup without even having invoked any action. Does that sound reasonable and would work well with our implementation? |
Thanks @felixarntz - sounds like a good solution. This was a quick fix, I've created a followup PR and tweaked the QAB accordingly, cc @mohitwp. |
…ite-followup Don't attempt to sync GTE settings without the Tag Manager readonly scope.
QA Update ✅
|
Based on #6077 and #6080, for the GA4 snippet, a Google Tag ID should be used going forward. While this usually is the same as the GA4 measurement ID, we will need to migrate all sites to have this tag ID determined and stored. While #6081 implements this for the "new user" / "updating configuration" scenarios, we also need to have logic that populates the data for existing sites where GA4 is already active and fully configured.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
If the
gteSupport
feature flag is enabled, and only with the Analytics / GA4 module active:Analytics_4
module settinggoogleTagID
is empty, the Site Kit dashboard should trigger an API request to determine and store it.Implementation Brief
Expose
googleTagLastSyncedAtMs
timestamp to facilitate request throttlingWithin
includes/Modules/Analytics_4/Settings.php
, inget_default()
:googleTagLastSyncedAtMs
with the default value0
.Within
assets/js/modules/analytics-4/datastore/base.js
:googleTagLastSyncedAtMs
to the list of settings insettingSlugs
.Create
*syncGoogleTagSettings()
actionWithin
assets/js/modules/analytics-4/datastore/properties.js
:*syncGoogleTagSettings()
. Within this action:yield Data.commonActions.getRegistry()
.gteSupport
feature flag is enabled -isFeatureEnabled( 'gteSupport' )
.isModuleConnected( 'analytics-4' )
.googleTagID
setting is empty -getGoogleTagID()
.measurementID
setting is not empty -getMeasurementID()
.Date.now()
is one hour or more later than the time stored in thegoogleTagLastSyncedAtMs
setting, or thegoogleTagLastSyncedAtMs
setting is empty -getGoogleTagLastSyncedAtMs()
,HOUR_IN_SECONDS
. NotegoogleTagLastSyncedAtMs
is in milliseconds, just asDate.now()
fetchGetGoogleTagSettings()
action.googleTagAccountID
,googleTagContainerID
andgoogleTagID
settings by dispatching their individual setter actions.googleTagLastSyncedAtMs
setting with the value of the current time as returned byDate.now()
.saveSettings()
.Call
*syncGoogleTagSettings()
from the DashboardWithin
assets/js/components/DashboardEntryPoint.js
:useMount()
hook that dispatches the*syncGoogleTagSettings()
action.Test Coverage
*syncGoogleTagSettings()
.DashboardEntryPoint
still work and consider adding a test here too.QA Brief
gteSupport
feature flag is disabled.getSettings()
selector at this point (see below), you'll see the Google Tag settings are not yet populated.gteSupport
feature flag.readonly
scope is needed for GTE and for the settings sync. Click on Redo setup and go through the OAuth flow.googleTagID
) are populated.Changelog entry
The text was updated successfully, but these errors were encountered: