site-kit-wp
site-kit-wp copied to clipboard
Extend Consent Mode conditions for determining Ads connection status.
Feature Description
For the Consent Mode MVP, we implemented a simple check for Ads being connected which is to check for the presence of the Ads Conversion ID.
We should extend these conditions to include the additional checks discussed under "when does this apply?" in the one-pager, to the extent that it's practical to do so.
As described in the "when does this apply?" section:
For Site Kit, this affects measurement that is connected to Ads in some way. The most explicit example is the placement of an Ads conversion ID tag on the page (e.g.
AW-12345678). However, this also applies to Analytics in the event where it is connected to Ads in some way, such as an Ads link (service side link between a GA4 property and Ads account), or using an Ads tag as a destination of a Google Tag (GT-, G-)...
GTE Note: we can't look up a tag's destinations by tag ID as we'd want to do here (i.e. check the destinations of tag ID we place). We can only look up a container by a destination ID, or look up destinations by a container. GTE is odd in that it is possible to have a Google tag which is also not a destination ID so we cannot assume this either.
With the above in mind, we should extend the conditions to include the check for the Ads link, and we should also include a check for an Ads tag being a destination of a connected Google tag if we can determine a sensible way to do so.
Update: Due to the limitations of the Tag Manager API mentioned above whereby we can't lookup a tag's destinations by tag ID, we're only going to be able to manage the Ads link part of this in the short term. I (@techanvil) have created a feature request to add an endpoint to look up a container by one of its tag IDs, which would then allow us to lookup the destinations for that container via the existing destinations.list endpoint.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The concept of an Ads link should be introduced to Site Kit, and the status of this (linked or not linked) should be refreshed for the connected Analytics property on a regular basis, with at least 24 hours between each refresh. In other words, it should be updated in a similar manner to the existing AdSense link status.
- Within the Consent Mode feature, the conditions for determining whether Ads is connected should include a check for the presence of an Ads link. That is to say, Ads should be considered connected if either an Ads Conversion ID is present, an Ads link is detected, or both of these are true. This in turn means that:
- The Setup CTA Banner should be displayed when an Ads link is detected (while the Consent Mode
enabledsetting isfalseand the banner has not been dismissed). - The "Recommended" badge and the notice reading "If you have Google Ads campaigns for this site, it's highly recommended to enable Consent mode..." on the Consent Mode section of the Settings screen should be displayed when an Ads link is detected.
- The Setup CTA Banner should be displayed when an Ads link is detected (while the Consent Mode
Implementation Brief
Note that this is basically copying the approach we take for the AdSense link status. It should be OK for now, but we might want to follow up later with some sort of abstraction around these so we don't keep repeating ourselves.
Server-side
- [ ] Within the
Analytics_4module:- [ ] Add new
adsLinkedandadsLinkedLastSyncedAtsettings. - [ ] Add a new
GET:ads-linksdatapoint, similar toGET:adsense-links, with the following key differences:- Use the following call in
create_data_request()to retrieve the links:$this->get_service( 'analyticsadmin' )->properties_googleAdsLinks->listPropertiesGoogleAdsLinks()
- Use
$response->getGoogleAdsLinks()inparse_data_response()to return the links.
- Use the following call in
- [ ] Include the
adsLinkedandadSenseLinkedLastSyncedAtsettings in the Site Health section by adding them toget_debug_fields()in a similar manner to the AdSense settings: https://github.com/google/site-kit-wp/blob/c174714d3d389772fb85a201de567cbb240589e0/includes/Modules/Analytics_4.php#L429-L439- Note that these can be unconditionally included rather than checking for the
adsmodule being connected, as we're interested in the link status regardless of the Ads module connection status. - Please also note this comment and update the field names accordingly: https://github.com/google/site-kit-wp/issues/8382#issuecomment-2018887379
- Note that these can be unconditionally included rather than checking for the
- [ ] Ensure these new settings are reset when the property changes, again similar to the AdSense versions: https://github.com/google/site-kit-wp/blob/c174714d3d389772fb85a201de567cbb240589e0/includes/Modules/Analytics_4.php#L215-L223
- [ ] Add new
- [ ] Add a new
Synchronize_AdsLinkedclass which is based onSynchronize_AdSenseLinked, synchronizing theadsLinkedsetting and updatingadSenseLinkedLastSyncedAtvia a cron job with a 24 hour schedule.- Note that the conditions for scheduling the job only needs to include a check for the
analytics-4module being connected, it doesn't need to include a check for theadsmodule being connected. - Register an instance of this class in
Analytics_4::register().
- Note that the conditions for scheduling the job only needs to include a check for the
Client-side
- [ ] Add
adsLinkedto the list of settings slugs for the JSanalytics-4datastore. - [ ] Include a check for
adsLinkedbeing true when determiningisAdsConnectedin the following locations:- [ ] The
ConsentModeSetupCTAWidgetcomponent: https://github.com/google/site-kit-wp/blob/c174714d3d389772fb85a201de567cbb240589e0/assets/js/components/consent-mode/ConsentModeSetupCTAWidget.js#L72-L75 - [ ] The
SettingsCardConsentModecomponent: https://github.com/google/site-kit-wp/blob/c174714d3d389772fb85a201de567cbb240589e0/assets/js/components/settings/SettingsCardConsentMode.js#L50-L53
- [ ] The
Test Coverage
- Add PHPUnit test coverage to the
Analytics_4class, this can follow the existing coverage foradSenseLinkedandadSenseLinkedLastSyncedAtsettings. - Add PHPUnit test coverage for the new
Synchronize_AdsLinkedclass. - Fix/update VRT tests as needed.
QA Brief
- Set up SK with the Analytics module.
- Make sure you do not have an Ads conversion ID set.
- Run the following in the browser console
googlesitekit.data.select( 'modules/analytics-4' ).getSettings()and verify thatadsLinkedis set tofalse. - Link Google Ads with your configured Google Analytics property following this guide.
- It will need Site Kit around 24 hours to re-check if Ads is linked with Analytics. If you intend to expedite the wait time, you can use the "WP Crontrol" plugin to run the
googlesitekit_cron_synchronize_ads_linked_datacron event immediately. - After around 24 hours, or after manually running the cron event, the
adsLinkedstatus should now be updated. Refresh the SK dashboard and re-do step 3 to verify thatadsLinkedis now set totrue. - Verify that the
Enable Consent Mode to preserve tracking for your Ads campaignsCoMo banner now appears in your SK dashboard. - Verify that the "Recommended" badge now appears in Site Kit Settings -> Admin Settings -> Consent Mode.
Changelog entry
- Add a linked Ads account as an option to surface Consent Mode features.
I've raised the priority of this one as it appears that users who have Ads linked with their Analytics account are seeing a drop off in tracking without Consent Mode being enabled. Implementing this issue will ensure the setup banner on the dashboard, and the recommendations on the Settings screen are shown to more Ads users and help to mitigate this problem. See the related Slack conversation.
Thanks @techanvil !
AC + IB ✅
One thing I noticed which relates to the issue here are the debug field definitions for the AdSense links which lack the "Analytics" prefix that all of its fields should have. Otherwise, it's not clear what module the fields are for. We could fix this for the AdSense fields here since we're touching the same part, or in a separate issue, I just thought I'd flag it here so we don't replicate that omission.
Thanks @aaemnnosttv, good spot there. I've added an additional point to the IB to make sure we don't miss this.
QA Update ⚠️
Tested on dev environment.
@nfmohit I tested this using oi.ie site and manually trigger cron to link analytics and AdSense. AdSense link status is showing true but banner is not showing on main dashboard and Recommended" badge not appearing in Site Kit Settings -> Admin Settings -> Consent Mode.
Let me know if I'm missing something.
Thank you for sharing your observations, @mohitwp.
I think we're having a little confusion between "Ads" linked & "AdSense" linked. We're working with adsLinked in this issue, and based on your screenshot, it looks like it isn't linked yet, i.e. adsLinked is false.
Could you ensure that it is actually linked and the cron job mentioned in the QAB is ran? Thank you!
QA Update ✅
- Tested on dev environment.
- Verified that by running manual running cron
googlesitekit_cron_synchronize_ads_linked_data. - Verified when Analytics don't have Ads conversion id.
- Verified that if adsLinked : True then CoMo banner is appearing on Dashboard and recommended badge is showing under settings.
https://github.com/google/site-kit-wp/assets/94359491/c1c368b8-3c69-4efe-aeb4-e1f0d416c20b