-
Notifications
You must be signed in to change notification settings - Fork 330
Closed
Labels
Module: Tag ManagerGoogle Tag Manager module related issuesGoogle Tag Manager module related issuesP0High priorityHigh priorityTeam MIssues for Squad 2Issues for Squad 2Type: EnhancementImprovement of an existing featureImprovement of an existing feature
Description
Feature Description
Tag Manager currently loads GTM scripts from the third-party script googletagmanager.com. When GTG is enabled, Tag Manager should load GTM scripts through the local measurement.php proxy to provide first-party benefits, similar to how Analytics and Ads modules work through the GTag class.
This integration will ensure that when GTG is enabled, Tag Manager benefits from improved data quality and measurement signal recovery by serving GTM scripts through the user's own domain.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When GTG is enabled and healthy, Tag Manager scripts should load through the first-party domain proxy (
gtg/measurement.php). - When GTG is disabled or unhealthy, Tag Manager scripts should load directly from
googletagmanager.com(current behavior). - Tag Manager functionality should work correctly in both GTG enabled and disabled states.
- No functionality changes when GTG is disabled - maintains backward compatibility.
- GTG health checks should be appropriately validated before using the proxy.
- Note: Based on the recent discussion, GTM + GTG should use the gtag snippet approach (same as Analytics/Ads) rather than modifying GTM's custom script loading. The noscript tag should be skipped when GTG is enabled.
Implementation Brief
- In
includes/Modules/Tag_Manager/Web_Tag.php:- Add a new protected method
is_google_tag_gateway_active. It can simply be a duplicate ofCore\Tags\GTag::is_google_tag_gateway_active. - Add a new protected methods
setup_gtag. It can imitateModules\Ads\Web_Tag::setup_gtag. - Add a new protected methods
filter_tag_output. It can imitateModules\Ads\Web_Tag::filter_tag_output, with the module name in the comment changed to "Google Tag Manager" instead. - Update the
renderandrender_no_jsmethods:- Return early if
is_google_tag_gateway_activeistrue.
- Return early if
- Update the
registermethod:- Wrap everything currently existing except the call to the
do_init_tag_actionmethod in a conditional block so that it is only executed whenis_google_tag_gateway_activeis nottrue. - If
is_google_tag_gateway_activeistrue:- Hook the
setup_gtagmethod to thegooglesitekit_setup_gtagaction with a priority of30. - Hook the
filter_tag_outputmethod to thescript_loader_tagfilter.
- Hook the
- Wrap everything currently existing except the call to the
- Add a new protected method
Test Coverage
- Add a test suite for
Modules\Tag_Manager\Web_Tag.- Verify that the tag is placed for Tag Manager.
- Verify the variance of the tag placed with and without Google Tag Gateway.
QA Brief
- Set up Site Kit.
- Turn on the
googleTagGatewayfeature flag in the tester plugin. - Set up the Tag Manager module.
- Verify that the Tag Manager snippet is placed in the site.
- Turn on Google tag gateway.
- Verify that the Tag Manager snippet in the site is no longer present; instead, the following appears:
<!-- Google Tag Manager snippet added by Site Kit -->is still present.- A
<script src="{yoursite.com}/wp-content/plugins/google-site-kit/gtg/measurement.php?id={container ID}" id="google_gtagjs-{container ID}-js" async></script>is added (notice the absence of&s=/gtag/jsunline other tags). - A
gtag("config", "{container ID}");is added to the gtag script.
- Regardless of whether GTG is enabled or not, verify that:
- Tag Manager functionality works as expected.
- Use the Tag Assistant to ensure that the GTM container is loaded on the site.
- Site Health correctly detects Site Kit placed Tag Manager tag and existing tags.
- Tag Manager functionality works as expected.
Changelog entry
- Use the GTag script via the first-party domain proxy
gtg/measurement.phpfor Tag Manager containers when Google tag gateway for advertisers is active.
Metadata
Metadata
Assignees
Labels
Module: Tag ManagerGoogle Tag Manager module related issuesGoogle Tag Manager module related issuesP0High priorityHigh priorityTeam MIssues for Squad 2Issues for Squad 2Type: EnhancementImprovement of an existing featureImprovement of an existing feature